MGF from a conditional distribution I'm having a difficulty with this problem, it is not for submission.
Let Y~U(0,1) be a continuous random variable, and X is another random variable such that given Y=p:
$X|_{Y=p}$~B(n,p).
I need to find the moment generating function of X.
I honestly don't have much here, but I will try to add some context. It's weird to me that they ask about Y=p while being a continuous random variable, but my guess is that this will be relevant later.
 I have the MGF formula of the Unified distribution:
$$M_x(t) = \frac{e^{tb}-e^{ta}}{t\left(b-a\right)} $$ And I thought about using that, but I still don't really see the way.
Another direction I thought of going through but couldn't advance with it is going to the definition:
$$M_x(t) = \sum _x\:e^{tx}P\left(X_{|Y=p}=x\right) $$ but I couldn't really solve it.
Thanks in advance for any help provided.
 A: Starting with the definition is the right step. Insert in the sum the expression for $B(x,n,p)$ ,considering for the moment $p$ to be fixed: you'll get a $M_x(t,p,n)$, that is the mgf subject to being $Y=p$. Thereafter, multiply that for $Pr(Y=[p, p+dp))$ and integrate over the support of $Y$
A: We can first write conditional MGF of bernoulli random r.v.$(I\sim BN(p))$, $MGF_{I}=pe^{t}+1-p$ then given that binomial r.v. is $B(n,p)=\sum_{k=1}^{n}I_{k}$
the MGF of binomial r.v. $B(n,p)$ is,
\begin{equation}
M(p,n)=E(e^{t\sum_{j=1}^{n}I_{j}})=\Pi_{k=1}^{n}E\left[e^{tI_{k}}\right]=\left(pe^{t}+1-p\right)^{n}=\left(p(e^{t}-1)+1\right)^{n}
\end{equation}
Given that $p=Y$,
\begin{equation}
M(X,t,n,p=y)=\left(y(e^{t}-1)+1\right)^{n}
\end{equation}
Now given that $p=Y\sim U(0,1) $ we can compute the MGF as follows,
\begin{equation}
M(X,n,p=Y\sim U(0,1))=\int_{0}^{1}\left(y(e^{t}-1)+1\right)^{n}dy
\end{equation}
Using standard integration arguments for above, we will have the final MGF,
\begin{equation}
M(X,t,n)=\frac{e^{t(n+1)}-1}{(n+1)(e^{t}-1)}=\frac{\sum_{k=1}^{n}e^{t(n-k)}}{n+1}
\end{equation}
A quick check on first moment will be which is,
\begin{equation}
E\left(X(n,y)\right)=nE(y)=\frac{n}{2}
\end{equation}
\begin{equation}
\frac{\partial M(X,t,n)}{\partial t}|_{t=0}=\frac{1}{n+1}\sum_{k=1}^{n}(n+1-k)=\frac{n(n+1)}{2(n+1)}=\frac{n}{2}
\end{equation}
which confirms the MGF.
Hope this is helpful for your question.
