A parcel service sends half of its parcels by standard routing and half by express, and a parcel is inspected with probability overall. Once the route of a parcel is known, is no longer the right average to use, because express parcels are inspected more often than standard ones. Conditional expectation is the average recomputed with the probabilities that apply after the information is known. This lesson computes it from a joint table, treats it as a random variable before the information arrives, shows that averaging it with the right weights recovers the overall mean, and explains why it is the best prediction under squared error.
Key terms
Conditional expectation
Definition Let and be discrete random variables on the same probability model, and let be a value with . The conditional expectation of given is the mean of the conditional PMF ,
provided the sum converges absolutely, which is the case when , in particular when has finitely many values. It is defined only for values with , because the conditional PMF divides by . In the same way, for an event with , the conditional expectation is the mean of computed with the conditional probabilities .
In plain words First update the probabilities with the information , by keeping one row of the joint table and rescaling it so that it adds to . Then take an ordinary weighted average of the values of with the updated weights. The result is a mean, so it need not be a value that can take.
Example In a constructed parcel model, for standard routing and for express, and when the parcel is inspected and otherwise.
Given standard routing, dividing the first row by gives the conditional probabilities and , so . Given express routing, the second row becomes and , and . Neither nor is a value that the indicator can take.
Conditional mean function
Definition The conditional mean function of given is
defined for every with at which this conditional expectation exists, which is every such when , in particular when has finitely many values. Each is a fixed number. When is the indicator of an event, is the conditional probability of that event. When is measured in a unit, such as minutes, is measured in the same unit. A value with gets no conditional mean from the table, since its row and its row total are both .
In plain words The conditional mean function is a lookup table with one average for each value of that can actually occur. It answers the question of what is on average among the outcomes with that value of .
Example In the parcel model, and , the inspection probabilities of standard and express parcels. In a second constructed model, a job belongs to group A or group B and its duration is measured in minutes. If its conditional mean duration is minutes in group A and minutes in group B, the conditional mean function of given the group takes the values and minutes.
Random conditional mean
Definition Putting the random variable into the conditional mean function gives the random variable
On an outcome where takes the value , it takes the value . When exists at every with , for example when , it is defined with probability , because a discrete takes such a value with probability . It is a function of , so its value is known as soon as is observed, and its distribution comes from that of . For each number , the probability is the sum of over the values with .
In plain words Before the route of a parcel is known, the inspection probability that will apply to it is itself uncertain. The expression is a number, while is a random quantity whose value is revealed together with .
Example In the parcel model, equals when the parcel is standard and when it is express, so it takes each of these values with probability . Its mean is , which is exactly , the inspection probability of a parcel whose route is unknown. The next card shows that this is no coincidence. The random variable is not itself, since is always or .
Law of total expectation
Definition Let and be discrete random variables on the same probability model with . Then
or, written out,
where and the sum runs over the values with . This is also called the tower rule. For a finite table the proof is a regrouping of one double sum. Each conditional probability is a cell divided by its row total, so the row total cancels,
Every cell contributes its value of times its probability exactly once, whether the sum is taken row by row or column by column. The same rule holds for groups that partition the sample space and have positive probabilities, as .
In plain words The overall mean is the average of the group means, weighted by how likely each group is. Equal weights give the overall mean when the groups are equally likely, and in general they do not.
Example In the parcel model, . For the jobs, let group A have probability and group B probability , with conditional mean durations of and minutes. Then
minutes, not the midpoint of the two group means. If the two groups were equally likely, the same group means would give minutes.
Integrability
Definition A random variable is integrable if . For a discrete this means , and every variable with finitely many values is integrable. If is integrable, then every conditional expectation with is finite, because , and the double sum in the tower rule converges absolutely, so it may be regrouped by rows or by columns. Integrability is a sufficient condition for the law of total expectation. Without it, the conditional means can all exist while does not.
In plain words Before regrouping an infinite sum of positive and negative terms, check that the sizes of the terms add to a finite total. Then summing by rows first or by columns first gives the same answer.
Example Let take the values and , each with probability , for , a distribution also studied in Expected Value, and let . Given , the variable equals or with probability each, so every conditional mean is and their weighted average is . Yet
and is undefined, because its positive part and its negative part both add to infinity. The tower rule does not apply, and the it would suggest is not a mean of .
Squared-error prediction
Definition Suppose , and let be a value with . For every real number ,
where is the variance of the conditional distribution. The identity follows by writing as and expanding, and the cross term vanishes because . So is the unique number that minimizes the conditional expected squared error. Averaging over shows that for every function defined at the values with ,
with equality exactly when for every such . The finite second moment makes the conditional variances and the expected squared error of finite. The result is about squared error only. The conditional mean need not be the most likely value, and other losses have other best predictions, for example a median for absolute error.
In plain words If you must announce one number for after seeing and the penalty is the square of your miss, announce the conditional mean for that value of to make the average penalty as small as possible. Any other number adds the squared distance from the conditional mean to the spread that no prediction can remove.
Example For a standard parcel, predicting the number for the inspection indicator gives the expected squared error
The best prediction is , with error , while predicting , the more likely value, gives . For an express parcel the conditional variance is . Using for every parcel gives the mean squared error , below the error of the best single number chosen without seeing the route.
Check yourself
- A school has two sections. Section 1 has students with mean test score , and section 2 has students with mean test score . A student is chosen uniformly at random from all . What is the expected score of the chosen student, and why is wrong?
Show the answer
The chosen student is in section 1 with probability and in section 2 with probability . The law of total expectation gives
The value averages the two section means with equal weights, which would be right only if the sections were equally likely to be chosen. Here section 2 is three times as likely.
- A device runs in mode A with probability and in mode B with probability . In mode A a task takes minutes with probability and minutes with probability . In mode B these two probabilities are reversed. Find the conditional mean duration in each mode and the overall mean duration.
Show the answer
In mode A the conditional mean is minutes, and in mode B it is minutes. The tower rule weights them by the mode probabilities,
so the overall mean is minutes. As a check, and , so . Equal weights would give minutes, but mode A occurs three times as often as mode B.
- The joint table of and has the row , , for and the row , , for , in the columns , and . Find , and the distribution of , and check the tower rule. Which prediction of minimizes the expected squared error when , and what is that error?
Show the answer
The row totals are and . Then and , so equals with probability and with probability . Its mean is , and directly , as the tower rule requires. The equal-weight average is wrong because the rows have different probabilities. When , the value is or with probability each, so the best prediction is , even though never equals . Its expected squared error is the conditional variance , while predicting or gives .