Find the moments of a binomial conditioned on a binomial? Suppose that $Y$ has the binomial distribution, $Bin(20, 0.25)$ and conditioned on $Y$, a random variable $X$ that has the binomial distribution, $Bin(Y, 0.5)$. 
How can I derive the $k$th moment of $X$?
I know the general case:
$E(X)=∑_{x∈Ω_X}x^kP[X=x]$, and I know that just for one binomial random variable, $E[X]$ is $np$, but I'm not sure how to deal with $X$, which is conditioned on a second variable.
 A: By the Law of Total expectation $$E[X^k]=E[E[X^k\mid Y]]$$ So, you can calculate $E[X^k\mid Y=y]$ and then take the expected value with respect to $Y$ $$E[X^k\mid Y=y]=\sum_{k=0}^{y}x^kP(X=x)=\sum_{x=0}^{y}\dbinom{y}{x}x^k0.5^k0.5^{y-k}=0.5^y\sum_{x=0}^{y}\dbinom{y}{x}x^k$$ which has a closed form but not that simple for all $k$. However for $k=1$ $$E[X]=E[E[X\mid Y]]=E[0.5Y]=0.5E[Y]=0.5(0.25)20=2.5$$ For $k=2$ you know that when $X\sim$ Bin$(n,p)$ then $Var(X)=np(1-p)$, and also $$Var(X)=E[X^2]-E[X]^2\implies E[X^2]=np(1-p)+(np)^2$$ so here this gives you (with $Y$ in place of $n$) 
\begin{align}E[X^2]&=E[E[X^2\mid Y]]=E[Yp(1-p)+(Yp)^2]\overset{p=0.5}=\\[0.2cm]&=0.5^2\left(E[Y]+E[Y^2\right)=0.5^2(E[Y]+Var(Y)+E[Y]^2)\\[0.2cm]&=0.5^2(20(0.25)+20(0.25)(0.75)+(20(0.25))^2)\\[0.2cm]&=\frac{135}{16}\end{align}
A: We have that $Y\sim Bin(20, 1/4)$ and $X|Y=y\sim Bin(y,1/2)$.
First of all, we need the distribution of $X$:
$$
P(X=x)=\sum_{u=0}^{20} P(X=x,Y=u)=\sum_{u=0}^{20}P(X=x|Y=u)P(Y=u)
$$
And now we go as usual:
$$
E[X^{k}]=\sum_{x=0}^{20}x^kP(X=x)
$$
