Tutorials › Regression Analysis (Undergraduate) › Subgroup Calibration and Error Comparisons

Prediction Metrics and Calibration · Tutorial 788 of 991

Subgroup Calibration and Error Comparisons

Compare prediction errors and calibration across subgroups, and see why an overall score may not represent every group’s experience.

Intermediate 10 min read

What You'll Learn

  • Calculate mean error, MAE, and RMSE separately for defined subgroups
  • Interpret the sign of subgroup mean error using a clear error convention
  • Summarize calibration within groups using calibration-in-the-large and calibration slopes
  • Compare subgroup metrics with overall metrics using correct weighted formulas
  • Recognize how group size and opposing patterns can obscure differences in aggregate summaries
  • Report subgroup comparisons cautiously, with units and group sizes

Why Compare Prediction Performance by Subgroup?

An overall prediction metric summarizes performance across all observations being evaluated. That summary can be useful, but it may conceal an important difference: predictions may be accurate for one group and systematically less accurate for another. For example, a model used to predict a health measurement might have small errors for most patients but large errors for a clinically meaningful subgroup. A single average cannot show that contrast.

Subgroup comparisons calculate familiar error and calibration summaries separately for groups defined by a relevant characteristic, such as age band, service location, or a prespecified risk category. They do not, by themselves, explain why performance differs or establish that group membership caused the difference. Their purpose is to make performance patterns visible and to support careful evaluation.

Definition: For observation \(i\), define the prediction error as \(e_i=y_i-\hat{y}_i\), where \(y_i\) is the observed outcome and \(\hat{y}_i\) is its prediction. Thus a positive error means the prediction was too low (underprediction), and a negative error means it was too high (overprediction). For subgroup \(g\), containing \(n_g\) observations, the mean error, mean absolute error (MAE), and root mean squared error (RMSE) are
$$ \mathrm{ME}_g=\frac{1}{n_g}\sum_{i\in g}e_i,\qquad \mathrm{MAE}_g=\frac{1}{n_g}\sum_{i\in g}|e_i|,\qquad \mathrm{RMSE}_g=\sqrt{\frac{1}{n_g}\sum_{i\in g}e_i^2}. $$

Mean error describes the direction and average size of signed errors, so positive and negative errors can offset one another. MAE and RMSE measure error magnitude without that cancellation. RMSE gives relatively more weight to large errors because the errors are squared before averaging. All three have the same units as the outcome.

Calculate and Compare the Metrics Within Groups

A useful comparison reports each subgroup’s sample size alongside its metrics. The group definitions should be relevant to the prediction task and set out clearly. If groups are selected after looking through many possible splits, an extreme difference can arise by chance; such a pattern should be treated as exploratory rather than as a confirmed finding.

Worked Example: Error Metrics for Two Subgroups

Suppose a hypothetical model predicts a measurement in units. The table gives observed values and predictions for four people in each of two prespecified subgroups. Calculate the three error summaries in each subgroup.

SubgroupObserved valuesPredicted values
A12, 18, 31, 3910, 20, 30, 40
B15, 25, 25, 3510, 20, 30, 40

For subgroup A, the errors \(y_i-\hat{y}_i\) are \(2,-2,1,-1\). With \(n_A=4\),

$$ \mathrm{ME}_A=\frac{2-2+1-1}{4}=\frac{0}{4}=0, \qquad \mathrm{MAE}_A=\frac{2+2+1+1}{4}=\frac{6}{4}=1.5, $$
$$ \mathrm{RMSE}_A=\sqrt{\frac{2^2+(-2)^2+1^2+(-1)^2}{4}} =\sqrt{\frac{10}{4}}=\sqrt{2.5}\approx1.581. $$

For subgroup B, the errors are \(5,5,-5,-5\). Therefore,

$$ \mathrm{ME}_B=\frac{5+5-5-5}{4}=0, \qquad \mathrm{MAE}_B=\frac{5+5+5+5}{4}=5, \qquad \mathrm{RMSE}_B=\sqrt{\frac{100}{4}}=5. $$

Both subgroups have zero mean error, but that does not mean their prediction performance is alike. The average signed errors cancel within each group, while subgroup B has substantially larger typical error magnitudes: its MAE is 5 units, compared with 1.5 units for subgroup A. Here RMSE also exceeds the subgroup A MAE, reflecting its greater sensitivity to the larger errors.

