Tutorials › Exam P - Probability › Within-Group and Between-Group Variance

Exam P · Conditional Expectation and Decomposition · Tutorial 779 of 915

Within-Group and Between-Group Variance

Use conditional means and variances to calculate and interpret within-group and between-group contributions to overall variance.

Advanced 10 min read

What You'll Learn

  • Apply the total-variance formula using a discrete group variable.
  • Calculate within-group variance as a probability-weighted average.
  • Calculate between-group variance from group means and the overall mean.
  • Interpret group proportions as weights in finite populations and mixtures.
  • Check a variance decomposition using second moments or direct calculations.
  • Avoid confusing probability variance with a sample variance using an \(N-1\) denominator.

Why Separate Within-Group and Between-Group Variation?

A population can vary because observations differ inside the groups to which they belong, because the groups have different averages, or both. For example, the variation in a hypothetical portfolio's annual claim amounts might reflect differences among policyholders within a risk class and differences in average claim amounts between classes. A variance calculation that keeps these sources separate can explain where the overall variability comes from.

The same calculation applies when a group is selected randomly and a value is then generated according to that group's distribution. The group is a conditioning variable: once its value is known, the conditional mean and variance describe the selected group's behavior. The overall variance combines those conditional variances with the variation in the group means.

Definition: Let \(G\) be a discrete group label and let \(X\) be a random variable with finite variance. The within-group variance is \(E[\operatorname{Var}(X\mid G)]\), the weighted average of the conditional variances. The between-group variance is \(\operatorname{Var}(E[X\mid G])\), the variance of the conditional means across groups. Their sum is the overall variance of \(X\).

The Total-Variance Formula

Suppose the possible groups are \(g_1,\ldots,g_k\), with \(P(G=g_j)=p_j\). Write \(\mu_j=E[X\mid G=g_j]\) and \(\sigma_j^2=\operatorname{Var}(X\mid G=g_j)\). The group probabilities satisfy \(p_j\geq 0\) and \(\sum_{j=1}^k p_j=1\). The overall mean is the weighted mean of the group means, and total variance separates as follows.

$$ E[X]=\sum_{j=1}^k p_j\mu_j $$
$$ \operatorname{Var}(X) = \underbrace{\sum_{j=1}^k p_j\sigma_j^2}_{\text{within-group variance}} + \underbrace{\sum_{j=1}^k p_j(\mu_j-E[X])^2}_{\text{between-group variance}}. $$

The weights are essential. A group with probability \(0.8\) contributes four times as much as a group with probability \(0.2\), all else equal. Neither the conditional variances nor the squared deviations of group means are generally averaged with equal weights.

Why the Decomposition Holds

The key identity is the conditional version of the variance definition. For a group \(G=g_j\), the squared deviation from the overall mean can be split into a deviation from the group's mean and a deviation of the group's mean from the overall mean:

$$ X-E[X] = \bigl(X-E[X\mid G]\bigr) + \bigl(E[X\mid G]-E[X]\bigr). $$

Square this identity and take expectations. The cross-product has expectation zero. To see why, condition on \(G\): the term \(E[X\mid G]-E[X]\) is fixed within a group, while

$$ E[X-E[X\mid G]\mid G] = E[X\mid G]-E[X\mid G] = 0. $$

Consequently, the expected cross-product is zero. The expected square of the first term is \(E[\operatorname{Var}(X\mid G)]\); the expected square of the second is \(\operatorname{Var}(E[X\mid G])\). This proves the total-variance formula:

$$ \operatorname{Var}(X) = E[\operatorname{Var}(X\mid G)] + \operatorname{Var}(E[X\mid G]). $$

This justification requires finite second moments so the variances and expectations in the identity are defined. In a finite population with a uniformly selected member, these moments exist automatically.

Finite Populations: Group Sizes Become Weights

For a finite population of \(N\) values, imagine selecting one member uniformly at random and calling that member's value \(X\). If group \(j\) contains \(N_j\) members, then \(P(G=g_j)=N_j/N\). Thus group size, not the number of groups, determines the weight.

The variance here is the probability variance for a uniformly selected population member, with divisor \(N\). It is not the sample variance computed from observed data using divisor \(N-1\). The latter is a different statistic, often used to estimate an unknown population variance.

Worked Example: Splitting Variation in a Finite Population

A hypothetical five-member population has values 2, 4, and 6 in Group A, and values 8 and 10 in Group B. Select one member uniformly. Calculate the overall mean, the within-group variance, the between-group variance, and the overall variance.

Method. Use each group's proportion of the population as its probability, calculate conditional means and variances, then combine the two variance contributions.

Group probabilities and conditional moments. Group A has 3 of 5 members, so \(P(A)=3/5=0.6\). Its conditional mean is \((2+4+6)/3=4\). Its conditional variance is \( ((2-4)^2+(4-4)^2+(6-4)^2)/3=(4+0+4)/3=8/3\). Group B has 2 of 5 members, so \(P(B)=2/5=0.4\). Its conditional mean is \((8+10)/2=9\), and its conditional variance is \(((8-9)^2+(10-9)^2)/2=1\).

Overall mean. Weight the group means: \(E[X]=0.6(4)+0.4(9)=2.4+3.6=6\).

Within-group contribution. \(0.6(8/3)+0.4(1)=1.6+0.4=2\).

Between-group contribution. \(0.6(4-6)^2+0.4(9-6)^2=0.6(4)+0.4(9)=2.4+3.6=6\). Therefore, \(\operatorname{Var}(X)=2+6=8\).

Check. Directly from the five values, the mean is 6 and the variance is \(((2-6)^2+(4-6)^2+(6-6)^2+(8-6)^2+(10-6)^2)/5=(16+4+0+4+16)/5=8\). This agrees with the decomposition. The within-group component is the variation among members of the same group; the larger between-group component reflects the separation between the two group means.

