Formula in probability theory
In probability theory, the law of total covariance,[1] covariance decomposition formula, or conditional covariance formula states that if X, Y, and Z are random variables on the same probability space, and the covariance of X and Y is finite, then

The nomenclature in this article's title parallels the phrase law of total variance. Some writers on probability call this the "conditional covariance formula"[2] or use other names.
Note: The conditional expected values E( X | Z ) and E( Y | Z ) are random variables whose values depend on the value of Z. Note that the conditional expected value of X given the event Z = z is a function of z. If we write E( X | Z = z) = g(z) then the random variable E( X | Z ) is g(Z). Similar comments apply to the conditional covariance.
The law of total covariance can be proved using the law of total expectation: First,
![{\displaystyle \operatorname {cov} (X,Y)=\operatorname {E} [XY]-\operatorname {E} [X]\operatorname {E} [Y]}](https://wikimedia.org/api/rest_v1/media/math/render/svg/f1640f54ab44b3f8b7b3fd6ce9b44e47f6576700)
from a simple standard identity on covariances. Then we apply the law of total expectation by conditioning on the random variable Z:
![{\displaystyle =\operatorname {E} {\big [}\operatorname {E} [XY\mid Z]{\big ]}-\operatorname {E} {\big [}\operatorname {E} [X\mid Z]{\big ]}\operatorname {E} {\big [}\operatorname {E} [Y\mid Z]{\big ]}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/e73873e9bb5e80b4f254985371019560dde3459e)
Now we rewrite the term inside the first expectation using the definition of covariance:
![{\displaystyle =\operatorname {E} \!{\big [}\operatorname {cov} (X,Y\mid Z)+\operatorname {E} [X\mid Z]\operatorname {E} [Y\mid Z]{\big ]}-\operatorname {E} {\big [}\operatorname {E} [X\mid Z]{\big ]}\operatorname {E} {\big [}\operatorname {E} [Y\mid Z]{\big ]}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/88000aa872d3c4aec4ed610180f7d8d2a2329308)
Since expectation of a sum is the sum of expectations, we can regroup the terms:
![{\displaystyle =\operatorname {E} \!{\big [}\operatorname {cov} (X,Y\mid Z){\big ]}+\operatorname {E} {\big [}\operatorname {E} [X\mid Z]\operatorname {E} [Y\mid Z]{\big ]}-\operatorname {E} {\big [}\operatorname {E} [X\mid Z]{\big ]}\operatorname {E} {\big [}\operatorname {E} [Y\mid Z]{\big ]}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/c1db8ce13ab9fb61360993c72d8d16df4f304b33)
Finally, we recognize the final two terms as the covariance of the conditional expectations E[X | Z] and E[Y | Z]:
![{\displaystyle =\operatorname {E} {\big [}\operatorname {cov} (X,Y\mid Z){\big ]}+\operatorname {cov} {\big (}\operatorname {E} [X\mid Z],\operatorname {E} [Y\mid Z]{\big )}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/ad3010c7ce77176b93bc8b3cbf13c7c9b789843c)
Notes and references
[edit] - ^ Matthew R. Rudary, On Predictive Linear Gaussian Models, ProQuest, 2009, page 121.
- ^ Sheldon M. Ross, A First Course in Probability, sixth edition, Prentice Hall, 2002, page 392.