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}$$
 A: In geometric distributions, there are only two possible outcomes. Since either $p$ or $q$ happens, $p=1-q\implies(1-q)^2=p^2$.
A: 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$$
A: That step is certainly not explained in what you have posted.  Possibly someone had in mind writing
$$
\sum_{k=1}^\infty kq^k = q \sum_{k=1}^\infty kq^{k-1} = q \frac d {dq} \sum_{k=1}^\infty q^k
$$
and then summing the geometric series and then differentiating.  One thing problematic about that is that, although the sum of the derivatives is equal to the derivative of the sum when there are only finitely many terms, the question of when it works with infinitely many terms is more involved than that.
Alternatively, one might say
\begin{align}
& \sum_{k=1}^\infty kq^k = \sum_{k=1}^\infty \sum_{j=1}^k q^k = \sum_{\begin{smallmatrix} j,k\,:\,1\le j\le k \end{smallmatrix}} q^k = \sum_{j=1}^\infty \sum_{k=j}^\infty q^k \overset{\star}= \sum_{j=1}^\infty \frac{q^j}{1-q} \\[10pt]
 = {} & \frac 1 {1-q} \sum_{j=1}^\infty q^j \overset{\star}= \frac 1 {1-q} \cdot \frac q {1-q} = \frac q {(1-q)^2}
\end{align}
Both of the steps labeled $\text{“}\star\text{''}$ are just the summing of a geometric series.
