$P(X = n) = pq^{n-1}$ where p, q > 0 and p + q = 1. Find Var(X) using generating function.

$$P(X = n) = pq^{n-1}$$ where $$p, q > 0$$ and $$p + q = 1$$. Find $${\tt Var}(X)$$ using generating function.

First I found $$E(X)$$:

$$\sum_{n=1}^\infty q^n = 1/(1-q) - 1 = q/(1-q)$$ then differentiate

$$\sum_{n=1}^\infty nq^{n-1} = 1/(1-q) + q/(1-q)^2 = 1/(1-q)^2$$

Then multiplying by p you have $$p/(1-q)^2 = 1/p = E(X)$$.

You can differentiate again to obtain

$$\sum_{n=1}^\infty n(n-1)q^{n-2} = 1/(1-q)^3$$

then $$\sum_{n=1}^\infty n^2q^{n-2} = 1/(1-q)^2 + 1/(1-q)^3$$

$$pq$$ times above sum = $$q/p + q/p^2 = (1-p^2)/p^2$$

I must have went wrong, because $$Var(X) = E(X^2) - [E(X)]^2 = -1$$.

Next, using the generating function, $$G(\alpha) = E(\alpha ^x)$$ $$G'(1) = E(X)$$ $$G''(1) = E(X(X-1))$$.

$$G(\alpha) = \sum_{n=1}^\infty \alpha^npq^{n-1} = p/q \sum_{n=1}^\infty (\alpha q)^n = p\alpha/(1-q\alpha)$$

$$G'(\alpha) = p/(1-q\alpha) + pq\alpha/(1-q\alpha)^2$$

$$G'(1) = 1/p = E(X)$$

So I'm fairly confident I have $$E(X)$$.

$$G''(\alpha) = 2pq/(1-q\alpha)^2 + pq^2\alpha/(1-q\alpha)^3$$

$$G''(1) = E(X(X-1)) = E(X^2) - E(X) = 2q/p + q^2/p^2$$

So add $$E(X) = 1/p$$ to get $$E(X^2)$$:

$$2q/p + 1/p + q^2/p^2 = (5p - p^2 + 1)/p^2$$

Then subtract $$[E(X)]^2 = 1/p^2$$ and you have

$$(5p - p^2)/p^2 = (5-p)/p = Var(X)$$

$$G'(\alpha) = p/(1-q\alpha) + pq\alpha/(1-q\alpha)^2$$ $$G''(\alpha) = pq/(1-q\alpha)^2 + pq/(1-q\alpha)^2 + 2pq^2\alpha/(1-q\alpha)^3$$ $$G''(1) = 2q/p + 2q^2/p^2 = (2pq + 2q^2)/p^2 = 2q(p+q)/p^2 = 2(1-p)/p^2 = E(X(X-1))$$ For $$Var(X)$$, add $$E(X)$$ and subtract $$[E(X)]^2$$: $$(2(1-p) + p - 1)/p^2 = (1 - p)/p^2 = Var(X)$$ Please let me know if this is correct.
You have made several mistakes in the first method. The derivative of $$\frac 1 {(1-q)^{2}}$$ is $$-\frac 2 {(1-q)^{3}}$$. Also you have used the formula for $$\sum\limits_{n=1}^{\infty} nq^{n-1}$$ when you actually have $$\sum\limits_{n=1}^{\infty} nq^{n-2}$$. If you redo your calculations you should be able to get the same answer by both methods.