How Subgroup and Overall Metrics Are Related

For a partition of the data into nonoverlapping subgroups, the overall mean error is the group-size-weighted average of subgroup mean errors. The same averaging identity applies to MAE and to mean squared error, but not directly to RMSE. The reason is that RMSE takes a square root after averaging squared errors.

Result: If the subgroups partition all \(n\) observations, so that \(n=\sum_g n_g\), then
$$ \mathrm{ME}=\sum_g\frac{n_g}{n}\mathrm{ME}_g,\qquad \mathrm{MAE}=\sum_g\frac{n_g}{n}\mathrm{MAE}_g, $$
$$ \mathrm{RMSE} =\sqrt{\sum_g\frac{n_g}{n}\mathrm{RMSE}_g^2}. $$

To justify the last identity, start with the overall mean squared error. Each subgroup contributes the sum of its squared errors, and that sum equals its size multiplied by its subgroup mean squared error:

$$ \frac{1}{n}\sum_g\sum_{i\in g}e_i^2 =\frac{1}{n}\sum_g n_g\left(\frac{1}{n_g}\sum_{i\in g}e_i^2\right) =\sum_g\frac{n_g}{n}\mathrm{RMSE}_g^2. $$

Taking the square root gives the stated overall RMSE formula. In particular, averaging subgroup RMSE values with group-size weights generally gives the wrong overall RMSE. The correct calculation weights the subgroup mean squared errors and then takes one square root.

Worked Example: Reconstructing the Overall Metrics

Use the eight hypothetical observations in the previous example. Each subgroup has four observations, so each has weight \(4/8=0.5\). The overall mean error and MAE are

$$ \mathrm{ME}=0.5(0)+0.5(0)=0, \qquad \mathrm{MAE}=0.5(1.5)+0.5(5)=3.25. $$

For RMSE, combine the subgroup mean squared errors, which are \(1.581^2=2.5\) for A and \(5^2=25\) for B:

$$ \mathrm{RMSE}=\sqrt{0.5(2.5)+0.5(25)} =\sqrt{13.75}\approx3.708. $$

This overall RMSE is not the arithmetic average \((1.581+5)/2\), which is about \(3.291\). The overall MAE of 3.25 also does not describe either subgroup particularly well: it is higher than subgroup A’s MAE and lower than subgroup B’s. Reporting the overall figures without the subgroup results would hide this difference.

Calibration Summaries Within Subgroups

Error metrics describe discrepancies between observed and predicted values. Calibration asks whether predicted values agree with observed outcomes across their range. For subgroup comparisons, it is useful to report subgroup means and, when appropriate, the subgroup calibration intercept and slope. In a linear calibration summary, observed outcomes are regressed on predictions within a subgroup:

$$ y_i=a_g+b_g\hat{y}_i+\varepsilon_i. $$

Here \(a_g\) is the calibration intercept and \(b_g\) is the calibration slope for subgroup \(g\). Ideal calibration corresponds to \(a_g=0\) and \(b_g=1\). An intercept different from zero indicates an offset in this linear summary; a slope different from one indicates that the observed-predicted relationship is not at the ideal scale. These summaries complement error metrics rather than replacing them.

Calibration in the large: The subgroup mean error \(\overline{y}_g-\overline{\hat{y}}_g\) summarizes average underprediction or overprediction in that subgroup. With the convention \(e_i=y_i-\hat{y}_i\), a positive value indicates average underprediction. It is not generally the same as the intercept \(a_g\) from an unconstrained calibration regression when its slope is estimated rather than fixed at 1.

Worked Example: Comparing Subgroup Calibration Slopes

Return to the hypothetical data in the first example. Within each subgroup, the predictions are \(10,20,30,40\), with mean \(\bar{\hat{y}}_g=25\). The observed mean is also 25 in both groups. For an ordinary least-squares calibration line, the slope is \(S_{\hat{y}y}/S_{\hat{y}\hat{y}}\), the ratio of the sum of cross-products of centered predictions and outcomes to the sum of squared centered predictions. In each group,

$$ S_{\hat{y}\hat{y}}=(-15)^2+(-5)^2+5^2+15^2=500. $$

For subgroup A, the observed values \(12,18,31,39\) have deviations from their mean 25 of \(-13,-7,6,14\). Thus

