Prove that $Var(X) =\sigma^2E[N]+\mu^2Var(N)$ Given $Y_1,Y_2,Y_3......$ are iid, random variables with mean $\mu$ and variance $\sigma^2$.Suppose that N is an independent random variable taking positive integer values such that $E[N^2]$ finite. Set $X=Y_1+Y_2+....+Y_N$. Prove :
$Var(X) =\sigma^2E[N]+\mu^2Var(N)$ 
Looking at the problem, it seems to me the random variable X depends on both N and Y. I have a feeling it must be some sort of conditional expection/variance with the sigma algebra generated by N, but I don't know how to put them it to proof, Please help
 A: Expectation of a sum is usually the sum of the expectations; however, the number of terms in the sum is itself random. In this case, we make a distinction between taking expectations with respect to the $Y$ distribution and the $N$ distribution. Another way to formulate this is to write everything as double expectations, with the inner ones conditioned on $N=n$, but the below notation works. A subscript of $y$ denotes an expectation (or variance) with respect to the probability density of the $Y_i$ variables. A subscript of $n$ denotes expectation with respect to the value $N$. A mixed subscript means you're taking the expectation with respect to both densities, and the order doesn't matter because of independence. Then:
$$
\mathrm{E}_{yn}[X] = \mathrm{E}_{n}\left[\mathrm{E}_y\left[\sum_{i=1}^N Y_i\right]\right] = 
\mathrm{E}_{n}\left[\sum_{i=1}^N \mathrm{E}_y\left[Y_i\right]\right] = 
\mathrm{E}_{n}\left[\sum_{i=1}^N \mu\right] = 
\mu\mathrm{E}_{n}\left[N\right]
$$
If you're concerned about this being "right", think of each expectation as it's integral representation, and we can move things through each other / reorder expectations because of independence. Continuing on
$$
\mathrm{E}_{yn}\left[X^2\right] = 
\mathrm{E}_{yn}\left[\sum_{i=1}^N\sum_{j=1}^N Y_iY_j\right] = 
\mathrm{E}_{n}\left[\sum_{i=1}^N\sum_{j=1}^N \mathrm{E}_{y}[Y_iY_j]\right]
$$
Now there's two cases, when $i=j$, and when $i\neq j$. 
$$
\mathrm{E}_{y}[Y_iY_j] = \left\{
\begin{array}{ccc}
\sigma^2+\mu^2&,&i=j\\
\mu^2&,&i\neq j
\end{array}
\right.
$$
So that double sum becomes
$$
\mathrm{E}_{yn}\left[X^2\right] = 
\mathrm{E}_{n}\left[\sum_{i=1}^N\sum_{j=1}^N \mu^2 + \sum_{i=1}^N\sigma^2\right] = 
\mu^2\mathrm{E}_{n}\left[N^2\right] + \sigma^2\mathrm{E}_{n}[N]
$$
Now the variance 
$$
\mathrm{Var}_{yn}\left[X\right] = \mathrm{E}_{yn}\left[X^2\right]-\mathrm{E}_{yn}\left[X\right]^2 = 
\mu^2\mathrm{E}_{n}\left[N^2\right]+ \sigma^2\mathrm{E}_{n}[N]-\mu^2\mathrm{E}_{n}\left[N\right]^2\\
{} = \mu^2\left(\mathrm{E}_{n}\left[N^2\right]-\mathrm{E}_{n}\left[N\right]^2\right)+\sigma^2\mathrm{E}_{n}[N]=\mu^2\mathrm{Var}_n[N]+ \sigma^2\mathrm{E}_{n}[N]
$$
A: Here's a hint to get you started: Recall that $\rm{Var}(X) = \mathbb{E}(X^2) - \mathbb{E}(X)^2$. What does this equal, given $N = n$, for a deterministic integer $n>0$?
