Tutorials › Generalized Linear Models › Calibration Diagnostics for Predicted Binary Risks

Goodness of Fit and Calibration · Tutorial 793 of 981

Calibration Diagnostics for Predicted Binary Risks

Learn how to read complementary calibration diagnostics, calculate their summaries, and identify what each can—and cannot—establish.

Intermediate 12 min read

What You'll Learn

  • Define calibration of binary risks using the conditional event probability given a prediction
  • Interpret calibration plots alongside calibration-in-the-large and calibration slopes
  • Distinguish agreement in average risk from agreement across the range of predictions
  • Calculate calibration summaries for rare events and heterogeneous predicted risks
  • Recognize limitations of bins, fitted recalibration models, and small validation samples

Why Use More Than One Calibration Diagnostic?

A binary risk prediction is a probability \(p_i\) assigned to an observation whose outcome \(Y_i\) is 0 or 1. Calibration asks whether predictions agree with observed event frequencies. A useful assessment does not reduce this question to one number: agreement in the overall event rate can coexist with serious errors at particular predicted risks, while a plot can look persuasive even when its estimates are imprecise.

Three complementary views help: a calibration plot shows how observed risk varies across predicted risk; calibration-in-the-large summarizes overall over- or underprediction; and a calibration slope assesses whether predictions vary too much or too little. These are diagnostics, not interchangeable tests. Their interpretation depends on how predictions were obtained, the validation sample, and the distribution of predicted risks.

Definition: Let \(Y\in\{0,1\}\) be a binary outcome and \(P\in[0,1]\) its predicted risk. The predictions are calibrated if \(E[Y\mid P]=P\) almost surely. Since \(E[Y\mid P]\) is the event probability conditional on the prediction, calibration means that among observations assigned risk \(p\), the event frequency is \(p\), in the population sense.

In a validation sample, the predictions \(p_i\) are treated as given and compared with outcomes \(Y_i\). The observed data cannot establish the conditional equality at every possible value of \(P\); it can only provide estimates, with uncertainty. A calibration plot estimates the relationship between outcome and prediction. Its ideal reference is the diagonal \(y=p\), but uncertainty and the amount of data near each risk value matter as much as visual proximity.

Three Complementary Summaries

A calibration plot can be constructed by grouping predictions into bins and plotting each bin's mean observed outcome against its mean predicted risk, or by estimating a smooth calibration curve. Binned plots are simple, but the result depends on the binning and can hide within-bin variation. Smooth curves avoid abrupt bin boundaries but rely on a smoothing method and can be uncertain, especially where few predictions occur. Uncertainty bands should be read as uncertainty about the estimated curve, not as proof of calibration wherever the diagonal falls inside a band.

Two logistic recalibration summaries provide compact complements. Write \(z_i=\operatorname{logit}(p_i)=\log\{p_i/(1-p_i)\}\), requiring \(0<p_i<1\). Calibration-in-the-large fits an intercept while using \(z_i\) as a fixed offset. The calibration slope fits both an intercept and a coefficient for \(z_i\). In both cases, the outcome is modeled as Bernoulli; these regressions describe the validation data and do not by themselves repair the original predictions.

Definition: In a validation sample of \(n\) independent Bernoulli outcomes, calibration-in-the-large estimates \(\alpha\) in \(\operatorname{logit}P(Y_i=1)=\alpha+z_i\), with \(z_i\) fixed as an offset. Ideal calibration-in-the-large has \(\alpha=0\). The calibration slope estimates \(\alpha\) and \(\beta\) in \(\operatorname{logit}P(Y_i=1)=\alpha+\beta z_i\). Ideal values are \(\alpha=0\) and \(\beta=1\). These interpretations presume a finite, identifiable fit; boundary predictions and separation can prevent an ordinary finite maximum-likelihood estimate.

A positive calibration-in-the-large intercept indicates that the validation outcomes require a common upward shift on the log-odds scale when the original predictions are used as offsets; a negative intercept indicates a downward shift. It is not simply the difference between the observed and predicted event proportions. A slope below 1 typically indicates that the spread of predicted risks is too extreme relative to outcomes in this validation sample; a slope above 1 indicates that the spread is too compressed. The fitted intercept in the slope model can differ from the calibration-in-the-large intercept, because the slope model also changes the contribution of each predicted risk.

Worked Example: A Rare-Event Shift in Overall Risk