$$ S_{\hat{y}y,A}=(-15)(-13)+(-5)(-7)+(5)(6)+(15)(14)=470, $$
$$ b_A=\frac{470}{500}=0.94,\qquad a_A=\bar{y}_A-b_A\bar{\hat{y}}_A=25-0.94(25)=1.5. $$

For subgroup B, the observed values \(15,25,25,35\) have deviations \(-10,0,0,10\) from their mean of 25. Therefore,

$$ S_{\hat{y}y,B}=(-15)(-10)+(-5)(0)+(5)(0)+(15)(10)=300, $$
$$ b_B=\frac{300}{500}=0.60,\qquad a_B=25-0.60(25)=10. $$

The calibration summaries differ: subgroup A has slope 0.94 and intercept 1.5 units, whereas subgroup B has slope 0.60 and intercept 10 units. Both groups have calibration-in-the-large equal to zero because their mean predictions and mean outcomes match. That agreement of means does not imply ideal calibration throughout the range; the different slopes show why a group-level mean difference alone may be insufficient.

Group Size, Interpretation, and Common Pitfalls

An overall metric gives more influence to larger subgroups because it summarizes observations, not groups equally. That may be appropriate when the target is average performance for the observed population. If the goal is to compare groups on equal footing, an unweighted average of subgroup metrics answers a different question and should be labelled accordingly. Neither choice is universally correct; the reporting should match the intended target.

Worked Example: A Small Group Hidden by Overall Error

Suppose a hypothetical model predicts a laboratory measurement in mg/dL for 100 people. For 90 people in subgroup A, the error is 0 mg/dL. For 10 people in subgroup B, the error is 10 mg/dL for each person. Calculate the overall summaries and compare them with subgroup B.

Subgroup B has \(\mathrm{ME}_B=10\) mg/dL, \(\mathrm{MAE}_B=10\) mg/dL, and \(\mathrm{RMSE}_B=10\) mg/dL. Subgroup A has all three metrics equal to zero. The overall mean error and MAE are

$$ \mathrm{ME}=\mathrm{MAE} =\frac{90(0)+10(10)}{100}=1\text{ mg/dL}. $$

For RMSE, the subgroup B squared error is \(10^2=100\) \((\text{mg/dL})^2\), while subgroup A’s is zero:

$$ \mathrm{RMSE} =\sqrt{\frac{90(0^2)+10(10^2)}{100}} =\sqrt{10}\approx3.162\text{ mg/dL}. $$

The overall summaries are much smaller than subgroup B’s errors because subgroup B accounts for only 10% of the observations. This is not an arithmetic defect: the overall figures correctly summarize the full set of 100 people. But they would be incomplete if the question is whether errors are acceptably small for each subgroup.

A subgroup with few observations also tends to have less stable summaries: changing one or two predictions can substantially alter its MAE, RMSE, or calibration line. Report the subgroup sample size and avoid interpreting small numerical differences as firm evidence of a persistent performance gap. A useful report states how groups were defined, gives their sizes, uses consistent units and error signs, and presents both subgroup and overall summaries.

  • Mistake: “The overall mean error is near zero, so predictions are unbiased in every subgroup.” The overall mean can conceal group-specific underprediction and overprediction that offset one another. Calculate mean error separately by subgroup.
  • Mistake: “Overall RMSE is the weighted average of subgroup RMSE values.” RMSE is a square root of a weighted mean squared error. Weight subgroup RMSE values after squaring them, then take one square root.
  • Mistake: “Matching group means proves calibration.” A mean prediction can match a mean outcome while calibration varies across the prediction range. Consider subgroup slopes and other relevant calibration summaries as well.
Key takeaway: Overall metrics describe the combined observations, not necessarily each meaningful subgroup. Report subgroup sizes, signed and magnitude-based errors, and relevant calibration summaries together; use the group definitions and units to make every comparison interpretable.

Check Your Understanding

Use the definitions and calculations in this tutorial to answer the following.

  1. If errors are defined as observed minus predicted, what does a negative subgroup mean error indicate?
  2. Why can two subgroups have the same mean error but different MAE values?
  3. A partition has subgroup RMSE values 2 and 6, with equal subgroup sizes. Write the formula for the overall RMSE. Why is it not the arithmetic average of 2 and 6?
  4. What do calibration-in-the-large and the calibration slope summarize, respectively?
  5. Why should subgroup sample sizes be reported alongside error and calibration summaries?