Mixtures: Group Means Need Not Be Observed Values

In a mixture model, the group label is selected with specified probabilities and then \(X\) follows the conditional distribution for that group. The same weighted formulas apply whether the groups represent categories in a finite population or components of a probability model. Conditional means and variances are enough to calculate the overall variance; the full conditional distributions are not needed for this calculation.

Worked Example: Variance of a Two-Group Mixture

A hypothetical measurement \(X\) comes from Group A with probability \(0.4\) and Group B with probability \(0.6\). The conditional means are 10 and 16, and the conditional variances are 4 and 9, respectively. Find the overall mean and variance, and report each variance contribution.

Method. Calculate the weighted mean first, because the between-group contribution uses deviations from the overall mean, not deviations from zero.

Overall mean. \(E[X]=0.4(10)+0.6(16)=4+9.6=13.6\).

Within-group contribution. \(E[\operatorname{Var}(X\mid G)]=0.4(4)+0.6(9)=1.6+5.4=7\).

Between-group contribution. \(\operatorname{Var}(E[X\mid G])=0.4(10-13.6)^2+0.6(16-13.6)^2\). The deviations are \(-3.6\) and \(2.4\), so the contribution is \(0.4(12.96)+0.6(5.76)=5.184+3.456=8.64\).

Total and check. \(\operatorname{Var}(X)=7+8.64=15.64\). As a second-moment check, the weighted conditional second moment is \(0.4(4+10^2)+0.6(9+16^2)=0.4(104)+0.6(265)=41.6+159=200.6\). Subtracting the squared overall mean gives \(200.6-(13.6)^2=200.6-184.96=15.64\), as required.

Interpreting the Two Contributions

The within-group term measures the average residual spread after the group is known. It is a probability-weighted average, not the variance of all observations after subtracting a single group-specific quantity. The between-group term measures the spread in the group means around the overall mean. It is zero exactly when all groups with positive probability have the same conditional mean.

A zero between-group term does not imply zero overall variance: groups can have identical means and still have positive conditional variances. Conversely, if each group has no variation internally, the entire overall variance comes from differences among the group means. Both contributions are nonnegative, so the total variance cannot be less than either contribution individually.

For a numerical check, the second-moment identity is also useful:

$$ \operatorname{Var}(X) = \sum_{j=1}^k p_j\bigl(\sigma_j^2+\mu_j^2\bigr) - \left(\sum_{j=1}^k p_j\mu_j\right)^2. $$

This follows from \(E[X^2\mid G=g_j]=\sigma_j^2+\mu_j^2\), followed by \(\operatorname{Var}(X)=E[X^2]-(E[X])^2\). It provides an independent way to check arithmetic, but it does not replace interpreting the within- and between-group terms.

Common Mistakes and Exam Traps

  • Using the wrong center for the between-group term. The group means are compared with the overall mean. In the two-group example, using zero would produce \(0.4(10^2)+0.6(16^2)\), which is not the between-group variance. The correct center is \(13.6\), giving \(0.4(10-13.6)^2+0.6(16-13.6)^2=8.64\).
  • Giving every group equal weight. In the finite-population example, the groups have sizes 3 and 2, so their weights are \(0.6\) and \(0.4\), not \(0.5\) and \(0.5\).
  • Adding group variances without weighting them. The within-group contribution is \(\sum_j p_j\sigma_j^2\), not \(\sum_j\sigma_j^2\) and not an unweighted average unless all group probabilities are equal.
  • Mixing probability variance with sample variance. A uniformly selected member of a population of size \(N\) has variance with divisor \(N\). Replacing it with an \(N-1\) sample-variance calculation changes the quantity being computed.
Key takeaway: First find the weighted overall mean. Then compute the weighted average of conditional variances and the weighted variance of conditional means around that overall mean. Adding those two nonnegative contributions gives \(\operatorname{Var}(X)\).

Check Your Understanding

For each problem, show the overall mean and both variance contributions before combining them.

  1. A hypothetical outcome comes from Group A with probability \(0.3\) and Group B with probability \(0.7\). Their conditional means are 5 and 9, and their conditional variances are 4 and 1. Find the overall mean and variance. (Answer: Mean \(=7.8\); within \(=1.9\); between \(=3.36\); variance \(=5.26\).)
  2. A finite population has Group A values 1, 3, and 5, and Group B values 7 and 9. A member is selected uniformly. Find the within-group, between-group, and overall variances, using divisor \(N\). (Answer: Within \(=2\); between \(=6\); overall variance \(=8\).)
  3. A mixture has three groups with probabilities \(0.2, 0.3, 0.5\), conditional means \(2,6,8\), and conditional variances \(1,4,9\), respectively. Calculate the overall mean and variance. (Answer: Mean \(=6.2\); within \(=5.9\); between \(=5.16\); variance \(=11.06\).)
  4. A two-group model has probabilities \(0.25\) and \(0.75\), conditional means 12 and 20, and conditional variances 5 and 3. Find the variance decomposition. (Answer: Mean \(=18\); within \(=3.5\); between \(=12\); variance \(=15.5\).)
  5. A five-member finite population is divided into Group A with values 2 and 6, and Group B with values 4, 8, and 12. A member is selected uniformly. Find the overall mean and variance and verify the result directly from the five values. (Answer: Mean \(=6.4\); within \(=8\); between \(=3.84\); overall variance \(=11.84\).)

This within-versus-between interpretation is a useful way to organize conditional-variance calculations aligned with the SOA Exam P (Probability) syllabus: group proportions determine the weights, conditional variances describe internal spread, and group means determine the additional spread between groups.

Clinical Biostats