Show $\mathbb{E}(X)=\frac{1-p}{p}$ if $\mathbb{P}(X=k)=p(1-p)^k$ This is a discrete math problem, $\mathbb{E}(X)$ is the expected value of $X$: Let $X$ be a random variable with $P(X=k)=(1-p)^kp$,  $k=0,1,2,3,\ldots$, $0 \leq p \leq 1$. Show that $\mathbb{E}(X)=\frac{1-p}{p}$.
I think we're supposed to use generating functions. So far, I have $\mathbb{E}(X)=\sum_{k=0}^{\infty}(k(1-p)^k p)$=$0+(1-p)p+2(1-p)^2 p+3(1-p)^3 p + \ldots $.
To try and construct that sequence: $\frac{1}{1-(1-p)}=\frac{1}{p}=1+(1-p)+(1-p)^2+(1-p)^3+(1-p)^4+\ldots$.
The derivative of $\frac{1}{p}$ is $-\frac{1}{p^2}=(1-p)+2(1-p)^2+3(1-p)^3 + \ldots$, so multiply by $p$ to get $p$ in every term, $-\frac{p}{p^2}=-\frac{1}{p}=(1-p)p+2(1-p)^2 p+3(1-p)^3 p + \ldots$,
but that would mean $\mathbb{E}(X)=-\frac{1}{p}$, so I must have made a mistake somewhere. I think maybe the last step where I multiplied by $p$ to multiply every term by $p$, am I allowed to do that if $p$ isn't a constant?
 A: I would recommend you to notice that:
\begin{align*}
\sum_{k=0}^{\infty}k(1 - p)^{k}p & = \sum_{k=1}^{\infty}k(1 - p)^{k}p = p(1 - p)\sum_{k=1}^{\infty}k(1 - p)^{k-1}
\end{align*}
where the last series resembles the derivative of a geometric series.
Indeed, if $|x| < 1$, the next series converges:
\begin{align*}
\sum_{x=0}^{\infty}x^{n} = 1 + x + x^{2} + \ldots = \frac{1}{1 - x}
\end{align*}
Differentiating both sides, we get that:
\begin{align*}
\sum_{n=1}^{\infty}nx^{n-1} = 1 + 2x + 3x^{2} + \ldots = \frac{1}{(1 - x)^{2}}
\end{align*}
which is exactly what we are looking for. Gathering the previous results, it yields that:
\begin{align*}
\sum_{k=0}^{\infty}k(1 - p)^{k}p = p(1 - p)\frac{1}{(1 - (1 - p))^{2}} = \frac{1 - p}{p}
\end{align*}
just as desired.
Hopefully this helps!
A: Let
$$g(a) = \sum_{k=0}^{\infty}a^{k},$$
where $a \in (0, 1)$. According to this (convergent geometric series), we have that:
$$g(a) = \frac{1}{1-a}.$$
Notice that:
$$g'(a) = \frac{\mathrm{d}}{\mathrm{d}a}\sum_{k=0}^{\infty} a^{k-1} = \sum_{k=0}^{\infty} \frac{\mathrm{d}}{\mathrm{d}a}a^{k-1} = \sum_{k=1}^{\infty}k a^{k-1},$$
and that
$$g'(a) = \frac{0\cdot(1-a) - 1 \cdot (-1)}{(1-a)^2} = \frac{1}{(1-a)^2}.$$
Hence:
$$\sum_{k=1}^{\infty}k a^{k-1} = \frac{1}{(1-a)^2}.$$

Let's pose $a= 1-p$. Upon the aforementioned premises, we have that:
$$\mathbb{E}[X] = \sum_{k=1}^{\infty}k\mathbb{P}(X=k)
= \sum_{k=1}^{\infty}kp(1-p)^k = \\
= p(1-p)\sum_{k=1}^{\infty}k(1-p)^{k-1} = \\
= p(1-p)\sum_{k=1}^{\infty}ka^{k-1} = \\
= p(1-p) \cdot \frac{1}{(1-a)^2} =\\=  p(1-p) \cdot \frac{1}{p^2}  = \frac{1-p}{p}.$$
A: Taking a look at your work, you are correct to write:
$$
\frac1p = 1 + (1-p) + (1-p)^2 + (1-p)^3 +(1-p)^4+\cdots
$$
However, when you took the derivative wrt $p$, you differentiated the RHS incorrectly. You should have:
$$
-\frac1{p^2} = 0 + [-1] + [ - 2(1-p)] + [-3(1-p)^2] +[-4(1-p)^3]+\cdots
$$
since the derivative of $(1-p)$ is $-1$, the derivative of $(1-p)^2$ is $2(1-p)(-1)$, and in general the derivative of $(1-p)^k$ is $k(1-p)^{k-1}(-1)$. Clearing the negative sign from both sides gets you:
$$\frac1{p^2}=1+2(1-p)+3(1-p)^2+4(1-p)^3+\cdots
$$
To get the RHS to look like $E(X)=(1-p)p + 2(1-p)^2p + 3(1-p)^3p+\cdots$, you multiply both sides by $(1-p)p$. The LHS then becomes $\frac{1-p}p$, as desired.
A: The moment generating function is
\begin{align} 
G(z) &= \sum_{k\ge 0} P(k)z^k \\
     &= \sum_{k\ge 0} p(1-p)^k z^k \\
     &= \frac{p}{1 - (1-p)z},
\end{align}
by the formula for the sum of a geometric series. Then $EX = \sum_{k\ge 0} k P(k) = G'(1)$,
and since $$G'(z) = \frac{p(1-p)}{(1-(1-p)z)^2},$$
we have that $EX = (1-p)/p.$
