I am trying to compute $E[X^3]$ for my assignment for a geometric variable. I have looked through other post but I'm not sure if my formula is correct.
$E[X^3] = E[X(X-1)(X-2) + 3X^2 -2X] = E[X(X-1)(X-2)] + 3E[X^2] - 2E[X] $
$E[X(X-1)(X-2)] = \sum_{k=0}^\infty k(k-1)(k-2)(1-p)^{k-3} = p(1-p)(-\frac{d}{dp}(\frac{2}{p^3})) = p(1-p)\frac{6}{p^4} $
$E[X^3] = p(1-p)(\frac{6}{p^4}) + 3(\frac{2-p}{p^2}) -2(\frac{1}{p})$
Using a known formula for $\mathbb{E}[f(X)]$, we can write
$$\mathbb{E}[X^3] = \sum k^3P(X=k)=\sum_{k=0}^\infty k^3\cdot p\cdot (1-p)^k=p\sum_{k=0}^\infty k^3\cdot (1-p)^k$$
Where I used the convention $P(X=k)=(1-p)^kp$. The sum can be directly computed using the polylogarithmic function, but I'll use a different approach. Noting that
$$k^3=k(k-1)(k-2)-2k+3k^2=k(k-1)(k-2)+3k(k-1)+k$$
We can rewrite
$$k^3(1-p)^k=-(1-p)^3\frac{d^3}{dp^3}(1-p)^k+3(1-p)^2\frac{d^2}{dp^2}(1-p)^k+(1-p)\frac{d}{dp}(1-p)^k$$
We can interchange the derivative and sum in this case, and thus the only series we would need to evaluate is a simple geometric series:
$$\sum_{k=0}^\infty (1-p)^k=\frac{1}{1-(1-p)}=\frac{1}{p}$$
Overall, we are left with the expression
$$\mathbb{E}[X^3]=p[-(1-p)^3\frac{d^3}{dp^3} \frac{1}{p}+3(1-p)^2\frac{d^2}{dp^2}\frac{1}{p}+(1-p)\frac{d}{dp}\frac{1}{p}]$$ $$=p(1-p)[6(1-p)^2p^{-4}+6(1-p)p^{-3}+p^{-2}]=\frac{(1-p)[6(1-p)^2+6p(1-p)+p^2]}{p^3}$$ $$=\frac{(1-p)[p^2-6p+6]}{p^3}$$
Which, by the way, equals $p\operatorname{Li}_{-3}(1-p)$. In fact, in general, for the geometric distribution, $\mathbb{E}[X^n]=p\operatorname{Li}_{-n}(1-p)$, where $\operatorname{Li}(x)$ is the polylogarithmic function.