Tutorials › Exam P - Probability › Deriving the Law of Total Expectation

Exam P · Conditional Expectation and Decomposition · Tutorial 775 of 915

Deriving the Law of Total Expectation

Learn why an overall expectation is a probability-weighted average of conditional expectations, and how to calculate it for discrete and continuous conditioning variables.

Advanced 12 min read

What You'll Learn

  • Derive the law of total expectation for a discrete conditioning variable
  • Extend the result to continuous conditioning variables using densities
  • Calculate an expectation in a discrete mixture model
  • Integrate conditional means over a continuous distribution
  • Recognize why a nonlinear conditional mean cannot generally be evaluated at the mean conditioning value

Why Average Conditional Means?

When a random outcome depends on a group, operating condition, or other random circumstance, it can be easier to calculate its expected value separately within each circumstance. The overall expected value then combines those conditional means, giving more weight to circumstances that occur more often. This principle is the law of total expectation.

The method applies whether the conditioning variable has a finite set of possible values or varies continuously. The calculation differs in form: a probability-weighted sum for discrete values, and an integral for a continuous variable.

Definition: Let \(X\) be an integrable random variable, meaning \(E[|X|]<\infty\), and let \(Y\) be a random variable. The law of total expectation states that $$ E[X]=E[E[X\mid Y]]. $$ Here \(E[X\mid Y]\) is itself a random variable: it is the conditional mean of \(X\), evaluated at the realized value of \(Y\). Its expectation averages that conditional mean over the distribution of \(Y\).

Derivation for a Discrete Conditioning Variable

Suppose \(Y\) takes countably many possible values \(y_1,y_2,\ldots\), with \(P(Y=y_j)>0\) for each value under consideration. The events \(Y=y_j\) form a partition: they are disjoint, and together they cover all possible outcomes. On the event \(Y=y_j\), the conditional mean of \(X\) is \(E[X\mid Y=y_j]\).

To obtain the unconditional mean, first split the expectation according to this partition. Each conditional mean is weighted by the probability of its event:

$$ \begin{aligned} E[X] &=\sum_j E\!\left[X\,\mathbf{1}_{\{Y=y_j\}}\right]\\ &=\sum_j P(Y=y_j)E[X\mid Y=y_j]\\ &=E[E[X\mid Y]]. \end{aligned} $$

The first equality holds because exactly one indicator \(\mathbf{1}_{\{Y=y_j\}}\) equals 1 on each outcome, so their sum is 1. For the second equality, the definition of conditional expectation on an event with positive probability gives \(E[X\,\mathbf{1}_{\{Y=y_j\}}]=P(Y=y_j)E[X\mid Y=y_j]\). The final sum is the expectation of the random variable \(E[X\mid Y]\), which takes the value \(E[X\mid Y=y_j]\) when \(Y=y_j\).

For a finite set of possible values, this is an ordinary finite sum. For a countable set, the same formula applies when the expectations are well-defined; the integrability condition ensures the unconditional expectation is finite. Values of \(Y\) with probability zero contribute nothing and need not be included.

Worked Example: Combining Claim Means Across Operating Conditions

A hypothetical equipment policy has three possible operating conditions during a year. Condition H occurs with probability \(0.20\), condition M with probability \(0.50\), and condition L with probability \(0.30\). Let \(X\) be the annual claim amount, in dollars. In condition H, \(X\) is equally likely to be $100 or $300. In condition M, \(X\) is $80 with probability \(0.25\) and $0 with probability \(0.75\). In condition L, \(X=0\). Find \(E[X]\).

Method: discrete law of total expectation. First calculate the conditional mean in each condition.

In condition H, \(E[X\mid H]=0.50(100)+0.50(300)=50+150=200\) dollars.

In condition M, \(E[X\mid M]=0.25(80)+0.75(0)=20+0=20\) dollars. In condition L, \(E[X\mid L]=0\) dollars because the claim is always zero.

Now weight these conditional means by the probabilities of the conditions:

$$ \begin{aligned} E[X] &=P(H)E[X\mid H]+P(M)E[X\mid M]+P(L)E[X\mid L]\\ &=0.20(200)+0.50(20)+0.30(0)\\ &=40+10+0\\ &=50\text{ dollars}. \end{aligned} $$

