{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Proof\n\nWe split $X - E[X]$ into a part inside the groups and a part between the groups. Then we show that the cross term has mean $0$.\n\n1. Let $\\mathcal{G} = \\sigma(Y)$, let $M = E[X \\mid Y] = E[X \\mid \\mathcal{G}]$ be the [[conditional expectation|0YAMJRK04E]], and let $\\mu = E[X]$. Since $E[X^2] \u003c \\infty$, $X$ is integrable, so $M$ exists.\n2. Claim: $E[M W] = E[X W]$ for each bounded $\\mathcal{G}$-measurable random variable $W$. For $W = 1_G$ with $G \\in \\mathcal{G}$, this is the defining property of $M$.\n3. By [[linearity of expectation|0P7PTC8DDE]], the claim holds for each simple $\\mathcal{G}$-measurable $W$. Such a $W$ is a finite linear combination of indicators of sets in $\\mathcal{G}$.\n4. Let $W$ be $\\mathcal{G}$-measurable with $\\abs{W} \\le c$ for a constant $c$. Let $W_j = 2^{-j} \\floor{2^j W}$ for $j \\ge 1$. Each $W_j$ is $\\mathcal{G}$-measurable and takes finitely many values, so it is simple.\n5. We have $\\abs{W_j - W} \\le 2^{-j}$ and $\\abs{W_j} \\le c + 1$. So $M W_j \\to M W$ and $X W_j \\to X W$ pointwise, with bounds $(c + 1) \\abs{M}$ and $(c + 1) \\abs{X}$, which are integrable.\n6. By [[dominated convergence|BYNV84PF86]], $E[M W_j] \\to E[M W]$ and $E[X W_j] \\to E[X W]$. With step 3, this proves the claim of step 2.\n7. Claim: $E[M^2] \\le E[X^2]$. For $k \\ge 1$, let $W_k = M \\, 1_{\\{\\abs{M} \\le k\\}}$. It is $\\mathcal{G}$-measurable and bounded by $k$.\n8. Step 2 gives $E[M W_k] = E[X W_k]$. The left side is $E[M^2 1_{\\{\\abs{M} \\le k\\}}] = E[W_k^2]$.\n9. By the [[Cauchy–Schwarz inequality|03PGHKAJG3]], $E[X W_k] \\le \\left(E[X^2]\\right)^{1/2} \\left(E[W_k^2]\\right)^{1/2}$.\n10. Steps 8 and 9 give $E[W_k^2] \\le \\left(E[X^2]\\right)^{1/2} \\left(E[W_k^2]\\right)^{1/2}$. Since $E[W_k^2] \\le k^2$ is finite, this gives $E[W_k^2] \\le E[X^2]$.\n11. The functions $W_k^2$ increase in $k$ to $M^2$. By the [[monotone convergence theorem|G2S6H789RG]], $E[M^2] = \\lim_k E[W_k^2] \\le E[X^2]$.\n12. So $X - M$ and $M - \\mu$ have finite second moments. Then $(X - M)^2$ is integrable, and the [[conditional variance|0F1SN93KXE]] $\\operatorname{Var}(X \\mid Y) = E[(X - M)^2 \\mid \\mathcal{G}]$ is defined.\n13. Claim: $E[(X - M)(M - \\mu)] = 0$. Let $V = M - \\mu$, which is $\\mathcal{G}$-measurable, and let $V_k = V \\, 1_{\\{\\abs{V} \\le k\\}}$ for $k \\ge 1$.\n14. Each $V_k$ is bounded and $\\mathcal{G}$-measurable. By step 2, $E[(X - M) V_k] = E[X V_k] - E[M V_k] = 0$.\n15. The product $(X - M) V_k$ tends to $(X - M) V$ pointwise. It is bounded by $\\abs{X - M} \\abs{V}$, which is integrable by the Cauchy–Schwarz inequality and step 12.\n16. By dominated convergence and step 14, $E[(X - M) V] = \\lim_k E[(X - M) V_k] = 0$.\n17. Write $X - \\mu = (X - M) + V$. Expand the square and use linearity: $E[(X - \\mu)^2] = E[(X - M)^2] + 2 E[(X - M) V] + E[V^2]$.\n18. By the definition of the [[variance|007QED3E0Y]], the left side is $\\operatorname{Var}(X)$. By step 16, the middle term is $0$.\n19. By the [[law of total expectation|04RRB6HM00]] for the integrable variable $(X - M)^2$, $E[(X - M)^2] = E\\left[E[(X - M)^2 \\mid \\mathcal{G}]\\right] = E[\\operatorname{Var}(X \\mid Y)]$.\n20. By the law of total expectation, $E[M] = E[X] = \\mu$. So $E[V^2] = E[(M - E[M])^2] = \\operatorname{Var}(E[X \\mid Y])$.\n21. Steps 17 to 20 give $\\operatorname{Var}(X) = E[\\operatorname{Var}(X \\mid Y)] + \\operatorname{Var}(E[X \\mid Y])$.\n\n## Idea\n\nWrite $X - E[X]$ as the deviation of $X$ from its group mean $E[X \\mid Y]$, plus the deviation of the group mean from $E[X]$. The first part is orthogonal to every function of $Y$, so the cross term vanishes and the two squares add up. Most of the work checks that every term is finite.\n",
  "commit": "4a3290d299c8b2cd6493fce2296920ba7f82d942",
  "front": {
    "kind": "proof",
    "msc": [
      "60A10"
    ],
    "name": "Proof of the law of total variance",
    "proves": "03BY5XTNA4",
    "sources": [
      {
        "locator": "Proof",
        "url": "https://en.wikipedia.org/wiki/Law_of_total_variance"
      }
    ],
    "tag": "5DRPDDWY6R",
    "uses": [
      "0YAMJRK04E",
      "0F1SN93KXE",
      "007QED3E0Y",
      "04RRB6HM00",
      "03PGHKAJG3",
      "G2S6H789RG",
      "BYNV84PF86",
      "0P7PTC8DDE"
    ]
  },
  "kind": "proof",
  "link": "https://math2.tamnd.com/node/5DRPDDWY6R/",
  "links": [
    {
      "field": "proves",
      "target": "03BY5XTNA4"
    },
    {
      "field": "uses",
      "target": "0YAMJRK04E"
    },
    {
      "field": "uses",
      "target": "0F1SN93KXE"
    },
    {
      "field": "uses",
      "target": "007QED3E0Y"
    },
    {
      "field": "uses",
      "target": "04RRB6HM00"
    },
    {
      "field": "uses",
      "target": "03PGHKAJG3"
    },
    {
      "field": "uses",
      "target": "G2S6H789RG"
    },
    {
      "field": "uses",
      "target": "BYNV84PF86"
    },
    {
      "field": "uses",
      "target": "0P7PTC8DDE"
    }
  ],
  "markdown": "https://math2.tamnd.com/node/5DRPDDWY6R.md",
  "msc": [
    "60A10"
  ],
  "name": "Proof of the law of total variance",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/5DR/5DRPDDWY6R.md",
  "status": null,
  "tag": "5DRPDDWY6R",
  "uri": "m2://5DRPDDWY6R",
  "url": "https://math2.tamnd.com/wiki/proof-of-the-law-of-total-variance/",
  "writing": {
    "tag": "5DRPDDWY6R",
    "kind": "proof",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      }
    ]
  }
}
