Expected value problem: a couple stops having children as soon as they have a child that has the same gender as their first Givens:


*

*$p$ is a real number with $0 < p < 1$

*Child is a boy with probability $p$

*Child is a girl with probability $1-p$

*Anna and Ben stop having children as soon as they have a child that has the same gender as their first child.

*Random variable $X$= number of children that Anna and Ben have


Required: $E(X)$.
I know that I need to use the fact that $\sum_{k=1}^{\infty} k x^{k-1} = 1/(1-x)^2$ but I don't know how.
Could someone please explain/show how answer this question?
 A: Case 1: Getting at first a boy and at last a boy
The probabiltiy to get  first a boy and at last a boy in n attempts is
$p \cdot (1-p)^{n-2}\cdot p$ 
The expected value is $\sum_{n=2}^{\infty } n\cdot p^2 \cdot (1-p)^{n-2}$
Now you can make an index shift: $k=n-1 \Rightarrow n=k+1$
$\sum_{k=1}^{\infty} (k+1) \cdot p^2 \cdot (1-p)^{k-1}$
$=\sum_{k=1}^{\infty} 1 \cdot p^2 \cdot (1-p)^{k-1}+\sum_{k=1}^{\infty} k \cdot p^2 \cdot (1-p)^{k-1}$
factor out $p$ and $p^2$
$=p\sum_{k=1}^{\infty} 1 \cdot p \cdot (1-p)^{k-1}+p^2\sum_{k=1}^{\infty} k \cdot (1-p)^{k-1}$


*

*$\sum_{k=1}^{\infty} 1 \cdot p \cdot (1-p)^{k-1}=1$

*And from your formula you know, that $\sum_{k=1}^{\infty} k \cdot
   (1-p)^{k-1}=\frac{1}{(1-(1-p))^2}=\frac{1}{p^2}$


Thus we get $p+\frac{p^2}{p^2}=p+1$
Case 2: Getting at first a girl and at last a girl
The expected value is $\sum_{n=2}^{\infty } n\cdot (1-p)^2 \cdot p^{n-2}$
The further calculations are similar. The result, in this case, is $2-p$.
A: Assuming the problem is not a silly trick, notice:
$$E(X)=E(X|\text{first child is male})P(\text{first child is male}) \\
+ E(X|\text{first child is female})P(\text{first child is female})$$
by the total expectation formula. We are given the two probability values: the first is $p$, the second is $1-p$. Now $X|\text{first child is male}$ is $1+G_p$, where $G_p$ is a geometric random variable with parameter $p$. This is because they have a male child (which counts for one child), and then wait for an event with probability $p$, having $G_p$ children in the process. Similarly $X|\text{first child is female}$ is $1+G_{1-p}$.
Can you finish the problem from here? For checking purposes, I think the final answer should be $3$. (Note that this requires that that $p$ cannot be $0$ or $1$; indeed in either of these cases it is trivial to see that $X$ is always $2$, so $E(X)=2$.)