Suppose a validation sample has 1,000 observations, each assigned risk \(p_i=0.01\), and 18 events are observed. The total predicted number of events is \(1{,}000(0.01)=10\), while the observed event proportion is \(18/1{,}000=0.018\). The raw difference is \(0.018-0.010=0.008\), or 8 events per 1,000 predictions.

Because all predictions are equal, the calibration-in-the-large fit has a common fitted event probability equal to the observed proportion: \(\operatorname{expit}(\alpha+\operatorname{logit}(0.01))=0.018\). Thus \(\alpha=\operatorname{logit}(0.018)-\operatorname{logit}(0.01)\).

$$ \alpha=\log\left(\frac{0.018}{0.982}\right) -\log\left(\frac{0.01}{0.99}\right) \approx -3.9992-(-4.5951)=0.5959. $$

The positive intercept indicates underprediction in this sample. The numerical intercept is not 0.008: it is a shift on the log-odds scale. Since all predicted risks are identical, a calibration slope cannot be separately estimated along with an intercept; there is no variation in \(z_i\) from which to estimate the slope.

What Average Agreement Does—and Does Not—Show

Calibration implies agreement in average risk, but the reverse is not true. The distinction is particularly important when predictions vary substantially. A model can predict too low for one set of observations and too high for another, with the errors cancelling in the total number of events.

Result: If \(Y\) is binary and \(P\) is a predicted risk, calibration \(E[Y\mid P]=P\) implies \(E[Y]=E[P]\). Equality of these two means alone does not imply calibration.

Proof. By the law of iterated expectation,

$$ E[Y]=E\{E[Y\mid P]\}=E[P]. $$

For the converse, let \(P\) equal 0.1 or 0.9 with probability one-half each, and let the conditional event probability be 0.9 when \(P=0.1\) and 0.1 when \(P=0.9\). Then \(E[P]=(0.1+0.9)/2=0.5\) and \(E[Y]=(0.9+0.1)/2=0.5\), but \(E[Y\mid P]\ne P\) at either prediction value. Thus equal means can conceal substantial miscalibration. \(\square\)

Worked Example: Equal Overall Rates, Opposing Errors

Consider 1,000 validation observations. Of these, 900 receive risk 0.01 and 100 receive risk 0.10. There are 18 events among the first 900 and 2 among the last 100.

The first group's observed event rate is \(18/900=0.02\), twice its predicted risk. Its expected event count was \(900(0.01)=9\), so it has 9 more events than predicted. The second group's observed rate is \(2/100=0.02\), compared with risk 0.10; its expected count was \(100(0.10)=10\), so it has 8 fewer events than predicted.

Overall, 20 events are observed and \(9+10=19\) are predicted. The observed proportion is 0.020 and the mean predicted risk is 0.019: the difference is only 0.001, or one event per 1,000. Yet the group-specific discrepancies go in opposite directions. The two-point calibration plot would show observed risk 0.02 at predictions 0.01 and 0.10, rather than lying on the diagonal.

The slope fit also signals the pattern. Both groups have the same observed rate, 0.02, so the fitted logistic model with an intercept and slope has \(\hat\alpha=\operatorname{logit}(0.02)\approx-3.892\) and \(\hat\beta=0\): it assigns the same fitted rate to both distinct prediction values. The slope fit is finite here because each group's data include both events and non-events and the prediction values differ. The near agreement of the overall event counts therefore does not establish calibration across risks.

Why the Recalibration Fits Have Their Score Equations

The logistic summaries are tied to the validation data through likelihood equations. Stating these equations makes clear what the fitted intercept and slope actually enforce. Assume that, conditional on the fixed predictions, \(Y_1,\ldots,Y_n\) are independent Bernoulli outcomes, and consider finite maximum-likelihood estimates in the stated model.

Result: In the calibration-slope model \(q_i=\operatorname{expit}(\alpha+\beta z_i)\), any finite maximum-likelihood estimate satisfies \(\sum_i(Y_i-q_i)=0\) and \(\sum_i z_i(Y_i-q_i)=0\). In the calibration-in-the-large model \(q_i=\operatorname{expit}(\alpha+z_i)\), its finite estimate satisfies \(\sum_i(Y_i-q_i)=0\).

Derivation. Ignoring constants that do not depend on the parameters, the slope-model log-likelihood is

$$ \ell(\alpha,\beta)=\sum_{i=1}^n \left[Y_i(\alpha+\beta z_i)-\log\{1+\exp(\alpha+\beta z_i)\}\right]. $$

