Why Multi-Stage Conditioning Helps
Some random quantities are generated in stages. A latent category, such as a risk class, influences how many opportunities occur; the count then determines how many individual outcomes contribute to a total. Examples include total payments from a random number of events or a score accumulated over a random number of trials. Calculating directly from every possible combination can be cumbersome. Conditioning in stages makes the structure visible and helps keep conditional quantities separate from overall ones.
Let \(C\) denote a latent category, \(N\) a count whose distribution may depend on \(C\), and \(X\) the final quantity. The useful order is often to find moments conditional on both \(C\) and \(N\), average over \(N\) within each category, and then average over categories. For variance, each of those steps has a corresponding source of variation.
The Nested Expectation and Variance Formulas
The law of total expectation can be applied repeatedly. First average \(X\) over its possible outcomes given the category and count. Then average those conditional expectations over the count, given the category. Finally average over the categories.
The last expression means that the conditional expectation \(E[X\mid C,N]\) is itself averaged over the joint distribution of \(C\) and \(N\). When the categories are discrete, this can be written explicitly as
For variance, apply the law of total variance twice. Within a category, variation in \(X\) comes both from variation in \(X\) at a fixed count and from variation in the conditional mean as the count changes. Across categories, the category-specific means can differ as well.
The two versions organize the same calculation differently. The first displays the outcome-level and count-level contributions separately. The second first combines those contributions within each category, then adds between-category variation. Either is valid, provided every expectation is taken over the appropriate distribution.
Justification: Why the Variance Stages Add
For any conditioning variable \(W\), write \(X-E[X]\) as \((X-E[X\mid W])+(E[X\mid W]-E[X])\). Squaring and taking expectations gives
The cross term is zero. Conditional on \(W\), the factor \(E[X\mid W]-E[X]\) is fixed, while \(E[X-E[X\mid W]\mid W]=0\). Thus the conditional expectation of the product is zero. The first squared term averages to \(E[\operatorname{Var}(X\mid W)]\), and the second is \(\operatorname{Var}(E[X\mid W])\). Therefore,
Taking \(W=(C,N)\) gives the outcome and count stages. Applying the same identity again within each category, with \(W=N\) conditional on \(C\), separates the count-level variation from the variation among category means. This is why the stages add rather than requiring an independence assumption between the category and count.
Worked Examples
Worked Example: A Category-Dependent Count of Payments
A hypothetical monitoring plan is in category A with probability \(0.4\) and category B with probability \(0.6\). Given A, the number \(N\) of monitored events is 0 or 2, each with probability \(0.5\). Given B, \(N\) is 1 or 3, each with probability \(0.5\). In category A, each event independently pays $5 with probability \(0.2\); in B, each event independently pays $5 with probability \(0.4\). Given the category and count, the event payments are independent. Find the expected total payment \(X\) and its variance.
Method. Find the mean and variance of one event payment in each category. Then use the random-sum moments within each category, followed by the category-level decomposition.
In A, one event payment \(Y\) is $5 with probability \(0.2\) and $0 otherwise. Therefore, \(E[Y\mid A]=5(0.2)=1\), and \(\operatorname{Var}(Y\mid A)=25(0.2)(0.8)=4\). The count has \(E[N\mid A]=(0+2)/2=1\) and \(\operatorname{Var}(N\mid A)=((0-1)^2+(2-1)^2)/2=1\). For a sum of \(N\) conditionally independent, identically distributed event payments, \(E[X\mid A]=E[N\mid A]E[Y\mid A]=1\), and \(\operatorname{Var}(X\mid A)=E[N\mid A]\operatorname{Var}(Y\mid A)+\operatorname{Var}(N\mid A)(E[Y\mid A])^2=1(4)+1(1)^2=5\).
In B, \(E[Y\mid B]=5(0.4)=2\), and \(\operatorname{Var}(Y\mid B)=25(0.4)(0.6)=6\). The count has \(E[N\mid B]=(1+3)/2=2\) and \(\operatorname{Var}(N\mid B)=((1-2)^2+(3-2)^2)/2=1\). Thus \(E[X\mid B]=2(2)=4\), and \(\operatorname{Var}(X\mid B)=2(6)+1(2)^2=16\).
The overall mean is \(E[X]=0.4(1)+0.6(4)=2.8\) dollars. The average within-category variance is \(0.4(5)+0.6(16)=11.6\) dollars squared. The variance of the category means is \(0.4(1-2.8)^2+0.6(4-2.8)^2=0.4(3.24)+0.6(1.44)=2.16\). Therefore, \(\operatorname{Var}(X)=11.6+2.16=13.76\) dollars squared.
Check. The category weights \(0.4\) and \(0.6\) sum to 1, and the between-category contribution is nonnegative. The result is \(E[X]=\$2.80\) and \(\operatorname{Var}(X)=13.76\) dollars squared. The common mistake avoided is averaging the category results equally even though the category probabilities are unequal.
Worked Example: Random Counts With Different Payment Distributions
A hypothetical service contract has class A or B, each with probability \(0.5\). Given A, the number \(N\) of service events is 0 or 2 with equal probability; given B, it is 1 or 3 with equal probability. Conditional on A, each event independently pays $2 or $6, each with probability \(0.5\). Conditional on B, each event independently pays $1 or $5, each with probability \(0.5\). Find the mean and variance of total payment \(X\).
Method. Use the random-sum formulas within each class, allowing the per-event distribution to depend on class, and then apply the total variance formula across classes.
In A, one event has mean \((2+6)/2=4\) dollars and variance \(((2-4)^2+(6-4)^2)/2=4\) dollars squared. The count has mean 1 and variance 1. Hence \(E[X\mid A]=1(4)=4\), and \(\operatorname{Var}(X\mid A)=1(4)+1(4^2)=20\). The two count outcomes also show the stages directly: for \(N=0\), the conditional mean and variance are 0 and 0; for \(N=2\), they are 8 and 8. Averaging the conditional variances gives 4, and the variance of the conditional means 0 and 8 is 16, totaling 20.
In B, one event has mean \((1+5)/2=3\) dollars and variance \(((1-3)^2+(5-3)^2)/2=4\) dollars squared. The count has mean 2 and variance 1. Thus \(E[X\mid B]=2(3)=6\), and \(\operatorname{Var}(X\mid B)=2(4)+1(3^2)=17\). At counts 1 and 3, the conditional means are 3 and 9 and the conditional variances are 4 and 12. Their average variance is 8, and the variance of means 3 and 9 is 9, again totaling 17.
Therefore, \(E[X]=0.5(4)+0.5(6)=5\) dollars. The average within-class variance is \(0.5(20)+0.5(17)=18.5\). The between-class variance is \(0.5(4-5)^2+0.5(6-5)^2=1\). Thus \(\operatorname{Var}(X)=18.5+1=19.5\) dollars squared.
Check. The direct count-level calculations agree with the random-sum calculations in both classes. The final results are \(E[X]=\$5.00\) and \(\operatorname{Var}(X)=19.5\) dollars squared. The common mistake avoided is treating the event payment distribution as identical across classes.
Worked Example: Keeping Count Variation in a Three-Stage Model
A hypothetical sensor system is in state A with probability \(0.4\) and state B with probability \(0.6\). Given A, the number \(N\) of alerts is 1 or 3, each with probability \(0.5\); given B, it is 2 or 4, each with probability \(0.5\). In A, each alert independently results in a $4 payment with probability \(0.5\); in B, each alert independently results in a $4 payment with probability \(0.25\). Find the mean and variance of total payments \(X\).
Method. Condition first on state, then on alert count. Within a state, use the mean and variance of one alert outcome and account for the random count.
In A, the count has mean \((1+3)/2=2\) and variance 1. One alert payment has mean \(4(0.5)=2\) and variance \(16(0.5)(0.5)=4\). It follows that \(E[X\mid A]=2(2)=4\), and \(\operatorname{Var}(X\mid A)=2(4)+1(2^2)=12\).
In B, the count has mean \((2+4)/2=3\) and variance 1. One alert payment has mean \(4(0.25)=1\) and variance \(16(0.25)(0.75)=3\). Therefore, \(E[X\mid B]=3(1)=3\), and \(\operatorname{Var}(X\mid B)=3(3)+1(1^2)=10\).
The overall mean is \(E[X]=0.4(4)+0.6(3)=3.4\) dollars. The average within-state variance is \(0.4(12)+0.6(10)=10.8\). The between-state variance is \(0.4(4-3.4)^2+0.6(3-3.4)^2=0.4(0.36)+0.6(0.16)=0.24\). Consequently, \(\operatorname{Var}(X)=10.8+0.24=11.04\) dollars squared.
Check. The weighted conditional means give \(3.4\), and the final variance is \(11.04\) dollars squared. A common wrong calculation keeps only the average of \(\operatorname{Var}(X\mid A,N)\) and \(\operatorname{Var}(X\mid B,N)\), then adds between-state variation. That gives \(8.6+0.24=8.84\), omitting count variation. The missing amount is \(0.4(1)(2^2)+0.6(1)(1^2)=2.2\), so the corrected variance is \(8.84+2.2=11.04\).
A Reliable Calculation Process
For a new problem, write down the conditioning stages before substituting values. A compact table of conditional means and variances can prevent category probabilities, count probabilities, and outcome probabilities from being confused.
Identify the latent category \(C\), the count \(N\), and the final quantity \(X\). Record which distributions are conditional on which variables.
Find \(E[X\mid C,N]\) and \(\operatorname{Var}(X\mid C,N)\) from the stated outcome model. Use independence only when the model states or implies conditional independence.
Use \(P(N=n\mid C=c)\), not the marginal count probabilities, to obtain \(E[X\mid C=c]\) and \(\operatorname{Var}(X\mid C=c)\).
Weight category-specific means and variances using \(P(C=c)\). Add the variance of the category-specific means to the average conditional variance.
Confirm that the category probabilities and each conditional count distribution sum to 1. Variance contributions cannot be negative, and the overall mean must be a probability-weighted average of the conditional means.
Common Traps
- Using equal weights for unequal category probabilities. Averages over categories must use \(P(C=c)\), not the number of categories or an assumed equal weighting.
- Replacing a conditional count distribution with its marginal distribution. If the count model depends on category, use \(P(N=n\mid C=c)\) within that category.
- Leaving out count variation. Averaging \(\operatorname{Var}(X\mid C,N)\) alone does not give the within-category variance. Also include the variation of \(E[X\mid C,N]\) as \(N\) changes.
- Adding conditional means instead of averaging them. The overall mean is a weighted average across all stages, not the sum of stage-specific means unless the model defines \(X\) as such a sum.
- Assuming independence after mixing categories. Outcomes can be independent conditional on category and still be dependent marginally because they share the same latent category. Use the independence assumptions at the stage where they are given.
Check Your Understanding
For each problem, keep the conditional count probabilities and category probabilities distinct. Monetary variances are in dollars squared.
- A hypothetical device is type G with probability \(0.3\) and type H with probability \(0.7\). Given G, its number of tests is 0 or 2 with equal probability; given H, it is 1 or 3 with equal probability. Each test independently pays $10 with probability \(0.2\) in G or \(0.4\) in H. Find expected total payment. (Answer: $6.20)
- A hypothetical contract is class A with probability \(0.4\) and class B with probability \(0.6\). Given A, the event count is 1 or 3 equally likely; given B, it is 0 or 2 equally likely. Each A event independently pays $2 with probability \(0.5\), and each B event independently pays $4 with probability \(0.25\). Find expected total payment. (Answer: $1.40)
- A hypothetical program is in state A or B with equal probability. Given A, \(N\) is 0 or 2 equally likely, and each event independently pays $0 or $4 equally likely. Given B, \(N\) is 1 or 3 equally likely, and each event independently pays $2 or $6 equally likely. Find the variance of total payment. (Answer: $25.00 squared)
- A hypothetical alert system is type A with probability \(0.25\) and type B with probability \(0.75\). Given A, the count is 1 or 3 equally likely; given B, it is 0 or 2 equally likely. Each event independently pays $8 with probability \(0.5\) in A or \(0.25\) in B. Find expected total payment. (Answer: $3.50)
- A hypothetical score \(X\) has category A with probability \(0.4\) and B with probability \(0.6\). Given A, \(N\) is 0 or 2 equally likely; given B, \(N\) is 1 or 3 equally likely. Given category and count, the conditional mean and variance of \(X\) are \(3N\) and \(2N\) in A, and \(2N\) and \(5N\) in B. Find \(E[X]\) and \(\operatorname{Var}(X)\). (Answer: \(E[X]=3.60\), \(\operatorname{Var}(X)=13.04\))