# Finding the moment generating function of a sum of poisson random variables, when the sum limit is itself a poisson random variable

Find the MGF of $\sum_{i=1}^N X_i$ where $N\sim$Poisson(3) and is independent of $X_1,..., X_n...$ which are i.i.d. Poisson($\theta$).

I'm very confused about how to get the MGF in this case, where the sum's upper bound is not a regular fixed number but is instead itself a poisson random variable.

If the sum was a fixed number I would do: $MGF_Y(t)=E(e^{ty})$ $MGF_{\sum_{i=1}^N X_i}(t)=E(e^{t(\sum_{i=1}^N X_i)})=E(e^{tx_1\times e^{tx_2}\times...\times e^{tx_n}})$ and since $x_1,...,x_n$ are independent we can say: $E(e^{tx_1})=E(e^{tx_2})=...=E(e^{tx_n})$ so then we get: $E(e^{tx_1})^n$ And from our notes we know the formula of the M.G.F. of a Poisson is: $e^{\theta(e^t-1)}$ and then you just take the power of n to get the resulting MGF: $(e^{\theta(e^t-1)})^n$.

How is it done differently in the case where the upper bound is itself a poisson distributed random variable?

When $N \sim \operatorname{Poisson}(\lambda)$, we would employ the law of total expectation. Let $$S = \sum_{i=1}^N X_i,$$ so we have $$M_S(t) = \operatorname{E}[e^{tS}] = \operatorname{E}[\operatorname{E}[e^{tS} \mid N]].$$ You have already calculated the interior, conditional expectation: $$\operatorname{E}[e^{tS} \mid N] = \exp\left(N\theta(e^t - 1)\right).$$ Thus we need to compute $$M_S(t) = \operatorname{E}\left[\exp\left(N\theta(e^t - 1)\right)\right].$$ But you can observe that this is simply the MGF of $N$ evaluated at $\theta(e^t - 1)$, and since $N$ is Poisson with MGF $$M_N(u) = e^{\lambda(e^u - 1)},$$ we have $$M_S(t) = M_N(\theta(e^t-1)) = \exp\left(\lambda(e^{\theta(e^t-1)} - 1)\right).$$
By the definition $$MGF_{\sum_{i=1}^N X_i}(t)=E\left(e^{t\sum_{i=1}^N X_i}\right)=E\left(E\left(e^{t\sum_{i=1}^N X_i}\mid \ N\right)\right).$$
And because of the independence $$E\left(e^{t\sum_{i=1}^N X_i}\mid \ N=n\right)=E\left(e^{t\sum_{i=1}^n X_i}\right)=\prod_{i=1}^nE\left(e^{tX_i}\right)=e^{\theta(e^t-1)n}$$ So, $$MGF_{\sum_{i=1}^N X_i}(t)=E\left(e^{\theta(e^t-1)N}\right).$$If we write $u=\theta(e^t-1)$ then $$MGF_{\sum_{i=1}^N X_i}(t)=E\left(e^{uN}\right)$$ which is the MGF of $N$ at $u$ that is $$MGF_{\sum_{i=1}^N X_i}(t)=e^{3(e^u-1)}=e^{3(e^{\theta(e^t-1)}-1)}.$$