Differentiating gives \(\partial\ell/\partial\alpha=\sum_i(Y_i-q_i)\) and \(\partial\ell/\partial\beta=\sum_i z_i(Y_i-q_i)\), because the derivative of \(\log\{1+\exp(t)\}\) is \(\operatorname{expit}(t)\). At a finite interior maximum, both derivatives are zero, which proves the two equations. In the offset model, \(\beta\) is fixed at 1 and only \(\alpha\) is estimated. Differentiating with respect to \(\alpha\) gives the single equation \(\sum_i(Y_i-q_i)=0\). Thus the fitted recalibrated probabilities match the observed event total within each fitted model; they need not match each observation or each risk region. \(\square\)

This derivation also explains why the calibration-in-the-large intercept is not the raw mean difference. The fitted probabilities are \(\operatorname{expit}(z_i+\hat\alpha)\), not \(p_i+\hat\alpha\); the logit shift changes each risk nonlinearly. The score equation matches their sum to the observed number of events, while the estimated shift depends on the full set of predicted risks.

Combining Diagnostics in Practice

A disciplined assessment uses the diagnostics to answer related but distinct questions. First inspect the distribution of predictions and the number of events: a curve in a region with little data is necessarily uncertain. Then examine a calibration plot with uncertainty, checking for systematic departures from the diagonal rather than treating each bin as a definitive test. Report calibration-in-the-large to describe the overall shift and the slope to summarize whether the risk spread appears too extreme or too compressed.

These summaries are most interpretable when predictions are evaluated on data not used to fit or tune the prediction model. If the same outcomes are used both to construct predictions and assess them, apparent calibration can be optimistic. Also report the validation sample size and event count: with rare outcomes, a small change in events can substantially alter observed rates and fitted recalibration coefficients. A numerical estimate without its uncertainty and data context is easy to overinterpret.

Worked Example: Reading a Plot and Its Summaries Together

Suppose a validation study contains 2,000 observations and 80 events. A smooth calibration curve lies close to the diagonal for predicted risks between 0.05 and 0.20, but bends below it at higher predicted risks. The estimated calibration-in-the-large intercept is 0.01, with an uncertainty interval that includes 0, and the fitted slope is 0.72.

The intercept provides little evidence of a common overall shift: its estimate is near the ideal value 0, and its uncertainty includes that value. It does not erase the visible local departure at high predicted risks. The slope below 1 is consistent with predictions that are too spread out, while the curve suggests that the discrepancy may not be captured by a single linear change on the log-odds scale.

The appropriate conclusion is qualified: average risk appears broadly aligned, but there is evidence of overstatement in the high-risk region and the overall slope suggests excessive spread. The curve's uncertainty at high risk must be checked before treating that pattern as stable, particularly if few observations or events occur there. Neither the near-zero intercept nor the slope alone replaces inspection of the curve.

Common Pitfalls

  • Equating matching totals with calibration. The reasoning “observed and predicted event counts are close, so predictions are calibrated” is wrong when errors can cancel across risk levels. Check the calibration curve and slope as well as the overall shift.
  • Reading the intercept as a risk difference. Calibration-in-the-large is a log-odds shift in an offset model, not observed mean risk minus predicted mean risk. Report the scale and, when helpful, both the fitted intercept and the raw mean difference.
  • Treating the slope as a complete curve. A single slope summarizes a particular logistic recalibration model. A nonlinear departure can remain even if the slope is near 1; compare it with the plot.
  • Overinterpreting bins or a smooth curve. Bin choices affect binned summaries, and smoothing affects smooth estimates. Show uncertainty and be cautious where observations are sparse.
  • Attempting a slope estimate without prediction variation. If all \(p_i\) are equal, all \(z_i\) are equal, so intercept and slope cannot both be identified separately.
Key takeaway: A calibration plot, calibration-in-the-large, and calibration slope answer different questions. Use them together: the plot reveals how agreement changes over predicted risk, the intercept summarizes an overall log-odds shift, and the slope summarizes the spread of predictions under a logistic recalibration model.

Check Your Understanding

Use the definitions and derivations above to answer the following.

  1. Why does calibration imply equality of mean observed and predicted risks, and why does the reverse implication fail?
  2. In the rare-event example, why is the calibration-in-the-large estimate a log-odds shift rather than the raw risk difference?
  3. How can a validation sample have nearly matching overall event counts while showing substantial miscalibration at different predicted risks?
  4. What two score equations characterize a finite calibration-slope fit, and what does the intercept equation enforce?
  5. Why can a calibration curve show a pattern that is not adequately described by the calibration slope?
Clinical Biostats