Law of total expectation (source code)

= Law of total expectation
{title2=$\mathbb E[\mathbb E[X\mid\mathcal G]]=\mathbb E[X]$}
{wiki}

= Tower property of conditional expectation
{synonym}

= Law of iterated expectation
{synonym}

= Tower property
{synonym}

The law of total expectation makes averaging in stages reliable, provided the outer stage uses the actual <probabilities> of the groups. For an <integrable random variable> $X$ and a sub-<sigma-algebra> $\mathcal G$,
$$
\boxed{\mathbb E[\mathbb E[X\mid\mathcal G]]=\mathbb E[X].}
$$
Replacing each outcome by its group's <conditional mean> preserves the overall <expected value>. In the definition of <conditional expectation>, take the <event> $A=\Omega$ to obtain this identity.<Probability: Theory and Examples (fifth edition) by Rick Durrett/4.1 Conditional Expectation>[Equation (4.1.5), p. 212]{ref}

For a complete finite example, choose a group $Y=A$ with <probability> $1/4$ and $Y=B$ with <probability> $3/4$. Within group $A$, $X$ is $0$ or $4$ with equal <conditional probabilities>; within group $B$, it is $6$ or $10$ with equal <conditional probabilities>. Thus the <joint probability distribution> puts probabilities $1/8,1/8,3/8,3/8$ on $(A,0),(A,4),(B,6),(B,10)$. The <conditional means> are two and eight. Consequently,
$$
\boxed{\mathbb E X=\frac14\cdot2+\frac34\cdot8=\frac{13}{2}.}
$$
Direct averaging of the four values gives the same $0/8+4/8+18/8+30/8=13/2$. Taking the unweighted average of the two group means instead gives five, which describes a different choice of group <probabilities>. This is why the outer weighting matters.

\Image[/total-expectation-weighted-group-averages.png]
{title=Group averages preserve the overall mean when weighted by group probabilities}
{description=The stipulated <joint probability distribution> assigns probabilities $1/8,1/8,3/8,3/8$ to values $0,4,6,10$ in groups $A,A,B,B$. The <conditional means> are two and eight, occurring with probabilities $1/4$ and $3/4$. Both representations have <expected value> $13/2$. The unweighted average of the group means, five, is shown separately as the result of different weighting. These are exact illustrative probabilities, not observations.}

The formula is useful when conditioning on a first choice makes the remaining experiment simple. It can replace a large outcome enumeration by smaller calculations within groups. In a <mixture distribution>, it combines component <means> using mixture weights; in a <random sum of independent claims>, it separates the number of summands from their individual <expected values> under the stated <independence> assumptions. The same averaging step appears in the <law of total variance>.