Why Compare Residual Spread by Group?
A residual plot can show whether residual spread changes across fitted values or predictors. Grouping observations can make that pattern easier to describe when a predictor is categorical or when a continuous predictor has a meaningful range. The goal is to compare the residuals from a specified mean model, not simply to compare how variable the raw outcomes are in different groups.
This distinction matters because outcomes can vary for two different reasons: the fitted mean can change, and the observations can vary around that mean. If a model accounts for systematic mean differences, its residuals focus attention on the remaining variation. Comparing raw outcomes alone can mix these sources of variation.
Set Up the Comparison
Suppose the fitted mean model is \(Y_i=\mathbf{x}_i^\mathsf{T}\boldsymbol{\beta}+\varepsilon_i\), where \(\mathbf{x}_i\) contains the predictors for observation \(i\). A common target is whether the error variance is approximately constant across the predictor settings: \(\operatorname{Var}(\varepsilon_i\mid \mathbf{x}_i)=\sigma^2\). A comparison across groups can help reveal departures from this condition, but it does not establish that the mean model is correct.
Before comparing spread, check that the fitted model is a reasonable description of the conditional mean. A residual pattern caused by an omitted group mean, curvature, or another systematic mean feature should not be interpreted as a pure difference in variance. Residual plots for unequal variance are useful alongside grouped summaries: plots preserve individual observations and can reveal patterns that a single number per group hides.
Groups can be defined by a factor such as clinic type, machine, or treatment category, or by dividing a continuous predictor into ranges. For continuous predictors, ranges should be chosen for a clear reason and reported explicitly. Different cut points can produce different summaries, and a coarse grouping can conceal a gradual pattern within a range.
The residual mean is also worth checking. A group with a nonzero average residual may indicate a mean-model problem, not just different spread. When the model includes a separate intercept for every group, least squares makes the residuals sum to zero within each group. Without those group indicators, that property need not hold. In either case, distinguish a shift in residual location from a change in residual spread.
Worked Comparisons
Worked Example: Raw Outcome Spread Versus Residual Spread
Consider hypothetical data from two categories, A and B, with a quantitative predictor \(x\). A fitted model includes an intercept, \(x\), and a category indicator for B. Suppose the fitted equations are \(\hat{y}=10+2x\) for A and \(\hat{y}=15+2x\) for B. The observed outcomes and residuals are:
For A, \(x=(0,0,0,0)\), \(y=(9,11,9,11)\), and \(e=(-1,1,-1,1)\). For B, \(x=(0,1,2,3)\), \(y=(16,16,18,22)\), and \(e=(1,-1,-1,1)\).
The stated fitted model is consistent with these data. Each category's residuals sum to zero. Also, for B, the residual cross-product with \(x\) is \(0(1)+1(-1)+2(-1)+3(1)=0\); for A, \(x\) is constant and the residuals sum to zero. Thus the residuals satisfy the least-squares constraints for this model.
For A, the raw outcome mean is \(10\), so its sample standard deviation is \[ s_{y,A}=\sqrt{\frac{(9-10)^2+(11-10)^2+(9-10)^2+(11-10)^2}{4-1}} =\sqrt{\frac{4}{3}}=1.155. \] Its residual sample standard deviation is also \(\sqrt{4/3}=1.155\).
For B, the raw outcome mean is \(18\), giving \[ s_{y,B}=\sqrt{\frac{(16-18)^2+(16-18)^2+(18-18)^2+(22-18)^2}{4-1}} =\sqrt{\frac{24}{3}}=2.828. \] But B's residual sample standard deviation is \[ s_{e,B}=\sqrt{\frac{1^2+(-1)^2+(-1)^2+1^2}{4-1}} =\sqrt{\frac{4}{3}}=1.155. \]
The raw outcomes vary more in B because \(x\) varies there and the fitted outcome changes by 2 units for each 1-unit increase in \(x\). After accounting for the fitted mean, the residual standard deviations are equal in these data. Comparing raw outcome spread would therefore give a misleading impression of unequal residual spread.
Worked Example: Comparing Groups of Unequal Sizes
Suppose a hypothetical regression includes category indicators, and the residuals are \((-1,0,1)\) in group A and \((-3,-2,-1,1,2,3)\) in group B. The residuals sum to zero within both groups, consistent with including separate group intercepts. The groups have different sizes, so report those sizes along with the summaries.
For A, \(n_A=3\), the sum of squared residuals is \(2\), and the sample standard deviation is \[ s_{e,A}=\sqrt{\frac{(-1)^2+0^2+1^2}{3-1}} =\sqrt{\frac{2}{2}}=1.000. \] The root mean square residual is \(\sqrt{2/3}=0.816\).
For B, \(n_B=6\), the sum of squared residuals is \(28\), and the sample standard deviation is \[ s_{e,B}=\sqrt{\frac{(-3)^2+(-2)^2+(-1)^2+1^2+2^2+3^2}{6-1}} =\sqrt{\frac{28}{5}}=2.366. \] The root mean square residual is \(\sqrt{28/6}=2.160\).
These summaries suggest substantially greater residual spread in B than in A, while also showing that B has twice as many observations. The larger group may give a more stable descriptive summary, but size alone does not guarantee that it is representative. The small group’s standard deviation is especially sensitive to its three residuals. The comparison is descriptive: it does not, by itself, quantify uncertainty or establish a statistically significant variance difference.
Worked Example: Comparing Spread Across Predictor Ranges
A hypothetical analyst divides a continuous predictor into three stated ranges and fits a model with a separate mean for each range. The residuals in the ranges are, respectively, \((-1,1)\), \((-2,0,2)\), and \((-4,-2,0,2,4)\). The zero residual sum in each range is consistent with fitting a separate intercept for each range.
For the first range, \(n_1=2\) and the sum of squared residuals is \(2\). Thus the sample residual standard deviation is \[ s_{e,1}=\sqrt{\frac{2}{2-1}}=1.414, \] and the root mean square is \(\sqrt{2/2}=1.000\).
For the second range, \(n_2=3\) and the sum of squares is \(8\). Therefore \[ s_{e,2}=\sqrt{\frac{8}{3-1}}=2.000, \qquad \operatorname{RMS}_2=\sqrt{\frac{8}{3}}=1.633. \] For the third range, \(n_3=5\) and the sum of squares is \(40\), giving \[ s_{e,3}=\sqrt{\frac{40}{5-1}}=3.162, \qquad \operatorname{RMS}_3=\sqrt{\frac{40}{5}}=2.828. \]
Both summaries increase across the ranges, so these hypothetical residuals show a descriptive pattern of increasing spread. However, the first group contains only two observations, and the conclusion may depend on how the predictor was divided. The plot of individual residuals against the original predictor should be checked before describing the pattern as a general trend.
How to Read the Evidence
A grouped residual plot should make group sizes and individual residuals visible. Useful displays include side-by-side dot plots, boxplots, or residuals plotted against the predictor with ranges marked. A table of \(n_g\), residual mean, residual standard deviation, and a robust magnitude summary can complement the graph. No single summary captures every feature: a few large residuals can inflate the standard deviation, while a median-based summary can conceal changes in the tails.
Unequal group sizes require particular care. A pooled summary is weighted toward groups with more observations; it can hide a pattern in a small group or make the largest group dominate the description. Compare group-specific summaries and plots first, and do not treat a pooled spread as evidence that each group has similar spread. Small groups also produce unstable estimates, so a striking difference based on only a few observations warrants caution.
Residuals are estimated quantities, not the unobserved errors. Under a homoskedastic linear model with independent errors of variance \(\sigma^2\), the residual variance for observation \(i\), conditional on the predictor matrix, is \(\sigma^2(1-h_{ii})\), where \(h_{ii}\) is its leverage. This follows because the residual vector is \((I-H)\boldsymbol{\varepsilon}\), and \(I-H\) is symmetric and idempotent, so its conditional covariance is \(\sigma^2(I-H)\). Consequently, groups with different leverage distributions can show different raw residual spreads even when the error variance is constant. A grouped comparison should therefore be read with leverage and the design in mind, especially when group sizes are small or predictor values are unusual.
These comparisons help describe and locate possible unequal spread. They do not identify its cause, prove that a variance condition fails, or replace a formal test. A pattern may also reflect a misspecified mean, dependence, influential observations, or other features of the data. Formal testing and adjustments to uncertainty require additional methods.
Common Mistake: Comparing Raw Outcomes
Wrong reasoning: “The outcomes in group B have a larger standard deviation than the outcomes in group A, so the residual variance must be larger in B.” That conclusion does not follow if the groups differ in fitted means or in how widely their predictors vary.
Correction: First fit and assess a suitable mean model. Then compare residuals across the groups, reporting group sizes and checking plots, residual location, and leverage. Treat the resulting pattern as diagnostic evidence rather than a stand-alone test or proof.
Check Your Understanding
Use the definitions and cautions in this tutorial to answer the following questions.
- Why can raw outcomes have different spreads across two groups even if their residual spreads are similar?
- A group has residuals \((-2,0,2)\). Calculate its sample residual standard deviation and root mean square residual.
- Why should a table comparing residual spread include the group sample sizes?
- What is one way unequal leverage distributions can complicate comparisons of raw residual spread?
- Why can dividing a continuous predictor into ranges conceal a gradual change in residual spread?