# How to use the law of total variance

I know that the law of total variance states $$Var(X)=\Bbb E[Var(X|Y)]+Var(\Bbb E[X|Y])$$ But how does one treat $$Var(X|Y)$$ and $$\Bbb E[X|Y]$$ as random variables? For example, say we know that $$\Bbb E[X|Y=y]=y \ \ \ \text {and} \ \ \ Var(X|Y=y)=1$$ I take it that directly calculating the expected value of $$x$$ and the variance of $$1$$ is not possible. So how does one actually do this practically?

## 2 Answers

The idea is that the expectation will be some function of $$y$$ i.e. $$\mathbb{E}[X|Y=y] = f(y)$$. In these cases, expectation and variance decomposition lemmas are useful.

Take ANOVA for e.g.

$$Var(X)=\Bbb E[Var(X|Y)]+Var(\Bbb E[X|Y])$$ is nothing but cross-group variance - $$\Bbb E[Var(X|Y)]$$ + within-group variance - $$Var(\Bbb E[X|Y])$$.

Don't confuse $$\Bbb E[X|Y]$$ and $$\Bbb E[X|Y=y]$$

$$\Bbb E[X|Y]$$ is a random variable, function of the random variable $$Y$$, $$\Bbb E[X|Y]=g(Y)$$ $$\Bbb E[X|Y=y]$$ is a number, $$\Bbb E[X|Y=y]=g(y)$$ You can compute both if you know the joint distribution of $$X$$ and $$Y$$, same with variance $$\Bbb Var[X|Y]$$ (random variable) or $$\Bbb Var[X|Y=y]$$ (number).

• If I have $\Bbb E[X|Y=y]$ and the distribution of $Y$, how do I establish what $\Bbb E[X|Y]$ is? Or $Var(X|Y)$ for that matter? – mathenthusiast May 22 at 11:42
• $\newcommand{\E}{\mathbb{E}}$Once you have the expression for $\E[X\mid Y=y]$, just replace every $y$ you see in this expression with $Y$ and that is the random variable $\E[X\mid Y]$. For example, if you know that $\E[X\mid Y=y]=y$ for all $y$, then $\E[X\mid Y] = Y$. As another example, if you knew that $\E[X\mid Y=y] = y^3$ for all $y$, then $\E[X\mid Y]$ is the random variable $Y^3$. A similar story holds for $\operatorname{Var}(X\mid Y)$. – Minus One-Twelfth May 22 at 12:58