# 22.3. Variance by Conditioning#

Iteration allows us to find expectation by conditioning. We now have the tools to find variance by conditioning as well.

Recall the notation of the previous section:

• $$X$$ and $$Y$$ are jointly distributed random variables

• $$b(X) = E(Y \mid X)$$

• $$D_w = Y - b(X)$$

Define $$D_Y = Y - E(Y)$$. Then

$D_Y ~ = ~ D_w + (b(X) - E(Y)) ~ = ~ D_w + D_b$

where $$D_b = b(X) - E(Y)$$ is the deviation of the random variable $$b(X)$$ from its expectation $$E(Y)$$.

In the graph below, the black line is at the level $$E(Y)$$, and the dark blue point is a generic point $$(X, Y)$$ in the scatter plot. Its distance from the black line is $$D_Y$$ and is equal to the sum of two lengths:

• $$D_w$$, the length of the purple segment

• $$D_b$$, the length of the green segment

## 22.3.1. Decomposition of Variance#

The expectation $$E(Y)$$ is a constant. That means $$D_b = b(X) - E(Y)$$ is a function of $$X$$, and hence $$E(D_wD_b) = 0$$. So

\begin{split} \begin{align*} Var(Y) ~ = ~ E(D_Y^2) ~ &= ~ E\big{(} (D_w + D_b)^2 \big{)} \\ &= E(D_w^2) + E(D_b^2) + 2 E(D_wD_b) \\ &= E(D_w^2) + E(D_b^2) \end{align*} \end{split}

Letâ€™s take a closer look at the two terms on the right hand side. In the previous section we saw that

$E(D_w^2) ~ = ~ MSE(b) ~ = ~ E(Var(Y \mid X))$

Thus the first term on the right hand side is the expectation of the conditional variance.

To understand the second term, note that $$D_b = b(X) - E(Y) = b(X) - E(b(X))$$. So

$E(D_b^2) ~ = ~ Var(b(X)) ~ = ~ Var(E(Y \mid X))$

Thus the second term on the right is the variance of the conditional expectation.

We thus have a decomposition of variance:

$Var(Y) ~ = ~ E(Var(Y \mid X)) + Var(E(Y \mid X))$

That is, the variance is equal to the expectation of the conditional variance plus the variance of the conditional expectation.

It makes sense that the two quantities on the right hand side are involved in the calculation of $$Var(Y)$$. The variability of $$Y$$ has two components:

• the rough size of the variability within the individual vertical strips, that is, the expectation of the conditional variance

• the variability between strips, measured by the variance of the centers of the strips.

The variance decomposition show that you can just add the two terms to get $$Var(Y)$$.

This decomposition is the basis of analysis of variance (ANOVA), widely used in statistics. In this course we are going to use it to find variances by conditioning.
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 1, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "http://prob140.org/textbook/content/Chapter_22/03_Variance_by_Conditioning.html", "fetch_time": 1716769653000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2024-22/segments/1715971058984.87/warc/CC-MAIN-20240526231446-20240527021446-00624.warc.gz", "warc_record_offset": 21378246, "warc_record_length": 9732, "token_count": 719, "char_count": 2476, "score": 4.375, "int_score": 4, "crawl": "CC-MAIN-2024-22", "snapshot_type": "latest", "language": "en", "language_score": 0.8074607253074646, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00000-of-00064.parquet"}