Proving a Geometric Progression Formula, Related to Geometric Distribution I am trying to prove a geometric progression formula that is related to the formula for the second moment of the geometric distribution. Specifically, I am wondering where I am going wrong, so I can perhaps learn a new technique.
It is known, and I wish to show:
$$
m^{(2)} = \sum_{k=0}^\infty k^2p(1-p)^{k-1} = p\left(\frac{2}{p^3} - \frac{1}{p^2}\right) = \frac{2-p}{p^2}
$$
Now, dividing by $p$ both sides, and assigning $a = 1-p$ yields:
$$
\sum_{k=1}^\infty k^2a^{k-1}=\frac{2}{(1-a)^3}-\frac{1}{(1-a)^2} \qquad \ldots \text{(Eq. 1)}
$$
I want to derive the above formula. I know:
$$
\sum_{k=0}^\infty ka^{k-1}=\frac{1}{(1-a)^2}
$$
Multiplying the left side by $1=\frac aa$, and multiplying both sides by $a$,
$$
\sum_{k=0}^\infty ka^k = \frac{a}{(1-a)^2}
$$
Taking the derivative of both sides with respect to $a$, the result is:
$$
\sum_{k=0}^{\infty}\left[a^k + k^2 a^{k-1}\right] = \frac{(1-a)^2 - 2(1-a)(-1)a}{(1-a^4)} = \frac{1}{(1-a)^2}+\frac{2a}{(1-a)^3}
$$
Moving the known formula $\sum_{k=0}^\infty a^k = \frac{1}{1-a}$ to the right-hand side, the result is:
$$
\sum_{k=0}^\infty k^2 a^{k-1} = \frac{1}{(1-a)^2} + \frac{2a}{(1-a^3)} - \frac{1}{1-a}
$$
Then, this does not appear to be the same as the original formula (Eq. 1). Where did I go wrong?
Thanks for assistance.

You have $$\sum_{k=0}^{\infty} ka^k = \dfrac{a}{(1-a)^2}$$
Differentiating with respect to $a$ gives us
$$\sum_{k=0}^{\infty} k^2 a^{k-1} = \dfrac{(1-a)^2 - a \times 2 \times (a-1)}{(1-a)^4} = \dfrac{1-a + 2a}{(1-a)^3} = \dfrac{a-1+2}{(1-a)^3}\\ = \dfrac2{(1-a)^3} - \dfrac1{(1-a)^2}$$
