$E[\sum_{i=1}^M X_i] = E[M]E[X_1]$? If $M, X_1, X_2, ...$ are id similarly distributed, then why is 
$$E[\sum_{i=1}^M X_i] = E[M]E[X_1]$$
I don't understand what it means to sum with regards to a random variable $M$?
 A: Assuming:


*

*$X_{i}$ are iid

*$X_{i}$ and $M$ are mutually independent


Let:
$$S=\sum_{i=1}^{M}X_{i}$$
Taking the expectation:
$$E[S]=E[E[S|M]]$$
Now,
$$E[S|M]=ME[X_{i}]$$
due to the fact that if $M$ is known, you have $M$ lots of $X_{i}$ summed together.
So now we have:
$$\begin{align}
E[S]&=E[E[S|M]]\\
&=E[ME[X_{i}]]\\
&=E[M]E[X_{i}]\,\,\text{ (independence)}
\end{align}$$
With regard to "what it means to sum with regards to a random variable $M$", consider the following example. Imagine you are an insurer who has issued some insurance policies. Based on experience, the severity of claims on these insurance policies (how much they cost the insurer) can be modeled well by the random variable $X$. The insurer would like to know how much these policies are expected to cost. Obviously, the insurer needs to know how many claims there will be in order to do this. However, claims are random, in this instance following the random variable $M$. Thus, to get the cost of the policies, the insurer must sum over a random variable $M$.
A: this can be solved by an application of the law of iterated expectation:
$$E(\sum_{i=1}^M X_i) = E(E(\sum_{i=1}^M X_i|M)) = E(\sum_{i=1}^M E(X_i))= E( \sum_{i=1}^M E(X_1)) = E(M)E(X_1).$$
A: Let $S_M=\sum_{m=1}^{M}X_{m}$. 
Consider the conditional expectation of $S_{M}$ given the value of $M$ as
\begin{eqnarray*}
% \nonumber to remove numbering (before each equation)
  E\left[S_{M}|M=m\right] &=& E\left[X_{1}+X_{2}+\cdots +X_{M}|M=m\right] \\
   &=& E\left[X_{1}+X_{2}+\cdots +X_{m}\right]\quad \mbox{ since X and M are independent RV's}\\
   &=& m E[X]\quad \mbox{ since $X_{i}'s$ are iid RV's}\\
  E\left[S_{M}\right] &=& \sum_{m}\underbrace{E\left(S_{M}|M=m\right)}_{m\cdot E[X]} P\left\{M=m\right\}\\
  &=& \sum_{m} m\cdot E[X]\cdot P\left\{M=m\right\}\\
  &=&E(X)\cdot \sum_{m}m\cdot P\left\{M=m\right\}\\
  E\left[S_{M}\right] &=& E[X]\cdot E[M]
\end{eqnarray*}