Check. The unconditional probabilities of claims of $100, $300, $80, and $0 are respectively \(0.20(0.50)=0.10\), \(0.20(0.50)=0.10\), \(0.50(0.25)=0.125\), and \(1-0.10-0.10-0.125=0.675\). Thus the direct calculation is \(0.10(100)+0.10(300)+0.125(80)+0.675(0)=10+30+10+0=50\) dollars, agreeing with the result.

Common mistake avoided: Do not give the three conditions equal weight. The correct weights are their probabilities, \(0.20\), \(0.50\), and \(0.30\), not one-third each.

Derivation for a Continuous Conditioning Variable

If \(Y\) has a density \(f_Y(y)\), conditional means are averaged across the possible values of \(Y\) using that density. In the common case where \((X,Y)\) has a joint density \(f_{X,Y}(x,y)\), the conditional density is \(f_{X\mid Y}(x\mid y)=f_{X,Y}(x,y)/f_Y(y)\) wherever \(f_Y(y)>0\). Integrating first over \(x\), then over \(y\), gives the continuous form:

$$ \begin{aligned} E[X] &=\int\!\!\int x f_{X,Y}(x,y)\,dx\,dy\\ &=\int\left[\int x f_{X\mid Y}(x\mid y)\,dx\right]f_Y(y)\,dy\\ &=\int E[X\mid Y=y]f_Y(y)\,dy\\ &=E[E[X\mid Y]]. \end{aligned} $$

The second line uses \(f_{X,Y}(x,y)=f_{X\mid Y}(x\mid y)f_Y(y)\). The expression in square brackets is the conditional mean at \(Y=y\). The final integral averages that conditional mean over the density of \(Y\). Interchanging the order of integration is justified when the required integrability conditions hold; in particular, \(E[|X|]<\infty\) is a standard sufficient condition for this expectation identity.

The density formula is not limited to a continuous \(X\); what matters here is that the conditioning variable \(Y\) has a density and that a suitable conditional distribution for \(X\) given \(Y=y\) is available. For discrete \(Y\), use a sum instead. More generally, the law remains valid for conditioning variables whose distributions are neither purely discrete nor purely continuous, with expectation taken over the distribution of \(Y\).

Worked Example: A Conditional Exponential Waiting Time

In a hypothetical monitoring system, the operating-load index \(Y\) is uniform on the interval from 0 to 2. Given \(Y=y\), a response time \(X\), in hours, has an exponential distribution with mean \(1+y\). Find the unconditional expected response time.

Method: integrate the conditional mean against the density of the conditioning variable. The density of \(Y\) is \(f_Y(y)=1/2\) for \(0\leq y\leq2\). By the stated conditional exponential model, \(E[X\mid Y=y]=1+y\) hours. Therefore,

$$ \begin{aligned} E[X] &=\int_0^2 E[X\mid Y=y]f_Y(y)\,dy\\ &=\int_0^2 (1+y)\frac{1}{2}\,dy\\ &=\frac{1}{2}\left[y+\frac{y^2}{2}\right]_0^2\\ &=\frac{1}{2}\left(2+\frac{4}{2}\right)\\ &=2\text{ hours}. \end{aligned} $$

Check. Since \(Y\) is uniform from 0 to 2, its mean is \((0+2)/2=1\). The conditional mean \(1+Y\) is linear in \(Y\), so its average is \(1+E[Y]=1+1=2\) hours, matching the integral.

Common mistake avoided: The exponential distribution describes \(X\) conditionally. Its parameter changes with \(y\), so using one fixed exponential mean for all operating loads would ignore the model. The conditional mean must be integrated over the distribution of \(Y\).

Nonlinear Conditional Means and a Common Trap

The law of total expectation does not say that \(E[X]\) is the conditional mean evaluated at \(E[Y]\). It says to average the function \(y\mapsto E[X\mid Y=y]\) over the distribution of \(Y\). If that function is nonlinear, these two calculations generally differ:

$$ E[X]=E[E[X\mid Y]] \qquad\text{but generally}\qquad E[E[X\mid Y]]\ne E[X\mid Y=E[Y]]. $$

A carefully chosen example makes the distinction visible. Suppose the conditional mean is \(2+y^2\). Averaging this mean involves \(E[Y^2]\), which is generally not the same as \((E[Y])^2\). Substituting the mean of \(Y\) into the conditional-mean formula therefore loses information about the spread of \(Y\).

