I am encountering times when Var(X) is interchanged with $E[X^2]$ where X is a random variable and in the cases where E[X] = 0 I see why that is:
$Var(X) = E[X^2] - (E[X])^2$.
But sometimes that is not the case, i.e. E[X] != 0. Would you mind weighing in? Take for example this problem:
Customers arrive at a restaurant with a Poisson rate $\lambda$ and on average spend 20 dollars with a variance of 5. What is the mean and variance of the revenue at this restaurant over 10 hours?
The solution goes as follows:
Let $X_i$ be money spent by i-th customer and let N(t) be customer arrivals by time t.
average money spent = $E[\sum_{i=1}^{N(10)}X_i = E[N(10)]*E[X_i]$
=$10*\lambda*20 $, this is clear
variance = $Var(\sum_{i=1}^{N(10)}X_i) = 10*\lambda*E[X_i^2]$
= $10*\lambda * (Var(X_i) + E[X_i]^2)$
- the expectation was computed to be 200*$\lambda$
- In the first step of the variance calculation they seemingly skipped a step that most likely was as follows:
variance = $Var(\sum_{i=1}^{N(10)}X_i) = E[N(10)]*Var[X_i]$
and then they substituted $Var(X_i) = E[X_i^2]$
How come? I'm not fully following why that is allowed.
First the average. Let me use $M$ instead of $N(10)$. We have $E M = 10 \lambda$, of course. \begin{eqnarray} E[ \sum_{k=1}^M X_k ] &=& E [ E [\sum_{k=1}^M X_k | M=n]] \\ &=& E [ E [\sum_{k=1}^n X_k | M=n]] \\ &=& \sum_n E [\sum_{k=1}^n X_k | M=n] P[M=n] \\ &=& \sum_n n E[X] P[M=n] \\ &=& EM \cdot EX \end{eqnarray}
Now the variance, note that $\operatorname{var} (\sum_{k=1}^M X_k) = E [(\sum_{k=1}^M X_k)^2] - (E [\sum_{k=1}^M X_k])^2$.
We have \begin{eqnarray} E[(\sum_{k=1}^M X_k)^2] &=& E[E[(\sum_{k=1}^M X_k)^2|M=n]] \\ &=& E[E[(\sum_{k=1}^n \sum_{k=1}^n X_k X_l|M=n] ] \\ &=& \sum_n E[(\sum_{k=1}^n \sum_{k=1}^n X_k X_l|M=n] P[M=n] \\ &=& \sum_n (n E X^2 + n(n-1) (EX)^2 ) P[M=n] \\ &=& \sum_n (n E X^2 + n^2 (EX)^2 - n (EX)^2) P[M=n] \\ &=& EM \cdot (EX^2) + EM^2 \cdot (E X)^2 - EM \cdot (EX)^2 \\ &=& EM \cdot \operatorname{var} X + EM^2 \cdot (E X)^2 \end{eqnarray} and so \begin{eqnarray} \operatorname{var} (\sum_{k=1}^M X_k) &=& EM \cdot \operatorname{var} X + (E X)^2 (E M^2 - (EM)^2) \\ &=& EM \cdot \operatorname{var} X + (EX)^2 \operatorname{var} M \end{eqnarray} Since $E M = \operatorname{var} M$, this gives $\operatorname{var} (\sum_{k=1}^M X_k) = E M \cdot E X^2$