Parcels go out by standard or express routing, and some of them are pulled aside for an extra inspection. Whether a parcel is inspected varies for two separate reasons. Inspections are random inside each route, and the two routes inspect at different rates. This lesson defines the conditional variance and proves the law of total variance, which splits the variance of a quantity exactly into a part from the spread inside the groups and a part from the differences between the group means.
Key terms
Conditional variance
Definition Let be a discrete random variable and let be a random variable on the same sample space with a finite second moment, . For each value with , write for the conditional mean. The conditional variance of given is the variance of under its conditional distribution given ,
For a discrete this is . It is finite, because . Writing , the random conditional variance is the random variable , in the same way that . No conditional distribution is defined at a value with , but takes such values with probability , so they never affect an expectation.
In plain words A conditional variance measures the spread of inside one group, around that group’s own mean rather than the overall mean. It carries the squared units of . A group with a larger conditional mean need not have a larger conditional variance.
Example In a constructed parcel model, for standard routing and for express routing, and is the indicator of an extra inspection. The joint PMF is in the table.
Each row adds to . Dividing the first row by gives the conditional probabilities and for and , so . An indicator with success probability has variance , so . The second row gives and , so and . Express parcels are inspected more often, yet their indicator is closer to the constant and therefore less spread out.
Within-group variation
Definition Under the same assumptions, the within-group variation is the expected conditional variance
where the sum runs over the values with . It is the weighted average of the conditional variances, with the group probabilities as weights, and it equals , the mean squared distance of from its own group mean. It is nonnegative, it carries the squared units of , and it equals exactly when is constant within every group of positive probability, in other words when .
In plain words Average the spread inside the groups, counting each group as often as it occurs. Each conditional variance already averages squared deviations, so the average is not squared again. Since every function satisfies , as shown in Conditional Expectation and the Tower Rule, the within-group variation is the mean squared error that remains when is predicted from in the best possible way.
Example In the parcel model both routes have probability , so
Here the plain average of and gives the same number, because the two routes are equally likely. With unequal group probabilities the weights must be those probabilities.
Between-group variation
Definition Under the same assumptions, let . The between-group variation is the variance of the conditional mean ,
summed over the values with . The sum is centered at because the tower rule gives . The between-group variation carries the squared units of , and it equals exactly when every group of positive probability has the same conditional mean.
In plain words Replace every outcome by the mean of its group, and measure how much these group means vary around the overall mean. Even if were constant inside each group, different constants in different groups would still make vary. If and are independent, every conditional mean equals and the between-group variation is . The converse is false, since groups with equal means can still have different distributions.
Example In the parcel model the conditional mean equals or with probability each. Its mean is , which agrees with . Both group means lie away from , so
Law of total variance
Definition Let be a discrete random variable and let be a random variable on the same sample space with . Then
In words, the total variance is the within-group variation plus the between-group variation, and all three are in the squared units of . Both terms on the right are finite and nonnegative, so each of them is at most . The examples on this page use finite tables, and the proof in the next card works for any discrete .
In plain words The overall spread of has two sources, the spread of outcomes around their own group mean and the spread of the group means around the overall mean. The law says that these two parts add up to the total exactly. The two terms are easy to confuse. The first is an average of variances, and the second is a variance of averages. The lesson Random Sums with Independent Counts uses this law with the number of terms as the group label, to find the variance of a total with a random number of terms.
Example In the parcel model the two parts give . Directly, is an indicator with , so as well.
For unequal groups, take a constructed device model in which the mode is A with probability and B with probability , and the duration is or minutes. In mode A these durations have probabilities and , and in mode B the probabilities are reversed.
| Mode | Probability | ||
|---|---|---|---|
| A | |||
| B |
In mode A the mean is minutes, and the squared deviations and average to square minutes. In mode B the mean is minutes, and the squared deviations and average to square minutes. The within-group variation is square minutes. The overall mean is minutes, so
square minutes, and square minutes. As an independent check, and . Then and , so .
Vanishing cross term
Definition Under the assumptions of the law, write , let be the deviation of from its group mean, and let be the deviation of the group mean from the overall mean. Then exactly, and
The first term is , and the second is because . For the cross term, fix a value with . Given , the factor is a constant and has conditional mean , so . Averaging over the groups gives . Every expectation here is finite, because gives , so the expectation of the sum may be split term by term.
In plain words Inside a fixed group, the deviations from the group mean average to zero, while the group’s offset from the overall mean is a fixed number, so their product also averages to zero. That is why the two parts add with no correction term. The split has to use the group mean. Spread inside a group measured around the overall mean already contains that group’s offset.
Example In the device model, mode A has group mean and the overall mean is . Measured around , the durations and in mode A give
which is . In mode A the deviation is or with probabilities and , so its conditional mean is , and the cross term of this group is . Mode B gives in the same way, and is already the whole variance. Adding the between-group variation on top of these spreads would count it twice.
Check yourself
- A group label is A or B with probability each. In group A the value is always , and in group B it is always . Find the within-group variation, the between-group variation and .
Show the answer
Each group contains a single value, so both conditional variances are and the within-group variation is . The conditional means and have overall mean , and both lie away from it, so the between-group variation is . The law gives . Directly, is or with probability each, so and .
- Change the model so that groups A and B, still with probability each, both have conditional mean and conditional variance . Find . Does a between-group variation of mean that the group label and are independent?
Show the answer
The conditional mean equals in both groups, so is the constant and the between-group variation is . The within-group variation is , so . No further details of the two distributions are needed.
It does not. For example, let be , or with probabilities , and in group A, and , or with probabilities , and in group B. Both groups have mean and variance , since and . Yet while , so the conditional distribution of depends on the group and the variables are dependent. A between-group variation of says only that the group means agree.
- Group A has probability , conditional mean and conditional variance . Group B has probability , conditional mean and conditional variance . Someone reports . Find the correct variance and name the two mistakes.
Show the answer
The within-group variation is . The overall mean is , so the between-group variation is
The law gives . The report weights the two groups equally although B is four times as likely as A, and it leaves out the between-group variation entirely. Even with the correct weights, the average of the conditional variances is only the within-group part.