# Law of total variance to find $V(Y)$

Let $X$ be a random variable with values $0$ and $1$.

Let $Y$ be a random variable with values in $\mathbb{N_0}$.

Let $p \in (0,1)$ and $P(X=0, Y=n) = p \cdot \frac{e^{-1}}{n!}$ and $P(X=1, Y=n) = (1-p) \cdot \frac{2^{n}e^{-2}}{n!}$.

Calculate $E(Y)$ and $Var(Y)$. (expected value and variance)

So We want to use the law of total expectation. $$E(Y) = E(E(Y|X))= \sum_xE(Y|X=x) \cdot P(X=x)= E(Y|X=0) \cdot p + E(Y|X=1) \cdot (1-p)= \sum_{n=1} n\cdot P(Y=n|X=0) \cdot p+ \sum_{n=1} n\cdot P(Y=n|X=1)\cdot (1-p) = \sum_{n=1} n\cdot \frac{e^{-1}}{n!} \cdot p +\sum_{n=1} n\cdot \frac{e^{-2}\cdot 2^n}{n!} \cdot(1-p)= e^{-1} \cdot e \cdot p + 2\cdot(1-p)\cdot e^{-2} \cdot \sum_{n=1} \frac{2^{n-1}}{(n-1)!} = p + 2\cdot (1-p) e^{-2} \cdot e^2= p+2 \cdot (1-p)= 2-p$$ So far so good. But I never used the law of total variance. Can somebody can only give me "the beginning". What do I mean with "beginning"? I mean that you only write $E(V(Y|X))$ and$Var(E(Y|X))$ as sums like I did with $E(E(Y|X))$. Then I will try the rest on my own.

Hint: the law of total variance is as follows: $$Var(Y) = E(Var(Y \mid X)) + Var(E(Y \mid X))$$
You can compute $Var(Y \mid X)$ in a number of ways, for example conditioning on $X = x$ like you did with the expectation. For the second term, you calculate $E(Y \mid X)$ like you just did and recall that $Var(Y) = E(Y^2) - {(E(Y))}^2$.