Contents / Probability / Expectation, Covariance and Conditional Expectation
Chapter 5
Expectation, Covariance and Conditional Expectation
Covariance and correlation, the Cauchy-Schwarz bound, conditional expectation as a random variable, the tower property, the law of total variance, best prediction, and Jensen's inequality.
Introduction
Two results from earlier chapters sit awkwardly next to each other. The theorem Linearity of expectation holds with no hypotheses at all: whether and are independent, dependent, or the same variable twice over. The theorem Variance of a sum of independent variables is not like that. It says , and it says so only for independent and — and when we proved it, independence entered at exactly one step and was never mentioned again.
That asymmetry is not an accident of the proof, and it is not a limitation we are stuck with. There is a number that measures precisely what independence was buying us, and once we name it the variance of a sum becomes an identity with no hypotheses whatsoever. The number is the covariance, and the corrected statement is
Independence forces the covariance to vanish, which is why the earlier theorem is true; but the identity above is true always. Half of this chapter is the study of that one extra term — its algebra, its normalised cousin the correlation coefficient, the sharp bound , and, crucially, the fact that a zero covariance does not buy independence back. The converse fails, and it fails for an example so simple that you can compute both sides by hand.
The other half is about a harder and more valuable object. Suppose you are told the value of and asked for your best guess at . The answer is a conditional expectation, and the surprising thing is that the most useful version of it is not a number but a random variable: is a function of , and since is random, so is it. Nearly every difficulty students have with this topic traces back to that one point, so we will belabour it. Out of it come three results that carry a great deal of weight — the tower property, which computes an expectation by conditioning on whatever you happen to know; the law of total variance, which splits uncertainty into a within-group part and a between-group part; and the theorem that is the best possible predictor of from in the mean-square sense, which is the precise reason regression is about conditional means and not about anything else.
The chapter closes with Jensen's inequality, the general statement about convex functions of which is the smallest special case. Together these results are the working vocabulary of every later subject that uses probability: portfolio variance, the bias-variance decomposition, random-effects models, martingales, and the entire theory of estimation.
5.1Covariance
Variance measures how far a single variable strays from its own mean. If we have two variables, there is a second question available: when is above its mean, does tend to be above its mean as well? The obvious way to measure that is to multiply the two deviations together and average.
Definition 5.1 (Covariance). Let and be random variables with finite means and , and suppose . The covariance of and is
Read the product inside the expectation one outcome at a time. If an outcome has above its mean and above its mean, both factors are positive and the product contributes a positive amount. If both are below their means, both factors are negative and the product is again positive. Only outcomes where the two deviations point in opposite directions contribute negatively. So the covariance is an average of signed contributions, positive when the variables move together and negative when they move against each other, and its sign is the summary of which tendency wins.
Intuition. Draw the joint distribution as a cloud of points and put the crosshairs at . The crosshairs cut the plane into four quadrants. Points in the upper-right and lower-left quadrants push the covariance up; points in the upper-left and lower-right push it down. The covariance is the average push, weighted by probability and by how far out the point sits — a point far from both means counts for much more than one near the crosshairs, because the contribution is a product of the two deviations, not a count.
The defining formula is the one to think with, but it is almost never the one to compute with, because it asks you to know both means before you start and then to average a product of deviations. Expanding the product gives a form built out of raw moments instead.
Proposition 5.3 (Computational formula for the covariance). If and have finite second moments, then
Proof. Expand the product inside the expectation:
The right-hand side is a linear combination of the random variables , and together with a constant, so the theorem Linearity of expectation applies term by term:
which collapses to . The finite second moments guarantee by the theorem Cauchy–Schwarz for random variables proved in the next section, so every expectation written here exists.∎
This is the exact analogue of the proposition Computational formula for the variance, and for the same reason: setting in one turns it into the other. That is worth recording as a statement of its own, because it is the fact that makes covariance a genuine generalisation of variance rather than a new and unrelated quantity.
Proposition 5.4 (Variance is a self-covariance). For any with finite variance, .
Proof. Put in the definition: , which is the definition of .∎
Example 5.5 (A joint distribution with positive covariance). Let the pair take each of the four values , , , with probability . Compute , and .
Solution.
- The marginal of puts mass on each of , so . The marginal of is the same set of values, so as well.
- For the cross moment, .
- By the proposition Computational formula for the covariance, .
- For the variances, , so , and by symmetry too.
- Check against the definition: the four deviation products are , , and , averaging to ✓.
The algebra of covariance
Covariance is a bilinear form: linear in each argument when the other is held fixed, and symmetric. Everything computational in this chapter follows from that one structural fact, so it deserves a careful statement and a careful proof.
Theorem 5.6 (Bilinearity and symmetry of covariance). Let , , be random variables with finite second moments and let , , be constants. Then
- Symmetry: .
- Constants: , and .
- Additivity: .
Consequently, for any constants , and variables , ,
Proof. (1) The product is the same random variable as , so the two expectations are equal.
(2) A constant has , so its deviation is the zero random variable and the product is identically zero. For the affine case, has mean , so its deviation is : the shift cancels itself. Hence
by linearity of expectation.
(3) The mean of is by the theorem Linearity of expectation, so the deviation of the sum is the sum of the deviations. Then
and expanding the bracket and applying linearity of expectation to the two terms gives .
The general formula follows by induction: (2) and (3) together give linearity in the first argument for a finite linear combination, and (1) transfers it to the second.∎
Part (2) contains a fact worth isolating: covariance does not see additive shifts. Measuring temperature from a different zero, or counting profits net of a fixed cost, changes neither variance nor covariance. Multiplicative rescaling, by contrast, is seen in full — and that is the source of the interpretive problem we solve in the next section.
Pitfall. The magnitude of a covariance means nothing on its own. If is a length in metres and a length in centimetres, then carries units of metre-centimetres, and switching to metres divides the number by without changing the relationship one bit. A covariance of is not evidence of a weak association, and a covariance of is not evidence of a strong one. Only the sign of a covariance is interpretable by itself; for magnitude, normalise it into a correlation.
The variance of a sum, without hypotheses
Now we can repay the debt from the start of the chapter.
Theorem 5.7 (Variance of a sum). For any and with finite variances,
and likewise . No independence is assumed.
Proof. By the proposition Variance is a self-covariance, . Expand by the theorem Bilinearity and symmetry of covariance:
The two middle terms are equal by symmetry, and the outer two are and . For the difference, write and use from part (2) of the same theorem.∎
Compare this with the theorem Variance of a sum of independent variables. That result is now a corollary of this one plus a single extra fact — that independence makes the covariance vanish — which is the content of the section Independence and Zero Covariance. What we have gained is an identity that survives dependence, and a diagnosis of what dependence costs: a positively correlated pair is more variable in aggregate than two independent ones, a negatively correlated pair less. That single sentence is the mathematical content of diversification.
Corollary 5.8 (Variance of a linear combination). Let have finite variances and let , be constants. Then
If the are pairwise uncorrelated, the double sum vanishes and .
Proof. The constant contributes nothing, by the proposition Variance under a linear change of scale. Write . By the proposition Variance is a self-covariance and the general bilinearity formula,
Split the double sum into the diagonal terms , each equal to , and the off-diagonal terms. By symmetry the pair and contribute the same amount, which is why the off-diagonal sum is written once over and doubled.∎
Example 5.9 (Two assets). An investor puts a fraction of her money in asset and in asset . Returns have , and (in squared percent). Find the variance of the portfolio return at , and find the that minimises it.
Solution.
- By the corollary Variance of a linear combination, .
- At : . Both assets alone are far more variable than the mixture, because the negative covariance subtracts.
- Expand in general: .
- This is a upward parabola in ; setting the derivative to zero gives .
- The minimum value is , smaller still. The general rule behind the arithmetic: mixing helps most when the covariance is most negative.
Remark. There is a useful sanity check hidden in the corollary Variance of a linear combination. Because for every choice of the , the matrix of covariances must be positive semidefinite. Not every symmetric matrix is a legitimate covariance matrix, and a set of pairwise correlations quoted without regard to that constraint can be jointly impossible — three variables cannot all be correlated with each other, for instance.
5.2Correlation and the Cauchy–Schwarz Bound
The pitfall above says covariance has the wrong units. The fix is the standard one in statistics: divide by the natural scale of each variable, which is its standard deviation.
Definition 5.10 (Correlation coefficient). Let and have finite, strictly positive variances. The correlation (or Pearson correlation coefficient) of and is
and are called uncorrelated when , equivalently when .
The requirement that the variances be strictly positive is not a technicality to skip past: a degenerate variable, one that equals a constant with probability one, has no correlation with anything, because the definition would divide by zero. That is the right answer rather than a defect — a quantity that never varies cannot be said to vary along with anything else.
Proposition 5.11 (Correlation is unit-free). Let and be constants. Then
In particular is unchanged by any change of units with positive scale factors, and by any shift of origin.
Proof. By part (2) of the theorem Bilinearity and symmetry of covariance, . By the proposition Variance under a linear change of scale, the standard deviations become and . Dividing,
which is when and when .∎
So converting a temperature from Celsius to Fahrenheit, or a price from euros to yen, leaves every correlation in a study untouched, while reversing a scale (measuring debt instead of wealth) flips every sign. This is exactly the behaviour one wants from a measure of association, and it is why correlations, not covariances, get reported.
Cauchy–Schwarz
The second thing one wants is a fixed scale — a number that means the same thing in every problem, with a known maximum. That maximum exists, and proving it is the same argument that proves the Cauchy–Schwarz inequality in linear algebra, run in the vector space of random variables with .
Theorem 5.12 (Cauchy–Schwarz for random variables). Let and be random variables with and . Then and
Equality holds if and only if there are constants , not both zero, with — that is, if and only if and are proportional almost surely.
Proof. First, integrability: since for all reals, monotonicity of expectation gives , so exists.
If then almost surely, so almost surely, both sides are , and the equality case holds with , . So assume .
For every real consider the non-negative random variable . Expectation preserves the inequality , so
using linearity of expectation to expand. Thus is a quadratic in with positive leading coefficient that is never negative, so its discriminant cannot be positive:
which rearranges to the stated inequality.
For equality: says the discriminant is exactly zero, so has a repeated real root , i.e. . A non-negative random variable with zero expectation is zero almost surely, so , giving the stated relation with , . Conversely, if with, say, , then almost surely and substituting shows both sides equal .∎
Intuition. Think of as a dot product of two vectors, with the squared length of . Cauchy–Schwarz then reads , which is the statement that a dot product is and a cosine cannot exceed in size. Equality is the case : the vectors are parallel. Every clause of the theorem, including the almost-sure proportionality in the equality case, is the geometry of that picture transcribed.
Applying the theorem to the centred variables is what bounds the correlation.
Corollary 5.13 (The correlation bound). If and have finite, positive variances then
Moreover if and only if almost surely for some constants and ; the sign of is then the sign of .
Proof. Apply the theorem Cauchy–Schwarz for random variables to and . Then , and , so
Both variances are positive, so dividing and taking square roots gives , i.e. .
Equality holds exactly when and are proportional almost surely: for some constant , which is with . (The constant cannot be , since that would force .) Finally by bilinearity, and , so .∎
So lives on a fixed scale with interpretable endpoints: means an exact increasing straight-line relationship, an exact decreasing one, and values in between measure how close the cloud comes to a line. That last phrase is the whole warning label, and we return to it in the next section.
Example 5.14 (Correlation of the four-point distribution). Find for the distribution of the example A joint distribution with positive covariance, and find .
Solution.
- We computed and .
- Hence and .
- Strong positive association, but not perfect — consistent with the picture, where the four points do not lie on a line.
- For the transformed variable, apply the proposition Correlation is unit-free with , : since , .
Example 5.15 (Correlation of a variable with its own sum). Let and be independent with the same variance , and let . Find .
Solution.
- By bilinearity, , the covariance term vanishing by independence.
- By the theorem Variance of a sum, , so .
- Therefore .
- Note the answer does not depend on at all — as the proposition Correlation is unit-free promises, a correlation cannot depend on the scale of measurement.
Pitfall. A correlation of does not mean " of a perfect relationship", and it is not twice as strong as in any meaningful sense. The quantity that admits a proportional reading is , which the section Conditional Expectation as the Best Predictor identifies as the fraction of the variance of removed by the best linear prediction from . So accounts for of the variance and for — a factor of four, not two.
5.3Independence and Zero Covariance
We come to the implication that makes the earlier variance theorem work, and to the converse that fails.
Proof. The theorem Expectation of a product under independence of the chapter Joint Distributions gives for independent and (the discrete case is the lemma Expectation of a product of independent variables). Substituting into the proposition Computational formula for the covariance,
Dividing by the positive number gives .∎
Corollary 5.17 (Variance adds under independence). If are pairwise independent with finite variances, then .
Proof. Every cross term in the corollary Variance of a linear combination is a covariance between an independent pair, hence zero by the theorem Independence implies zero covariance; the diagonal terms remain. Note that only pairwise independence is used — full mutual independence is more than this result needs.∎
That recovers the theorem Variance of a sum of independent variables and, better, isolates the exact role independence played: it killed one term. Any other hypothesis that kills the same term would do just as well, and "uncorrelated" is precisely the name of that weaker hypothesis. The natural question is whether the two hypotheses are actually the same. They are not.
Proof. Let be uniform on , so its density is on that interval, and set . All moments exist because the range is bounded.
By symmetry of the density about , every odd moment vanishes:
(Each integrand is an odd function integrated over an interval symmetric about the origin.) Now compute the covariance from the proposition Computational formula for the covariance, using :
So and are uncorrelated. But is a function of : knowing determines exactly. Independence would require , whereas the left side is and the right side is . Hence and are not independent.∎
The figure says in one glance what the algebra says in five lines. The dependence here is real and strong — is determined by — but it is perfectly symmetric, and correlation only ever detects the linear component of a relationship. A symmetric U-shape has no linear component at all: the best straight line through it is flat.
Intuition. Correlation asks one question and one question only: "does a straight line through this cloud tilt up or down, and by how much relative to the scatter?" For the parabola the answer is "it does not tilt", and is a correct answer to the question asked. It is simply not an answer to the question "are these variables related?", which is what people hear.
Pitfall. "Uncorrelated" and "independent" are not synonyms, and the direction of the implication matters in practice.
- Independent uncorrelated. Always true.
- Uncorrelated independent. False in general.
So a sample correlation near zero is never evidence of independence; it is evidence of no linear trend. Conversely, if you know only that a pair is uncorrelated, you may still use — that identity needs only the covariance term to vanish — but you may not use for general functions , which needs genuine independence. Indeed in the counterexample, and already break it.
There is one important setting where the converse does hold, and it is worth knowing precisely because it is so often over-generalised.
Proposition 5.20 (The jointly normal exception). If has a bivariate normal distribution and , then and are independent.
Proof. The bivariate normal density is a single exponential whose exponent is a quadratic form in and ; the only term coupling to carries a factor . Setting makes the exponent split as a function of plus a function of , so the joint density factors as the product of the two marginal normal densities, which is independence by the factorisation criterion. The explicit density and the full computation are the theorem Zero correlation implies independence for the bivariate normal in the chapter Joint Distributions.∎
Pitfall. The hypothesis in the proposition The jointly normal exception is that the pair is jointly normal, not merely that each of and is normal on its own. Two normal marginals do not make a normal joint distribution. For a counterexample, let and let be with probability each, independent of ; put and . Then is also standard normal, and , yet always. Uncorrelated, normal marginals, and wildly dependent.
5.4Conditional Expectation
Everything so far summarises a joint distribution with a single number. We now ask a sharper question: given that has turned out to equal , what do we expect to be? The chapter Foundations of Probability already defined conditional probability; conditional expectation is the expectation computed under that conditional distribution.
Definition 5.21 (Conditional expectation given an event value). Let and be discrete. For any with , the conditional pmf of given is
and the conditional expectation of given is
provided the sum converges absolutely. In the jointly continuous case, with joint density and marginal , the conditional density is and
Nothing here is new machinery: a conditional pmf is a pmf — it is non-negative and sums to , since dividing the joint masses on the slice by the total mass of that slice is exactly what makes them add to one — and is its mean in the ordinary sense. Every theorem about expectation therefore holds verbatim for conditional expectation, with all probabilities computed in the conditional world.
Example 5.22 (Conditioning on a die). Roll a fair six-sided die to get , then toss fair coins and let be the number of heads. Find for each , and find explicitly.
Solution.
- Given , the variable is binomial with and .
- By the theorem Mean and variance of the binomial, applied inside the conditional distribution, .
- So . The value is a plain number: we were told , and conditional on that information has a definite mean.
- The six numbers are for .
The random variable
Look at step 4 above. We produced not one number but a table: a number for each possible value of . That table is a function of , call it . Now feed the random variable into that function. The result, , is itself a random variable — it takes the value when the die shows , the value when the die shows , and so on, with the probabilities of . This object is what the rest of the chapter is about.
Definition 5.23 (Conditional expectation as a random variable). Let , defined for every in the support of . The conditional expectation of given is the random variable
It is a function of alone; it takes the value on the event .
Pitfall. and are different kinds of object, and confusing them is the single largest source of error in this topic.
- is a number (once is fixed). It is the mean of in the sub-population where . Asking for its variance, or writing , is a type error.
- is a random variable. Its randomness is inherited entirely from : nothing about is left un-averaged. It has a distribution, a mean and a variance of its own, and the next two sections are precisely the statements that its mean is and that its variance is part of .
The relation between them is substitution: is the function evaluated at the random . In the example Conditioning on a die, is a number, while is a random variable taking six values with probability each.
Intuition. Imagine a population split into groups by the value of . For each group, compute the average of within that group; write that group average on a card and give the same card to everyone in the group. Now draw a person at random. The number on their card is — random, because which group you land in is random, but less random than itself, because all the within-group variation has been averaged away. is with its fine detail blurred out and only the part that can see retained.
The properties of are the properties of ordinary expectation plus one new rule that has no unconditional analogue.
Theorem 5.24 (Properties of conditional expectation). Let , , have finite expectations, let be constants and let be a function with . Then, with all equalities holding almost surely:
- Linearity: .
- Taking out what is known: ; in particular .
- Independence: if and are independent, , a constant.
- Monotonicity: if almost surely then .
Proof. Fix with and argue in the conditional distribution; the discrete case is written out and the continuous case replaces sums by integrals throughout.
(1) The conditional pmf is a pmf, so the theorem Linearity of expectation applies to it: . This holds for every , so the corresponding functions of agree, and evaluating both at gives the claim.
(2) On the event the factor equals the constant , so
As functions of the two sides agree, and substituting for gives . Taking gives the special case.
(3) Independence makes the conditional pmf equal to the marginal: . Hence for every , so the function is constant and .
(4) If almost surely then the same holds under each conditional distribution, and expectation is monotone.∎
Property (2) is the one with no unconditional counterpart and the one that does the most work. It says that conditional on , any function of behaves like a constant — because it is one, once you know . Every calculation in the next two sections uses it.
Example 5.25 (Taking out what is known). With and as in the example Conditioning on a die, compute and .
Solution.
- is a function of , so by property (2) of the theorem Properties of conditional expectation, .
- We found , so .
- To get the unconditional we will need the tower property of the next section, which gives .
- For a fair die , so .
5.5The Tower Property
The example above ended with a promise: that an unconditional expectation can be recovered by averaging conditional ones. That is the tower property, and it is the workhorse of the chapter.
Theorem 5.26 (The tower property). Let have finite expectation and let be any random variable. Then
Equivalently, in the discrete case,
and in the jointly continuous case . The identity is also called the law of total expectation.
Proof. Write , so that . By the theorem Law of the unconscious statistician applied to the function of the variable ,
Now substitute the definition of and expand the conditional pmf:
The factor cancels — which is exactly why the conditional expectation must be weighted by and not averaged plainly. Absolute convergence, which holds because , licenses swapping the order of summation:
the inner sum being the marginal pmf of . The continuous case is the same computation with integrals in place of sums.∎
Intuition. The overall average is the average of the group averages — weighted by group size. A university's mean starting salary is not the plain average of the departmental means; a department with four hundred graduates counts a hundred times as much as one with four. The weight is the group size, and forgetting it is the classic error.
Method 5.27 (Computing an expectation by conditioning). To find when is hard to describe directly:
- Choose a variable such that, given , the distribution of is something you recognise. The right choice is usually the quantity whose randomness is causing the trouble — a random sample size, an unknown parameter, the outcome of a first step.
- Write down as a formula in , using known results inside the conditional world.
- Replace by to get the random variable .
- Take its expectation, weighting by the distribution of . The tower property says the answer is .
Example 5.28 (Expected number of heads, revisited). For the die-then-coins experiment of the example Conditioning on a die, find .
Solution.
- Conditioning on is step 1, and we already know .
- By the theorem The tower property, .
- A fair die has , so .
- Direct computation would require the pmf of , a mixture of six binomials — a page of arithmetic for a number that conditioning gives in one line.
A random sum of random variables
The most valuable application of the tower property is to a sum whose number of terms is itself random. Insurance claims in a month, customers served in a day, offspring in a generation: all are sums of a random number of random terms, and none has an obvious distribution.
Theorem 5.29 (Wald's identity). Let be independent and identically distributed with finite mean , and let be a non-negative integer-valued random variable with finite mean, independent of the sequence . Put
Then .
Proof. Condition on . On the event the sum has exactly terms, and since is independent of the , conditioning on does not change the distribution of . Hence, by linearity of expectation inside the conditional world,
As a function of this is , so the random variable is . Applying the theorem The tower property,
Pitfall. Wald's identity is , and it looks so much like linearity of expectation that it is tempting to skip the hypotheses. The independence of from the is doing real work, and it fails in the most natural-looking setting: whenever is chosen by looking at the .
For a concrete failure, let the be with probability each, so , and let if and otherwise. Then , but
The rule peeked at a term it had not yet taken. The hypothesis that covers the cases independence does not is that be a stopping time: the decision to stop after terms may depend on but not on anything later. Wald's identity holds under that hypothesis too, provided — and the rule above is not a stopping time, because stopping after one term required knowing .
Example 5.30 (Insurance claims). The number of claims filed against a policy in a year is Poisson with mean . Claim sizes are independent of and of each other, each with mean and standard deviation (in dollars). Find the expected total claim amount .
Solution.
- The hypotheses of the theorem Wald's identity hold: the are i.i.d. with finite mean and is independent of them.
- Therefore dollars.
- Notice how little was needed: no distributional assumption about the claim sizes beyond their mean, and only the mean of . The variance of needs more, and the next section supplies it.
Remark. The tower property generalises: for any two variables one has , sometimes stated as "the coarser conditioning wins". The version proved above is the case where carries no information at all. The general form is the defining property of a martingale and is the reason this chapter is a prerequisite for that theory.
5.6The Law of Total Variance
The tower property splits an expectation. Variance splits too, but into two pieces rather than being simply averaged — and the reason is the whole point of the result.
Why can we not just average the conditional variances? Because two sources of uncertainty are at work. Even if every group had zero internal variation, would still be uncertain, since which group you land in is uncertain. Total uncertainty is the within-group variation plus the between-group variation, and that sentence is the theorem.
Theorem 5.31 (Law of total variance). Let have finite variance and let be any random variable. Then
where is the random variable taking the value on . The two terms are called the within (or unexplained) and between (or explained) components. The result is also known as Eve's law.
Proof. Write . By the conditional form of the proposition Computational formula for the variance, applied inside each conditional distribution,
Take expectations of both sides and use the theorem The tower property on the first term:
Separately, is an ordinary random variable, so by the computational formula for its own variance,
the last step again by the tower property, which says .
Add (i) and (ii). The term cancels, leaving
Intuition. Split a population into groups by . The first term, , is the average spread inside a group — the variation that knowing does not help you with. The second, , is the spread of the group means themselves — the variation that knowing does explain. Every bit of the total is in one bucket or the other, and nothing is double-counted.
Two extreme cases pin the idea down. If is a function of , then knowing removes all uncertainty: the within term is and the between term is everything. If is independent of , then is constant, the between term is , and knowing has explained nothing.
Example 5.32 (Within and between, exactly). Let be uniform on and, given , let be uniform on the three integers — so gives , gives , and gives . Verify Eve's law.
Solution.
- Conditional means. Each group is symmetric about its midpoint, so ; that is, , taking the values .
- Conditional variances. Three consecutive integers with equal probability have variance , whatever the group. So identically, and the within term is .
- Between term. takes with probability each. Its mean is and its variance is .
- Eve's law predicts .
- Direct check. Unconditionally is uniform on , whose variance is ✓.
- The between term dominates by a factor of nine: the groups are far apart relative to their internal spread, so explains most of what does.
Corollary 5.34 (Variance of a random sum). Under the hypotheses of the theorem Wald's identity, with finite and finite,
Proof. Condition on . Given the sum is of i.i.d. terms independent of the conditioning, so by the corollary Variance adds under independence, , and from the proof of Wald's identity . As random variables, and . Now apply the theorem Law of total variance:
the second term by the proposition Variance under a linear change of scale.∎
Example 5.35 (Insurance claims, variance). Continue the example Insurance claims: , claim sizes with and . Find the standard deviation of the total claim amount.
Solution.
- A Poisson has , by the theorem Mean and variance of the Poisson.
- By the corollary Variance of a random sum, .
- So dollars against a mean of .
- Read the two terms: of the variance comes from not knowing how big the claims are, and from not knowing how many there will be. For this portfolio, the count is the bigger risk — which is the kind of conclusion the decomposition exists to deliver.
Pitfall. Variances do not average the way means do. Writing and stopping there throws away the between-group term and always understates the total. The error is easy to spot once named: if the groups have wildly different means but each is internally tight, the formula would report almost no variation in a population that is obviously spread out. Compare the means before you trust a pooled variance.
5.7Conditional Expectation as the Best Predictor
We have treated as a computational device. It is also the answer to a genuine optimisation problem, and that is what elevates it from a trick to the central object of prediction theory.
Fix the situation: you will observe and must then produce a guess at . A prediction rule is any function , and your guess is . Score the rule by its mean squared error . Which is best?
Theorem 5.36 (Conditional expectation minimises mean squared error). Let have finite variance. Among all functions with ,
with equality if and only if almost surely. That is, is the best mean-square predictor of from , and its mean squared error is .
Proof. Write and split the error by adding and subtracting it:
Note that is a function of . Squaring and taking expectations,
The cross term vanishes. To see it, condition on and use the tower property:
where came out of the inner expectation by property (2) of the theorem Properties of conditional expectation, since is a function of . But
by linearity and by the same take-out rule applied to . Hence and
since the discarded term is the expectation of a square. Equality forces , and a non-negative variable with zero mean is zero almost surely, so almost surely.
For the value of the minimum, by the tower property, and the inner quantity is by definition .∎
Intuition. The proof is an orthogonality argument wearing probabilistic clothes. The error is uncorrelated with every function of — that is what says — so is the orthogonal projection of onto the space of functions of . Prediction is projection, and the Pythagorean identity in the display above is the theorem. Read that way, the law of total variance is just Pythagoras: is the hypotenuse squared, the within term the error leg, the between term the projection leg.
Corollary 5.37 (The best constant predictor). Among constants , the minimiser of is , and the minimum value is .
Proof. Take to be a constant random variable, so that the only functions of are constants, and by property (3) of the theorem Properties of conditional expectation. The theorem Conditional expectation minimises mean squared error then gives the claim, the minimum value being . Alternatively, expand directly: , which is minimised by matching to .∎
This is the reason the mean, rather than any other centre, is the default summary of a distribution: it is the number that is closest to the whole distribution in the squared-error sense. (Under absolute error the answer would be the median instead — the loss function chooses the summary.)
The best linear predictor, and what measures
In practice one often restricts to predictors of the form , either because the conditional mean is unknown or because a straight line is all the data supports. That problem has a closed-form answer in terms of exactly the quantities of this chapter.
Proposition 5.38 (Best linear predictor). Let have finite positive variances. The function minimising has
and the resulting minimum mean squared error is
Proof. Fix and optimise over first. By the corollary The best constant predictor applied to the variable , the best is , and with that choice
using the theorem Variance of a sum. This is a quadratic in with positive leading coefficient ; differentiating and setting to zero gives , so , which equals by the definition of .
Substituting back,
Corollary 5.39 (Interpretation of ). The best linear predictor of from removes a fraction of the variance of :
Proof. Immediate from the proposition Best linear predictor: the minimum error is , so the reduction is , a fraction of . Since the error is non-negative, this also re-proves .∎
Two things follow. First, this is the population version of the least-squares regression line: the slope and the "variance explained" are exactly the regression coefficient and that a statistics course computes from data. Regression is conditional expectation, estimated. Second, the restriction to linear rules costs something in general, and nothing in one important case.
Example 5.40 (When the best predictor is not linear). For uniform on and as in the theorem Zero covariance does not imply independence, compare the best predictor of from with the best linear one.
Solution.
- The best predictor is . Since is a function of , property (2) of the theorem Properties of conditional expectation gives , with mean squared error : perfect prediction.
- The best linear predictor has slope , so it is the constant .
- Its mean squared error is .
- The gap between and is the entire cost of insisting on a straight line. Linearity, not conditioning, is what failed here.
Remark. When is bivariate normal the two coincide: is exactly the linear function , and is the same for every . That is why linear regression and normal-theory inference fit together so neatly, and why neither is safe when the joint distribution is far from normal.
5.8Jensen's Inequality
One inequality has been used repeatedly without being named. The corollary Variance is non-negative, and already told us , which says that squaring and averaging do not commute, and that the error goes in a definite direction. That is a special case of a statement about every convex function.
Definition 5.41 (Convex function). A function on an interval is convex if for all and all ,
It is strictly convex if the inequality is strict whenever and . A function is concave when is convex. If is twice differentiable, is convex exactly when on .
Geometrically, convexity says the chord between any two points of the graph lies on or above the graph. The dual statement, and the one we need, is that the graph lies on or above each of its tangents.
Lemma 5.42 (Supporting line). Let be convex on an open interval and let . Then there is a constant with
and if is strictly convex the inequality is strict for every .
Proof. Convexity is equivalent to the statement that the difference quotient
is non-decreasing in each argument. Consequently, for in we have , so the set of left slopes is bounded above by the set of right slopes. Let
both finite, and choose any . For , gives ; for , gives , which rearranges to the same inequality. At both sides agree. Strict convexity makes the difference quotients strictly increasing, so each inequality above is strict for . (When is differentiable, and the supporting line is simply the tangent.)∎
Theorem 5.43 (Jensen's inequality). Let be convex on an interval , and let be a random variable with and finite mean . If exists, then
If is strictly convex, equality holds if and only if almost surely. For concave the inequality reverses.
Proof. By the lemma Supporting line there is a with for every . Since takes values in with probability one, the inequality holds between random variables:
Expectation is monotone, so taking expectations of both sides and applying the theorem Linearity of expectation to the right-hand side gives
because . That is the inequality.
For the equality case with strictly convex, let , a non-negative random variable which is strictly positive wherever . Equality in Jensen says , so almost surely, so . The concave case follows by applying the convex case to .∎
Intuition. Averaging then bending is not the same as bending then averaging, and for a convex bend the second is always larger. Picture the graph as a valley: take two points on its walls and join them by a chord. The midpoint of the chord — the average of the two heights — sits above the valley floor at the average position. Jensen is that picture with any number of points and any weights.
Corollary 5.44 (Standard consequences of Jensen). Let be a random variable with the relevant moments finite.
- , with equality if and only if is constant almost surely.
- If , then .
- If , then .
- .
Proof. (1) Apply the theorem Jensen's inequality to , which has and so is strictly convex on . Equality iff is almost surely constant, by the equality clause. Rearranged, this says with equality only for a degenerate variable, which is the corollary Variance is non-negative, and proved a second way.
(2) On , has , so it is strictly convex; Jensen gives .
(3) On , has , so it is strictly concave and the inequality reverses.
(4) is convex, so . (It is not strictly convex, which is why equality can occur for non-constant — any of one sign achieves it.)∎
Example 5.45 (The average speed trap). A cyclist rides a fixed course at a speed which is or km/h with probability each. Compare the expected time per kilometre with the reciprocal of the expected speed.
Solution.
- , so hours per kilometre.
- The time per kilometre is , with hours.
- Indeed , as part (2) of the corollary Standard consequences of Jensen requires, and the gap is not small: .
- The reason is concrete. The slow leg takes three times as long as the fast one, so the ride spends most of its time going slowly, and the time-average speed is the harmonic mean , not the arithmetic mean .
Pitfall. for any that is not affine, and Jensen says which way the error runs. Plugging an average into a nonlinear formula and reporting the result is a mistake with a name — the flaw of averages — and it is systematically biased, not merely noisy. Average sales into a profit formula with a nonlinear cost, average a rate into a doubling time, average a portfolio return into a growth factor: each one is wrong in a predictable direction. The only functions for which substituting the mean is exact are , precisely because those are the ones that are both convex and concave.
Remark. Jensen's inequality has a conditional form, proved by running the same supporting-line argument inside each conditional distribution: for convex ,
Taking and then expectations recovers — conditioning never increases variance — which is the law of total variance read as an inequality.
Summary. Covariance. . It is symmetric, bilinear, blind to additive shifts, and satisfies . Its magnitude carries units and means nothing alone.
Variance of a sum. , with no hypotheses; more generally .
Correlation. is unit-free and, by Cauchy–Schwarz, lies in ; exactly when almost surely.
The asymmetry. Independent uncorrelated, always. Uncorrelated independent, never in general: uniform on with has and determined by . The converse does hold for a jointly normal pair.
Conditional expectation. is a number; is a random variable, a function of . It is linear, monotone, satisfies , and equals when and are independent.
Tower property. — average the group means weighted by group size. With it, for a random sum independent of its length (Wald).
Law of total variance. : within plus between. For a random sum, .
Best prediction. minimises over all , with minimum ; the best constant is ; the best linear rule has slope and leaves , so is the fraction of variance explained linearly.
Jensen. convex , strictly unless is constant. Hence , and for positive .
- Reading a covariance's size as a strength of association. Covariance carries the product of the two units, so its magnitude changes with the scale. Normalise to before comparing two pairs of variables, and quote only the sign of a raw covariance.
- Treating "uncorrelated" as "independent". Independence implies zero covariance; the reverse fails, as uniform on with shows. Zero correlation rules out a linear trend and nothing else.
- Assuming independence to add variances when uncorrelatedness would do. The corollary *Variance of a linear combination* needs only the covariances to vanish. Claiming more than you need is not an error of arithmetic, but it is an error of proof — and it invites the reverse error of assuming full independence elsewhere.
- **Dropping the cross term in . ** For dependent variables ; the minus sign attaches to the covariance, not to the variances, which still add.
- **Confusing with . ** The first is a number attached to one value of ; the second is a random variable. Only the second can be put inside another expectation or have a variance taken — expressions like are meaningless.
- Averaging conditional expectations without weights. The tower property weights by . A plain average of group means is the right answer only when the groups are equally likely.
- Forgetting the between-group term in the law of total variance. is *plus* . Omitting the second term understates the spread whenever the group means differ.
- Using Wald's identity when the number of terms is chosen by looking at the terms. needs independent of the sequence (or, more generally, a stopping time). "Keep buying until I have lost enough" is neither.
- Believing that zero correlation makes the best predictor a constant. The best *linear* predictor is constant when ; the best predictor may still be an exact formula, as shows.
- **Reporting as a percentage of a perfect relationship.** The quantity with a proportional reading is , the fraction of variance removed by linear prediction. A correlation of explains a quarter of the variance, not half of it.
- Substituting a mean into a nonlinear function. By Jensen's inequality the result is biased in a known direction: too low for a convex function, too high for a concave one. Average the outputs, not the inputs.
- Assuming normal marginals make a pair jointly normal. The proposition *The jointly normal exception* needs joint normality; two normal marginals can be uncorrelated and still deterministic in one another.