Calculating the expectation of a geometric distribution Can someone please explain to me how we got from step 3 to step 4? I am extremely confused? Some background information for those curious...
This is in regards to a sequence of Bernoulli trials, each with a probability $p$ of success and a probability $q = 1 - p$ of failure. Let variable $X$ denote the number of trials needed to obtain a success. Then $X$ has values in the range $\{0,1,2,\ldots\}$ and for $k \ge 1$,
$$ E[X] = \sum\limits_{k=1}^\infty kq^{k-1}p $$
$$ = \frac{p}{q} \sum\limits_{k=1}^\infty kq^{k}$$
$$ = \frac{p}{q} \frac{q}{(1-q)^2}$$
$$ = \frac{p}{q} \frac{q}{p^2}$$
$$ = \frac{p}{q} \frac{q}{p^2}$$
$$ = \frac{1}{p}$$

Let me try. You have $$\frac{1}{1-q} = \sum_{n=0}^\infty q^n$$
Then, $$\frac{1}{(1-q)^2} = \sum_{n=1}^\infty nq^{n-1}$$
So, $$\frac{q}{(1-q)^2} = \sum_{n=1}^\infty nq^n$$
