Law of total variance

In probability theory, the law of total variance or variance decomposition formula states that if X and Y are random variables on the same probability space, and the variance of X is finite, then


 * $$\operatorname{var}(X)=\operatorname{E}(\operatorname{var}(X\mid Y))+\operatorname{var}(\operatorname{E}(X\mid Y)).\,$$

In language perhaps better known to statisticians than to probabilists, the first term is the unexplained component of the variance; the second is the explained component of the variance.

The nomenclature in this article's title parallels the phrase law of total probability. Some writers on probability call this the "conditional variance formula" or use other names.

(The conditional expected value E( X | Y ) is a random variable in its own right, whose value depends on the value of Y. Notice that the conditional expected value of X given the event  Y = y is a function of y (this is where adherence to the conventional rigidly case-sensitive notation of probability theory becomes important!).  If we write E( X | Y = y) = g(y) then the random variable E( X | Y ) is just g(Y). Similar comments apply to the conditional variance.)

Proof
The law of total variance can be proved using the law of total expectation: First,


 * $$\operatorname{Var}[X] = \operatorname{E}[X^2] - \operatorname{E}[X]^2$$

from the definition of variance. Then we apply the law of total expectation by conditioning on the random variable Y:


 * $$= \operatorname{E}[\operatorname{E}[X^2|Y]] - \operatorname{E}[\operatorname{E}[X|Y]]^2$$

Now we rewrite the conditional second moment of X in terms of its variance and first moment:


 * $$= \operatorname{E}\!\left[\operatorname{Var}[X|Y] + \operatorname{E}[X|Y]^2\right] - \operatorname{E}[\operatorname{E}[X|Y]]^2$$

Since expectation of a sum is the sum of expectations, we can now regroup the terms:


 * $$= \operatorname{E}[\operatorname{Var}[X|Y]] + \left(\operatorname{E}[\operatorname{E}[X|Y]^2] - \operatorname{E}[\operatorname{E}[X|Y]]^2\right)$$

Finally, we recognize the terms in parentheses as the variance of the conditional expectation E[X|Y]:


 * $$= \operatorname{E}[\operatorname{Var}[X|Y]] + \operatorname{Var}[E[X|Y]]$$

The square of the correlation
In case the graph of the conditional expected value is a straight line, i.e., if we have


 * $$\operatorname{E}(X \mid Y)=a+bY,\,$$

then the explained component of the variance divided by the total variance is just the square of the correlation between X and Y, i.e., in that case,


 * $${\operatorname{var}(\operatorname{E}(X\mid Y)) \over \operatorname{var}(X)} = \operatorname{corr}(X,Y)^2.\,$$

Higher moments
A similar law for the third central moment μ3 says


 * $$\mu_3(X)=\operatorname{E}(\mu_3(X\mid Y))+\mu_3(\operatorname{E}(X\mid Y))

+3\,\operatorname{cov}(\operatorname{E}(X\mid Y),\operatorname{var}(X\mid Y)).\,$$

For higher cumulants, a simple and elegant generalization exists. See law of total cumulance.