Variance Within Groups and Between Groups
When information about a random variable is available, its remaining uncertainty can be measured by a conditional variance. This is itself a random variable: its value may depend on the information observed. The law of total variance connects this conditional uncertainty to the ordinary variance. It says that total variation has two parts: average variation remaining within groups, and variation between the groups’ conditional means.
Throughout, \((\Omega,\mathcal{F},\mathbb{P})\) is a probability space, and \(X:\Omega\to\mathbb{R}\) is a real-valued random variable with \(\mathbb{E}[X^2]<\infty\). Thus \(X\) is square-integrable, and \(\operatorname{Var}(X)=\mathbb{E}[(X-\mathbb{E}X)^2]\) is finite. Let \(\mathcal{G}\) be a sub-sigma-algebra of \(\mathcal{F}\), representing the information being conditioned on. Conditional expectations are defined up to almost-sure equality; all identities between them below hold \(\mathbb{P}\)-a.s.
The assumption \(\mathbb{E}[X^2]<\infty\) ensures that this definition is meaningful: \(Y\) is square-integrable by conditional Jensen’s inequality, so \((X-Y)^2\) is integrable. The conditional variance records the squared error after subtracting the conditional mean, rather than the squared error after subtracting the unconditional mean.
A Formula in Terms of Conditional Moments
Proof. Let \(Y=\mathbb{E}[X\mid\mathcal{G}]\). Expanding the square gives \((X-Y)^2=X^2-2XY+Y^2\). Each term is integrable: \(X^2\) and \(Y^2\) are integrable, and \(XY\) is integrable by the Cauchy–Schwarz inequality. By linearity of conditional expectation and the property of pulling out a \(\mathcal{G}\)-measurable factor, \(\mathbb{E}[XY\mid\mathcal{G}]=Y\mathbb{E}[X\mid\mathcal{G}]=Y^2\) and \(\mathbb{E}[Y^2\mid\mathcal{G}]=Y^2\). Therefore \(\mathbb{E}[(X-Y)^2\mid\mathcal{G}]=\mathbb{E}[X^2\mid\mathcal{G}]-2Y^2+Y^2=\mathbb{E}[X^2\mid\mathcal{G}]-Y^2\) almost surely. \(\square\)
In particular, the difference between the conditional second moment and the square of the conditional mean is nonnegative almost surely. This also follows directly from the definition as a conditional expectation of a nonnegative random variable. The formula is useful for calculations, but the definition explains what the quantity measures.
The Law of Total Variance
Proof. Put \(Y=\mathbb{E}[X\mid\mathcal{G}]\), \(Z=X-Y\), and \(m=\mathbb{E}[X]\). The tower property gives \(\mathbb{E}[Y]=m\) and \(\mathbb{E}[Z\mid\mathcal{G}]=\mathbb{E}[X\mid\mathcal{G}]-Y=0\) almost surely. By the definition of conditional variance and the tower property, \(\mathbb{E}[\operatorname{Var}(X\mid\mathcal{G})]=\mathbb{E}[\mathbb{E}[Z^2\mid\mathcal{G}]]=\mathbb{E}[Z^2]\). All these expectations are finite because \(X\) and \(Y\) are square-integrable.
Since \(X-m=Z+(Y-m)\), expanding the square and taking expectations gives \(\operatorname{Var}(X)=\mathbb{E}[Z^2]+2\mathbb{E}[Z(Y-m)]+\mathbb{E}[(Y-m)^2]\). The cross term is zero. Indeed, \(Y-m\) is \(\mathcal{G}\)-measurable, and the conditional-expectation pulling-out property gives \(\mathbb{E}[Z(Y-m)]=\mathbb{E}[(Y-m)\mathbb{E}[Z\mid\mathcal{G}]]=0\). This use of the property is valid for the possibly unbounded factor \(Y-m\), since both factors are square-integrable and their product is integrable. The last term is \(\operatorname{Var}(Y)\), because \(\mathbb{E}[Y]=m\). Substituting \(\mathbb{E}[Z^2]=\mathbb{E}[\operatorname{Var}(X\mid\mathcal{G})]\) proves the identity. \(\square\)
The identity includes degenerate cases. If \(\mathcal{G}\) contains no information beyond events of probability zero or one, then \(Y=m\) almost surely and the between-group term is zero. If \(X\) is \(\mathcal{G}\)-measurable, then \(Y=X\) almost surely, the conditional variance is zero, and all variation is in the conditional mean.
Finite Partitions and Worked Calculations
For a finite partition \(\{A_1,\ldots,A_k\}\) with \(\mathbb{P}(A_i)>0\) for every \(i\), let \(\mathcal{G}\) be the sigma-algebra generated by the partition. On \(A_i\), the conditional mean is \(\mathbb{E}[X\mid A_i]=\mathbb{E}[X\chi_{A_i}]/\mathbb{P}(A_i)\). The conditional variance on that cell is \(\mathbb{E}[X^2\mid A_i]-\mathbb{E}[X\mid A_i]^2\). Values assigned on zero-probability cells do not affect any almost-sure statement or expectation; the formulas using division by \(\mathbb{P}(A_i)\) are used only for positive-probability cells.
Worked Example: Two Groups with Different Means
Take four equally likely outcomes. Let \(A_1\) contain two outcomes on which \(X\) is \(0\) and \(2\), and let \(A_2\) contain the other two, on which \(X\) is \(3\) and \(5\). Condition on the partition \(\{A_1,A_2\}\). Compute both terms in the law of total variance and check the total directly.
Each cell has probability \(1/2\). Within \(A_1\), the conditional mean is \((0+2)/2=1\), and the conditional variance is \(((0-1)^2+(2-1)^2)/2=(1+1)/2=1\). Within \(A_2\), the conditional mean is \((3+5)/2=4\), and the conditional variance is \(((3-4)^2+(5-4)^2)/2=(1+1)/2=1\). Thus the conditional variance is \(1\) on each cell, so its expectation is \((1/2)\cdot1+(1/2)\cdot1=1\).
The conditional mean takes the values \(1\) and \(4\), each with probability \(1/2\). Its expectation is \((1/2)\cdot1+(1/2)\cdot4=5/2\), and its variance is \(((1-5/2)^2+(4-5/2)^2)/2=((9/4)+(9/4))/2=9/4\). Therefore the law gives \(\operatorname{Var}(X)=1+9/4=13/4\).
Direct check: the four values have mean \((0+2+3+5)/4=10/4=5/2\). Their squared deviations from \(5/2\) are \(25/4,1/4,1/4,25/4\), whose average is \((52/4)/4=13/4\). This agrees with the decomposition.
Worked Example: A Finite Mixture
Let a two-valued group indicator \(G\) select group 1 with probability \(1/3\) and group 2 with probability \(2/3\). Given group 1, let \(X\) take values \(0\) and \(2\) with equal probabilities. Given group 2, let \(X\) take values \(2\) and \(4\) with equal probabilities. Compute the conditional and unconditional variances.
In group 1, the mean is \((0+2)/2=1\) and the variance is \(((0-1)^2+(2-1)^2)/2=1\). In group 2, the mean is \((2+4)/2=3\) and the variance is \(((2-3)^2+(4-3)^2)/2=1\). Hence \(\mathbb{E}[\operatorname{Var}(X\mid G)]=(1/3)\cdot1+(2/3)\cdot1=1\).
The unconditional mean, computed from the conditional means, is \((1/3)\cdot1+(2/3)\cdot3=7/3\). The variance of those conditional means is \((1/3)(1-7/3)^2+(2/3)(3-7/3)^2=(1/3)(16/9)+(2/3)(4/9)=24/27=8/9\). Thus the law gives \(\operatorname{Var}(X)=1+8/9=17/9\).
Direct check: unconditionally, \(X=0\) has probability \((1/3)(1/2)=1/6\); \(X=2\) has probability \((1/3)(1/2)+(2/3)(1/2)=1/6+1/3=1/2\); and \(X=4\) has probability \((2/3)(1/2)=1/3\). These probabilities sum to \(1/6+1/2+1/3=1\). The mean is \(0\cdot(1/6)+2\cdot(1/2)+4\cdot(1/3)=1+4/3=7/3\). The second moment is \(0^2\cdot(1/6)+2^2\cdot(1/2)+4^2\cdot(1/3)=2+16/3=22/3\). Therefore the variance is \(22/3-(7/3)^2=66/9-49/9=17/9\), as before.
Worked Example: Conditioning a Fair Die on Parity
Let \(X\) be the outcome of a fair six-sided die, so each value in \(\{1,2,3,4,5,6\}\) has probability \(1/6\). Let \(\mathcal{G}\) record whether the outcome is odd or even. Compute the conditional variances, the variance of the conditional mean, and the ordinary variance.
The odd cell is \(\{1,3,5\}\), and the even cell is \(\{2,4,6\}\); each has probability \(3/6=1/2\). The conditional mean on the odd cell is \((1+3+5)/3=3\); its variance is \(((1-3)^2+(3-3)^2+(5-3)^2)/3=(4+0+4)/3=8/3\). The conditional mean on the even cell is \((2+4+6)/3=4\); its variance is \(((2-4)^2+(4-4)^2+(6-4)^2)/3=(4+0+4)/3=8/3\). Thus \(\mathbb{E}[\operatorname{Var}(X\mid\mathcal{G})]=(1/2)(8/3)+(1/2)(8/3)=8/3\).
The conditional mean is \(3\) or \(4\), each with probability \(1/2\), so its mean is \((3+4)/2=7/2\) and its variance is \(((3-7/2)^2+(4-7/2)^2)/2=(1/4+1/4)/2=1/4\). The law gives \(8/3+1/4=32/12+3/12=35/12\).
Direct check: the die mean is \((1+2+3+4+5+6)/6=21/6=7/2\). The squared deviations are \(25/4,9/4,1/4,1/4,9/4,25/4\), with sum \(70/4=35/2\). Their average is \((35/2)/6=35/12\), which confirms the result.
A Common Mistake: Omitting Between-Group Variation
A common error is to calculate the conditional variances and then report their average as the unconditional variance. That omits the variation in conditional means. In the finite-mixture example, the average conditional variance is \(1\), but the unconditional variance is \(17/9\). The missing term is the variance \(8/9\) of the group-specific conditional means.
The conditional-moment formula also prevents a related mistake: \(\operatorname{Var}(X\mid\mathcal{G})\) is not simply \(\mathbb{E}[X^2\mid\mathcal{G}]\). One must subtract the square of the conditional mean, not the conditional mean itself. The law of total variance is useful precisely because it keeps the two sources of variation separate. For a finite partition, it is often efficient to compute each cell’s mean and variance first, then combine the within-cell variances and the between-cell means.
Check Your Understanding
Use the definition and the law of total variance to organize each calculation.
- For a square-integrable \(X\) and a sub-sigma-algebra \(\mathcal{G}\), derive the conditional-moment formula from \(\mathbb{E}[(X-\mathbb{E}[X\mid\mathcal{G}])^2\mid\mathcal{G}]\).
- Suppose \(X\) has conditional mean \(2\) and conditional variance \(3\) on one group, and conditional mean \(5\) and conditional variance \(3\) on another group. The groups have probabilities \(1/4\) and \(3/4\). Find the average conditional variance and the variance of the conditional mean.
- If \(X\) is \(\mathcal{G}\)-measurable and square-integrable, what are \(\operatorname{Var}(X\mid\mathcal{G})\) and \(\operatorname{Var}(\mathbb{E}[X\mid\mathcal{G}])\)? Verify that their sum is \(\operatorname{Var}(X)\).
- In the fair-die example, why does knowing parity change the conditional mean but not the conditional variance?
- For a finite partition containing a cell of probability zero, why should the conditional mean formula using division by the cell probability not be applied on that cell?