Assume you visit $N$ number of stores and you spend $X_i$ money in the $i$-th store. We want to model the total money spend in all stores $Y$.
$ Y=X_1+\dots +X_N $
**Assume:**
- $X_i$ are i.i.d. with $\mathbb E[X]$ and $\mathrm{Var}(X)$.
- $X_i$ are independent of $N$. (only because you visit more stores, does not mean that you spend less per store).
**Results:**
$
\begin{align}
\mathbb E[Y] &= \mathbb E[N]*\mathbb E[X] \\
\mathrm {Var}(Y) &= \big(\mathbb{E}[X] \big)^2*\mathrm{Var}(N) + \mathbb{E}[N]*\mathrm{Var}(X)
\end{align}
$
## Derivation of Expectation
Deriving the [[Conditional Expectation]]:
$
\begin{align}
\mathbb E[Y \vert N=n] &=\mathbb E[X_1+\dots+X_n \vert N=n] \tag{1}\\
&= \mathbb{E}[X_1+\dots+X_n] \tag{2}\\
&=n* \mathbb{E}[X] \tag{3}\\
\mathbb E[Y \vert N]&=N* \mathbb{E}[X] \tag{4}
\end{align}
$
where:
- (2) Since every $X_i$ is independent of the choice of $n$, the conditional equals the unconditional expectation.
- (3) By [[Linearity of Expectations]] the expectation of a sum is the sum of individual expectations. Also $\mathbb E[X_i]$ is the same for all $i$.
- (4) Can be generalized for all $n \in N$.
Deriving unconditional [[Expectation]]:
$
\begin{align}
\mathbb{E}[Y] &= \mathbb{E}\big[\mathbb{E}[Y \vert X] \big] \tag{5}\\ &=\mathbb{E}\big[N*\mathbb{E}[X]\big] \tag{6}\\
&=\mathbb{E}[N]*\mathbb{E}[X] \tag{7}
\end{align}
$
where:
- (5) Applying [[Law of Iterated Expectations]].
- (6) Inserting definition from (4) for the conditional expectation.
- (7) Under independence, the [[Expectation of a Product]] can be split up.
## Derivation of Variance
$
\begin{align}
\mathrm{Var}(Y \vert N=n) &= \mathrm{Var}(X_1+\dots+X_n \vert N=n) \tag{1}\\
&= \mathrm{Var}(X_1+\dots+X_n) \tag{2}\\
&=n*\mathrm{Var}(X) \tag{3}\\
\mathrm{Var}(Y \vert N)&=N*\mathrm{Var}(X) \tag{4}
\end{align}
$
where:
- (2) Since every $X_i$ is independent of the choice of $n$, the conditional equals the unconditional variance.
- (3) Under independence the [[Variance of Sum of Random Variables]] is equal to sum of variances. Also $\mathrm{Var}(X_i)$ is the same for all $i$.
- (4) Can be generalized for all $n \in N$.
Computing the components of the [[Law of Total Variance]]:
$
\begin{align}
\mathrm{Var} \big(\mathbb{E}[Y \vert N] \big)
&= \mathrm{Var}\big(N*\mathbb{E}[X]\big) = (\mathbb{E}[X])^2*\mathrm{Var}(N) \tag{5}\\
\mathbb{E}\big[\mathrm{Var}(Y \vert N)\big]
&= \mathbb{E}\big[N*\mathrm{Var}(X)\big] = \mathbb{E}[N]*\mathrm{Var}(X) \tag{6}
\end{align}
$
where:
- (5) Since $\mathbb E[X]$ is a constant in this setting, it can be pulled out of variance as a squared factor (see [[Variance after Linear Transformation]]).
- (6) Since $N \perp X$, we can split the expectation of a product.
Putting together both expressions (5) and (6) together:
$
\mathrm {Var}(Y) = \big(\mathbb{E}[X] \big)^2*\mathrm{Var}(N) + \mathbb{E}[N]*\mathrm{Var}(X)
$