Worked Example: A Poisson Mixture with a Nonlinear Mean

In a hypothetical counting model, \(Y\) is uniform on \([-1,1]\). Given \(Y=y\), the count \(X\) has a Poisson distribution with parameter \(2+y^2\). Find \(E[X]\), and identify the error in evaluating the conditional mean only at \(E[Y]\).

Method: use the conditional mean of the Poisson distribution, then integrate. A Poisson random variable with parameter \(\lambda\) has mean \(\lambda\). Thus \(E[X\mid Y=y]=2+y^2\). The density of \(Y\) is \(1/2\) on \([-1,1]\), so

$$ \begin{aligned} E[X] &=\int_{-1}^{1}(2+y^2)\frac{1}{2}\,dy\\ &=\frac{1}{2}\left[2y+\frac{y^3}{3}\right]_{-1}^{1}\\ &=\frac{1}{2}\left(\frac{7}{3}-\left(-\frac{7}{3}\right)\right)\\ &=\frac{7}{3}. \end{aligned} $$

Check using the second moment of the uniform variable. For \(Y\) uniform on \([-1,1]\), \(E[Y^2]=\int_{-1}^{1}y^2(1/2)\,dy=1/3\). Hence \(E[2+Y^2]=2+1/3=7/3\), as found by integration.

The tempting but incorrect calculation is \(E[X\mid Y=E[Y]]\). Since \(E[Y]=0\), it gives \(E[X\mid Y=0]=2+0^2=2\), not \(7/3\). This substitution replaces \(E[Y^2]=1/3\) with \((E[Y])^2=0\), which is not valid. The conditional mean must be averaged over the possible values of \(Y\), not evaluated at its average.

A Reliable Calculation Sequence

For a mixture or a model with a random conditioning variable, separate the calculation into the conditional step and the averaging step. This keeps the model assumptions visible and makes it easier to check whether the weights or density have been used correctly.

1
Identify the conditioning variable.
List its possible values and probabilities if it is discrete, or its density and support if it is continuous.
2
Find the conditional mean.
Use the specified conditional distribution to calculate \(E[X\mid Y=y]\) for each relevant value \(y\).
3
Average over the distribution of the conditioning variable.
Use a probability-weighted sum for discrete \(Y\), or integrate against \(f_Y(y)\) for continuous \(Y\).
4
Check the result.
When feasible, compare with a direct unconditional calculation or verify that the weights sum to 1 and the units are consistent.

This sequence is aligned with the SOA Exam P (Probability) syllabus because it turns a conditional model into an unconditional expectation while preserving the role of each possible circumstance. It is especially useful when the conditional distribution is simpler than the unconditional distribution.

Key takeaway: The unconditional mean is the average of the conditional means, weighted according to how likely the conditioning values are. For discrete conditioning, sum the weighted means; for continuous conditioning, integrate the conditional mean against the density. Do not replace that averaging step by plugging the mean conditioning value into a nonlinear conditional-mean function.

Check Your Understanding

For each problem, calculate the unconditional expectation by conditioning on the stated variable.

  1. A hypothetical repair cost \(Z\) has conditional means of $12 in state A and $4 in state B. State A occurs with probability \(0.25\), and state B occurs otherwise. Find \(E[Z]\). (Answer: $6)
  2. A random setting \(T\) is uniform on \([0,3]\). Given \(T=t\), a hypothetical waiting time \(W\) has an exponential distribution with mean \(2t+1\) minutes. Find \(E[W]\). (Answer: 4 minutes)
  3. A hypothetical count \(N\), conditional on group \(G\), has mean 10 if \(G=A\) and mean 20 if \(G=B\). If \(P(G=A)=0.20\) and \(P(G=B)=0.30\), with the remaining probability assigned to group C where the conditional mean is 40, find \(E[N]\). (Answer: 28)
  4. Let \(Y\) be uniform on \([0,1]\). Given \(Y=y\), let \(X\) have a Poisson distribution with parameter \(1+4y\). Find \(E[X]\). (Answer: 3)
  5. A hypothetical event count \(K\) has conditional mean 5 in environment A and 2 in environment B. Environment A occurs with probability \(0.40\), and B occurs with probability \(0.60\). Find the overall expected count. (Answer: 3.2)
Clinical Biostats