{
  "id": "law-of-total-expectation",
  "title": "Law of Total Expectation",
  "lang": "en",
  "source_lang": "en",
  "summary": "The law of total expectation expresses an unconditional mean as the probability-weighted average of conditional means and, more generally, describes how nested conditional expectations simplify.",
  "category": "mathematics",
  "subcategory": "probability-statistics",
  "type": "concept",
  "aliases": [
    "Law of iterated expectations",
    "Iterated expectation theorem",
    "Tower property",
    "Averaging law"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/law-of-total-expectation/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/law-of-total-expectation/",
      "json": "https://aiwiki.page/zh/law-of-total-expectation.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "The law of total expectation is a theorem in probability theory stating that the expected value of a random variable equals the expected value of its conditional expectation. For an integrable random variable \\(X\\) and another random variable \\(Y\\),\n\n\\[\\mathbb E[X]=\\mathbb E\\!\\left[\\mathbb E[X\\mid Y]\\right].\\]\n\nInformally, an overall mean can be obtained by calculating the mean within each group and then averaging those group means using the groups’ probabilities. The law requires no independence assumption. Its more general form, called the tower property, describes successive conditioning on nested collections of information."
    },
    {
      "heading": "Basic statement and interpretation",
      "text": "Suppose \\(X\\) is real-valued and integrable, meaning\n\n\\[\\mathbb E[|X|]<\\infty.\\]\n\nThe expression \\(\\mathbb E[X\\mid Y]\\) is itself a random variable: its value depends on the observed value of \\(Y\\). The outer expectation averages this conditional mean over the distribution of \\(Y\\).\n\nIf \\(m(y)\\) denotes a suitable version of \\(\\mathbb E[X\\mid Y=y]\\), the law becomes\n\n\\[\\mathbb E[X]=\\mathbb E[m(Y)].\\]\n\nThus, replacing each outcome of \\(X\\) by the average associated with its value of \\(Y\\) preserves the overall expectation.\n\nThe theorem also holds for nonnegative \\(X\\), allowing either side to equal \\(+\\infty\\). For a signed random variable that is not integrable, additional care is necessary: an expectation involving the undefined expression \\(+\\infty-\\infty\\) is not meaningful."
    },
    {
      "heading": "Discrete and continuous forms",
      "text": "Conditioning on a partition\n\nLet \\(A_1,A_2,\\ldots\\) be a finite or countable partition of the sample space, with events of probability zero omitted. Then\n\n\\[\\mathbb E[X] = \\sum_i \\mathbb E[X\\mid A_i]\\,\\mathbb P(A_i).\\]\n\nHere\n\n\\[\\mathbb E[X\\mid A_i] = \\frac{\\mathbb E[X\\mathbf 1_{A_i}]}{\\mathbb P(A_i)},\\]\n\nwhere \\(\\mathbf 1_{A_i}\\) is the indicator function of \\(A_i\\).\n\nFor a discrete conditioning variable \\(Y\\), this gives\n\n\\[\\mathbb E[X] = \\sum_{y:\\,\\mathbb P(Y=y)>0} \\mathbb E[X\\mid Y=y]\\,\\mathbb P(Y=y).\\]\n\nOnly \\(Y\\) needs to be discrete; \\(X\\) may be discrete, continuous, or mixed.\n\nConditioning on a continuous variable\n\nIf \\(Y\\) has a probability density function \\(f_Y\\), then\n\n\\[\\mathbb E[X] = \\int_{-\\infty}^{\\infty} m(y)f_Y(y)\\,dy, \\qquad m(y)=\\mathbb E[X\\mid Y=y].\\]\n\nIf \\(X\\) and \\(Y\\) have a joint density, a version of \\(m\\) can be written as\n\n\\[m(y)= \\int_{-\\infty}^{\\infty} x f_{X\\mid Y}(x\\mid y)\\,dx\\]\n\nwhere \\(f_Y(y)>0\\). Substituting this expression yields\n\n\\[\\mathbb E[X] = \\int_{-\\infty}^{\\infty} \\left( \\int_{-\\infty}^{\\infty} x f_{X\\mid Y}(x\\mid y)\\,dx \\right)f_Y(y)\\,dy.\\]\n\nFor continuous \\(Y\\), the event \\(Y=y\\) ordinarily has probability zero. Accordingly, \\(\\mathbb E[X\\mid Y=y]\\) is not defined by dividing by \\(\\mathbb P(Y=y)\\). It is interpreted through a conditional distribution or a measurable representation of \\(\\mathbb E[X\\mid Y]\\), determined up to sets of \\(Y\\)-probability zero.\n\nMore generally, writing \\(P_Y\\) for the distribution of \\(Y\\),\n\n\\[\\mathbb E[X]=\\int m(y)\\,P_Y(dy).\\]\n\nThis formulation also covers distributions that are neither purely discrete nor purely continuous."
    },
    {
      "heading": "Measure-theoretic formulation",
      "text": "On a probability space \\((\\Omega,\\mathcal F,\\mathbb P)\\), let \\(\\mathcal G\\subseteq\\mathcal F\\) be a sigma-algebra representing available information. For integrable \\(X\\), the conditional expectation\n\n\\[Z=\\mathbb E[X\\mid\\mathcal G]\\]\n\nis an integrable, \\(\\mathcal G\\)-measurable random variable satisfying\n\n\\[\\int_A Z\\,d\\mathbb P = \\int_A X\\,d\\mathbb P \\qquad\\text{for every }A\\in\\mathcal G.\\]\n\nIt is unique almost surely.\n\nTaking \\(A=\\Omega\\) immediately gives\n\n\\[\\mathbb E[\\mathbb E[X\\mid\\mathcal G]] = \\mathbb E[X].\\]\n\nThe basic law of total expectation is therefore a direct consequence of the defining property of conditional expectation.\n\nConditioning on \\(Y\\) means conditioning on \\(\\sigma(Y)\\), the sigma-algebra generated by \\(Y\\). This measure-theoretic formulation does not require a density or a countable set of possible values."
    },
    {
      "heading": "Tower property",
      "text": "If\n\n\\[\\mathcal G\\subseteq\\mathcal H\\subseteq\\mathcal F,\\]\n\nthen\n\n\\[\\mathbb E\\!\\left[ \\mathbb E[X\\mid\\mathcal H]\\mid\\mathcal G \\right] = \\mathbb E[X\\mid\\mathcal G] \\quad\\text{almost surely}.\\]\n\nAveraging an estimate based on finer information over coarser information gives the estimate based directly on the coarser information.\n\nTo prove this, set\n\n\\[Z=\\mathbb E[\\mathbb E[X\\mid\\mathcal H]\\mid\\mathcal G].\\]\n\nFor every \\(A\\in\\mathcal G\\), the inclusion \\(A\\in\\mathcal H\\) implies\n\n\\[\\int_A Z\\,d\\mathbb P = \\int_A\\mathbb E[X\\mid\\mathcal H]\\,d\\mathbb P = \\int_A X\\,d\\mathbb P.\\]\n\nTogether with \\(\\mathcal G\\)-measurability, this identifies \\(Z\\) as a version of \\(\\mathbb E[X\\mid\\mathcal G]\\).\n\nThe reverse order also satisfies\n\n\\[\\mathbb E\\!\\left[ \\mathbb E[X\\mid\\mathcal G]\\mid\\mathcal H \\right] = \\mathbb E[X\\mid\\mathcal G],\\]\n\nbecause a \\(\\mathcal G\\)-measurable random variable is already \\(\\mathcal H\\)-measurable.\n\nAn important random-variable form is\n\n\\[\\mathbb E\\!\\left[ \\mathbb E[X\\mid Y,Z]\\mid Y \\right] = \\mathbb E[X\\mid Y].\\]\n\nThe nesting matters: arbitrary successive conditioning on unrelated information sets does not obey the same simplification."
    },
    {
      "heading": "Examples",
      "text": "Weighted group means\n\nSuppose a production process uses machine A for \\(70\\%\\) of items and machine B for \\(30\\%\\). The mean processing times are 4 minutes and 9 minutes, respectively. If \\(X\\) is the processing time and \\(Y\\) identifies the machine, then\n\n\\[\\mathbb E[X] = 0.7(4)+0.3(9) = 5.5\\text{ minutes}.\\]\n\nThe unweighted average, \\(6.5\\) minutes, is not the overall mean because the machines are not used equally often.\n\nA random success probability\n\nLet \\(P\\) take values in \\([0,1]\\), and suppose\n\n\\[X\\mid P\\sim\\operatorname{Binomial}(n,P),\\]\n\nwhere \\(n\\) is fixed. The conditional mean of this binomial distribution is \\(nP\\), so\n\n\\[\\mathbb E[X] = \\mathbb E[nP] = n\\mathbb E[P].\\]\n\nThis remains valid regardless of the particular distribution of \\(P\\).\n\nA random number of summands\n\nLet \\(N\\) be a nonnegative integer-valued random variable with finite mean. Let \\(X_1,X_2,\\ldots\\) be identically distributed, integrable random variables with mean \\(\\mu\\), and suppose the entire sequence is independent of \\(N\\). Define\n\n\\[S=\\sum_{i=1}^{N}X_i,\\]\n\nwith \\(S=0\\) when \\(N=0\\). Since\n\n\\[\\mathbb E[S\\mid N=n]=n\\mu,\\]\n\nthe law gives\n\n\\[\\mathbb E[S]=\\mu\\,\\mathbb E[N].\\]\n\nIndependence among the \\(X_i\\) is not needed for this mean calculation. Independence from \\(N\\), however, is a sufficient condition that justifies the stated conditional mean."
    },
    {
      "heading": "Consequences and applications",
      "text": "Total probability\n\nApplying the theorem to the indicator of an event \\(A\\) gives\n\n\\[\\mathbb P(A) = \\mathbb E[\\mathbb P(A\\mid Y)].\\]\n\nFor discrete \\(Y\\),\n\n\\[\\mathbb P(A) = \\sum_y \\mathbb P(A\\mid Y=y)\\mathbb P(Y=y).\\]\n\nThus, the law of total probability is the indicator-variable case of total expectation.\n\nVariance decomposition\n\nIf \\(\\mathbb E[X^2]<\\infty\\), applying total expectation to squared deviations gives the law of total variance:\n\n\\[\\operatorname{Var}(X) = \\mathbb E[\\operatorname{Var}(X\\mid Y)] + \\operatorname{Var}(\\mathbb E[X\\mid Y]).\\]\n\nThis separates variance into average within-group variability and variability of the group means.\n\nConditional Monte Carlo\n\nIn the Monte Carlo method, replacing \\(X\\) by a computable conditional expectation \\(\\mathbb E[X\\mid Y]\\) preserves its mean. Under square integrability,\n\n\\[\\operatorname{Var}(\\mathbb E[X\\mid Y]) \\leq \\operatorname{Var}(X).\\]\n\nA simulation based on conditional means can therefore have lower variance, although the computational cost of obtaining those means also matters.\n\nBayesian prediction and stochastic processes\n\nIn Bayesian inference, predictive expectations average parameter-conditional expectations over the parameter’s posterior distribution. For observed data \\(D\\), parameter \\(\\theta\\), and future observation \\(X\\),\n\n\\[\\mathbb E[X\\mid D] = \\mathbb E\\!\\left[ \\mathbb E[X\\mid\\theta,D]\\mid D \\right],\\]\n\nwhenever the required expectations exist.\n\nFor a filtration \\((\\mathcal F_t)\\) and an integrable random variable \\(Z\\), the process\n\n\\[M_t=\\mathbb E[Z\\mid\\mathcal F_t]\\]\n\nis a martingale. Indeed, for \\(s\\leq t\\), the tower property gives\n\n\\[\\mathbb E[M_t\\mid\\mathcal F_s]=M_s.\\]"
    },
    {
      "heading": "Conditions and common pitfalls",
      "text": "- Conditional means must receive the correct weights. Equally weighting groups generally gives a different result from averaging over their population probabilities.\n- Independence is unnecessary. If \\(X\\) and \\(Y\\) are statistically independent, the conditional mean is constant almost surely; the theorem also applies when they are dependent.\n- Integrability cannot be ignored. For example, a Cauchy-distributed random variable has no ordinary expectation, so the finite-mean identity cannot be invoked for it.\n- Conditioning must be nested for the tower simplification. Without an inclusion relation between information sets, replacing repeated conditioning by a single conditional expectation is generally invalid.\n- Expectation does not generally commute with nonlinear functions. The theorem implies\n\n\\[\\mathbb E[g(X)] = \\mathbb E[\\mathbb E[g(X)\\mid Y]]\\]\n\nwhen integrable, but does not generally imply\n\n\\[\\mathbb E[g(X)] = \\mathbb E[g(\\mathbb E[X\\mid Y])].\\]\n\nFor convex \\(g\\), the corresponding inequality is governed by Jensen’s inequality."
    }
  ],
  "links": [
    "probability",
    "expected-value",
    "random-variable",
    "conditional-expectation",
    "probability-distribution",
    "set-partition",
    "sample-space",
    "indicator-function",
    "probability-density-function",
    "probability-space",
    "sigma-algebra",
    "almost-surely",
    "measure-theory",
    "binomial-distribution",
    "variance",
    "monte-carlo-method",
    "bayesian-inference",
    "filtration-probability",
    "martingale",
    "cauchy-distribution",
    "jensens-inequality"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}