# Thread: Second moment of geometric random variable

1. ## Second moment of geometric random variable

If we define the geometric pmf as $\displaystyle P(X = x) = (1-p)^{x-1} p$, the second moment of a geometric random variable should be $\displaystyle (2-p)/p^2$. However, when I try to derive it, I'm getting $\displaystyle 2(1-p)/p^2$. Can somebody help me find the error in my derivation?

Let q = 1-p.

$\displaystyle E(X^2) = \sum_{x=1}^\infty x^2 (1-p)^{x-1} p = \sum_{x=1}^\infty x^2 q^{x-1} p =\sum_{x=1}^\infty x \large( \dfrac{d}{dq} q^x \large) p = p \dfrac{d}{dq} \sum_{x=1}^\infty x q^x$
$\displaystyle = pq \dfrac{d}{dq} \sum_{x=1}^\infty x q^{x-1} = pq \dfrac{d}{dq} \sum_{x=1}^\infty \dfrac{d}{dq} (q^x) = pq \dfrac{d^2}{dq^2} \sum_{x=1}^\infty q^x = pq \dfrac{d^2}{dq^2} \large( \dfrac{q}{1-q} \large)$
$\displaystyle = pq \dfrac{d}{dq} [(1-q)^{-2}] = 2pq(1-q)^{-3} = \dfrac{2pq}{p^3} = \dfrac{2(1-p)}{p^2}$

2. ## Re: Second moment of geometric random variable

I realize my error. In the second line, I took the q outside of the derivative with respect to q.

3. ## Re: Second moment of geometric random variable

$\displaystyle \sum \limits_{x=1}^\infty ~x\left(\dfrac{d}{dq}~q^x\right)p \neq p \dfrac {d}{dq}\left( \displaystyle \sum \limits_{x=1}^\infty~x q^x\right)$

what you probably have to do is

$\displaystyle \sum \limits_{x=1}^\infty ~x^2 q^{x-1}p = \displaystyle p\sum \limits_{x=1}^\infty~\left(q \dfrac{d^2}{{dq}^2}\left(q^x\right) + \dfrac{d}{dq}\left(q^x\right)\right)$

and proceed as you did before.

a minor nit: One doesn't use $x$ for integer variables. Use $i,j,k,m,n$ instead