TL;DR
The conditional expectation is the average value of once you know . Because it depends on , it is itself a random variable. It is the best guess for that you can make from , when "best" means smallest average squared error. Averaging it over all values of gives back the ordinary mean of .
Where you'll see it: in regression, where the ideal prediction is the conditional mean; in filtering, where a Kalman filter updates its estimate as new measurements arrive; and in martingales, which model fair games and the prices of many financial assets.
Intuition
Average, given what you know
Suppose you want the average height of a student in a school. Across the whole school the answer is one number. If you first learn each student's grade, the average height inside each grade is a better guess for any one student. The grade-by-grade averages are the conditional expectation of height given grade. Knowing more gives a sharper average.
That is the whole idea. The unconditional mean ignores what you know, and the conditional mean uses it. Since different outcomes of lead to different averages, the conditional mean is a function of , not a single number.
- E[Y given X = x]
- E[Y], ignoring X
The solid curve is the conditional mean. Each value of gets its own prediction. The dashed line is the unconditional mean, the same prediction for every . The gap between them is the information that carries about .
The math
Definition
For discrete variables, the conditional expectation of given is
and for continuous variables it is . The random variable is obtained by plugging the random value into this function.
Here and are the conditional distributions of given , which restrict the conditional probability to the slice where . The sum or integral is the ordinary expected value, computed with the conditional distribution in place of the marginal.
The law of total expectation
Averaging the conditional mean over returns the overall mean:
Here is the derivation for discrete variables. Start from the definition of and split each across the values of :
The middle step uses the product rule . This is the same idea as the law of total probability, applied to a weighted average.
The best prediction
Suppose you must predict using a function , and you penalise the squared error . The best choice is . To see why, write and expand:
The cross term is zero. Since depends only on , , because . The first term does not depend on , and the second is zero only when . So the conditional mean minimises the error.
Variance decomposition
The same algebra splits the variance into two pieces:
Write , then subtract . The first piece is the average spread inside each group. The second is the spread between the group averages. This decomposition is the reason analysis of variance works.
Worked examples
Flip a fair coin to get , each with probability . If , roll a fair two-sided die labelled 1 and 2, so is uniform on . If , is uniform on .
- Conditional means: and .
- Law of total expectation: .
- Check by listing directly. , and . The direct mean is .
Interpretation: the two group averages, weighted by how often each group occurs, reproduce the overall mean. The direct calculation confirms the shortcut.
A shop records the order value in dollars. New customers make up 30% of orders, with average order value 20 dollars and variance 100 squared dollars. Returning customers make up the other 70%, with average 55 dollars and variance 400 squared dollars.
- Overall mean: dollars.
- Best prediction for a new order: dollars, and for a returning order it is 55 dollars.
- Average within-group variance: .
- Spread of the group means: .
- Total variance: . Check directly: , and .
Interpretation: about 55% of the total variance (310 of 567) is spread inside the groups, and the rest is the difference between the groups. Predicting by customer type removes the second part, but the first part remains and should be reported.
Tradeoffs and failure modes
| Situation | Problem | Better choice |
|---|---|---|
| Error is measured in absolute value, not squares | The conditional mean is no longer the best predictor | Use the conditional median |
| Conditioning on an event of probability zero | The division in the definition is undefined | Define it through densities, or through measure-theoretic conditioning |
| Estimating the conditional mean from few observations per group | Group averages are noisy | Smooth across groups, use regression, or pool sparse groups |
| Assuming the conditional mean is linear | Curvature in the relationship is missed | Nonparametric regression, or a model with the right shape |
| Reporting only the mean | Spread within each group is hidden | Report the conditional variance or quantiles as well |
The most common mistake is to read as . They are different quantities, and a conditional mean in one direction says little about the other.
History
Christiaan Huygens's 1657 treatise on games of chance introduced the idea of an expected value, and averaging within cases was part of solving such problems from the start. A precise general rule for conditioning came much later. Gauss's least-squares work in the early 1800s is the linear special case: the best linear predictor. Andrey Kolmogorov's 1933 foundations defined conditional expectation for general random variables, which made it a rigorous tool. In the 1950s Joseph Doob used it at the core of the theory of martingales, which turned it into a standard instrument in probability and finance.
Check yourself
QuestionRecall: State the law of total expectation.Show answer
. The overall mean of is the average, over the values of , of the mean of within each value.
QuestionComputation: In the customer example, what is if new customers make up 50% of orders instead of 30%?Show answer
dollars. Only the weights change, and the group means stay the same.
QuestionWhy: Why is the conditional mean the best prediction of under squared error?Show answer
Write the expected squared error of a prediction as the error of the conditional mean plus a non-negative term that depends on . The cross term vanishes because the conditional mean's errors average to zero within each value of . The non-negative term is zero only when , so that is the minimiser.
QuestionApplied: A delivery app reports the average delivery time for each weather type. A user plans a meeting and sees only the average for rain. What does the average leave out, and what should the app show instead?Show answer
The average says nothing about how much delivery times vary within rainy weather. Two rainy routes with the same average can have very different spreads, and a late delivery can ruin a meeting. The app should also show the conditional variance or a range, such as the 90th percentile of delivery time given rain. The mean answers "what to expect", and the spread answers "how sure can I be".