Tutorials › Pharmacokinetic-Pharmacodynamic (PK/PD) Modeling › Calibration and Residual Checks for Binary PK/PD Models

Binary, Ordinal and Count Response Models · Tutorial 321 of 598

Calibration and Residual Checks for Binary PK/PD Models

Use calibration and residual diagnostics to identify where a binary PK/PD model’s predicted risks agree with, or systematically differ from, observed outcomes.

Advanced 12 min read

What You'll Learn

  • Define calibration for predicted binary-response probabilities and distinguish it from discrimination.
  • Compare grouped observed risks with mean predicted risks, including their sampling uncertainty.
  • Calculate and interpret Pearson and deviance residuals for Bernoulli observations.
  • Use exposure-stratified diagnostics to detect systematic prediction errors across the concentration range.
  • Recognize when grouping, dependence, sparse data, or in-sample evaluation can mislead.
  • Choose complementary checks without treating a single diagnostic as proof of model adequacy.

Why Check Calibration?

A binary PK/PD model can rank patients or occasions from lower to higher risk and still give inaccurate probabilities. For example, among observations assigned a 30% probability of a pharmacodynamic event, calibration asks whether the event occurs about 30% of the time. This matters when predictions inform decisions that depend on absolute risk, such as whether an exposure level is associated with an acceptable event probability.

Let \(Y_i\) be the binary response for observation \(i\), with \(Y_i=1\) denoting the event and \(Y_i=0\) its absence. Let \(\hat p_i\) be the model-predicted probability of the event for that observation. A fitted binary model commonly gives \(\hat p_i=\operatorname{logit}^{-1}(\hat\eta_i)\), where \(\hat\eta_i\) is its fitted linear predictor and \(\operatorname{logit}^{-1}(u)=1/(1+\exp(-u))\). Diagnostics compare these probabilities with the outcomes, not merely with the model’s fitted coefficients.

Definition: A model is calibrated in a group of observations if the average observed event frequency agrees, within sampling variability, with the average predicted event probability in that group. In the population, calibration means that predicted risk \(p\) corresponds to an event probability \(p\). Calibration is distinct from discrimination, which concerns how well predictions rank observations with and without the event.

A finite sample will not match predictions exactly. Calibration assessment therefore looks for differences that are large, persistent, or patterned enough to be inconsistent with ordinary outcome variation. The target must also be clear: predictions for a new patient, predictions conditional on a patient-specific random effect, and marginal predictions averaged over patient variability answer different questions. Compare observed outcomes with predictions defined for the same target.

Grouped Observed-versus-Predicted Risks

A direct diagnostic is to sort observations by \(\hat p_i\), divide them into groups, and compare each group’s mean predicted risk with its observed event proportion. If group \(g\) contains \(n_g\) observations and \(O_g\) events, its observed risk is \(O_g/n_g\), while its mean predicted risk is the average \(\hat p_i\) in that group. A calibration plot places these two quantities on the vertical and horizontal axes, respectively. Perfect empirical agreement lies on the 45-degree line.

The grouping is a summary, not a model assumption. Groups should have enough observations and events to make observed proportions informative. Quantile-based groups often keep group sizes similar, while exposure-based groups can answer whether misfit changes over the concentration range. The choice should be reported: different cut points can hide or expose different patterns. Plot uncertainty intervals for observed risks when possible; an observed point away from the line is not automatically evidence of systematic misfit.

Worked Example: Comparing Grouped Risks

Suppose 200 hypothetical independent observations are divided into four equal-sized groups according to predicted event risk. The mean predictions are 0.10, 0.20, 0.40, and 0.60. The corresponding event counts are 6, 11, 19, and 31, with 50 observations in each group. Calculate and compare observed and predicted risks.

For each group, the observed risk is \(O_g/50\), and the expected number of events under the predictions is \(50\) times the mean predicted risk.

GroupMean predicted riskExpected eventsObserved eventsObserved risk
10.1050 × 0.10 = 566/50 = 0.12
20.2050 × 0.20 = 101111/50 = 0.22
30.4050 × 0.40 = 201919/50 = 0.38
40.6050 × 0.60 = 303131/50 = 0.62

The observed-minus-predicted differences are \(0.02,\ 0.02,\ -0.02,\) and \(0.02\), respectively. To gauge their scale, under independent Bernoulli outcomes with a common group probability \(p\), the standard error of an observed proportion is \(\sqrt{p(1-p)/n_g}\). Using each group’s mean prediction as \(p\), the approximate standard errors are 0.0424, 0.0566, 0.0693, and 0.0693. Each difference is smaller in magnitude than one such standard error. These data show no clear grouped calibration departure, but four groups of 50 do not establish that the model is calibrated at every risk level.

The standard error calculation is an approximation when predictions vary within a group. With independent outcomes and fixed predicted probabilities, the variance of the total number of events is \(\sum_i \hat p_i(1-\hat p_i)\); dividing by \(n_g^2\) gives the variance of the observed proportion. This expression is preferable when within-group predictions are not nearly equal. If observations are repeated within patients, treating them as independent can understate uncertainty; use an approach that respects the dependence and the prediction target.

Residuals for Binary Outcomes

For an individual Bernoulli observation, the raw residual is \(Y_i-\hat p_i\). It equals \(1-\hat p_i\) when the event occurs and \(-\hat p_i\) when it does not. Its expected value is zero if the predicted probability is correct, and its variance is \(\hat p_i(1-\hat p_i)\) under the Bernoulli model. Dividing by the square root of that variance gives the Pearson residual.

$$ r_{Pi}=\frac{Y_i-\hat p_i}{\sqrt{\hat p_i(1-\hat p_i)}}. $$

This standardization follows directly from the Bernoulli variance. If \(Y_i\) has event probability \(p_i\), then \(E(Y_i)=p_i\) and \(\operatorname{Var}(Y_i)=p_i(1-p_i)\). Replacing \(p_i\) with the fitted \(\hat p_i\) gives a residual with approximate unit scale when the model is adequate. It does not make the residual normally distributed: a single binary outcome has only two possible residual values at a given \(\hat p_i\).

Worked Example: Calculating Individual Residuals

Consider four hypothetical independent observations with predicted risks \(0.20,\ 0.40,\ 0.70,\) and \(0.80\), and outcomes \(0,\ 1,\ 1,\) and \(0\), respectively. Calculate the Pearson residual for each.

For the first observation, \(r_P=(0-0.20)/\sqrt{0.20(0.80)}=-0.20/0.40=-0.500\). For the second, \(r_P=(1-0.40)/\sqrt{0.40(0.60)}=0.60/\sqrt{0.24}=1.225\). For the third, \(r_P=(1-0.70)/\sqrt{0.70(0.30)}=0.30/\sqrt{0.21}=0.655\). For the fourth, \(r_P=(0-0.80)/\sqrt{0.80(0.20)}=-0.80/0.40=-2.000\).

The last observation is a non-event despite an 80% predicted risk, so it has a relatively large negative Pearson residual. One such observation is possible under a calibrated model; it is a prompt to examine its context, not a diagnosis by itself. In particular, inspect whether similarly high-risk observations show repeated non-events or whether the discrepancy is isolated.

Deviance residuals provide another signed measure of each observation’s contribution to the Bernoulli log-likelihood discrepancy from a saturated fit. For \(Y_i\) equal to zero or one, they are

$$ r_{Di}=\operatorname{sign}(Y_i-\hat p_i) \sqrt{2\left\{Y_i\log\left(\frac{Y_i}{\hat p_i}\right) +(1-Y_i)\log\left(\frac{1-Y_i}{1-\hat p_i}\right)\right\}}. $$

Terms of the form \(0\log(0/q)\) are defined as zero by continuity. For the four observations above, the deviance residuals are approximately \(-0.668,\ 1.354,\ 0.845,\) and \(-1.794\). For example, the first is \(-\sqrt{2\log(1/0.80)}=-0.668\), and the second is \(+\sqrt{2\log(1/0.40)}=1.354\). Pearson and deviance residuals are useful for finding unusual observations, but neither should be expected to follow a normal distribution in a binary model.

Look for Patterns Across Exposure

A residual’s sign has a direct interpretation: positive values indicate an event occurred more strongly than predicted, while negative values indicate less response than predicted. Plot residuals or grouped observed-versus-predicted risks against exposure, predicted risk, time, dose, and other scientifically relevant covariates. A trend can point to a missing or misspecified exposure effect, a changing baseline risk, or another omitted structure. A random-looking spread is reassuring but cannot prove that the model is correct.

Worked Example: Detecting Exposure-Related Misfit

In a hypothetical assessment, four exposure strata each contain 100 independent observations. The model predicts mean event risks of 0.10, 0.20, 0.40, and 0.70, while the observed event counts are 8, 18, 45, and 78. Compare risks and calculate grouped Pearson residuals for the event counts.

The observed risks are \(8/100=0.08,\ 18/100=0.18,\ 45/100=0.45,\) and \(78/100=0.78\). Expected event counts are 10, 20, 40, and 70. For each group, the count residual is \((O_g-E_g)/\sqrt{n_gp_g(1-p_g)}\). The four calculations are \((8-10)/\sqrt{100(0.10)(0.90)}=-2/3=-0.667\); \((18-20)/\sqrt{100(0.20)(0.80)}=-2/4=-0.500\); \((45-40)/\sqrt{100(0.40)(0.60)}=5/\sqrt{24}=1.021\); and \((78-70)/\sqrt{100(0.70)(0.30)}=8/\sqrt{21}=1.746\).

The observed-minus-predicted risk differences are \(-0.02,\ -0.02,\ 0.05,\) and \(0.08\). The sign changes from overprediction at the lower exposures to underprediction at the higher exposures, with increasing positive residuals at the upper end. This pattern is more concerning than any one residual alone and suggests exposure-dependent misfit. The grouped summary does not identify its cause: a different exposure-response shape, an omitted predictor, or chance variation remain possible explanations to investigate.

For a calibration-in-the-large check, one may fit a logistic recalibration model with the original predictions as an offset:

$$ \operatorname{logit}\{P(Y_i=1)\}=a+\operatorname{logit}(\hat p_i). $$

The ideal intercept is \(a=0\); a positive estimate indicates that observed risks are generally higher than predicted, and a negative estimate indicates they are generally lower. A calibration-slope check instead fits \(\operatorname{logit}\{P(Y_i=1)\}=a+b\operatorname{logit}(\hat p_i)\); ideal values are \(a=0\) and \(b=1\). A slope below one often indicates that predictions are too extreme, while a slope above one indicates insufficient spread, provided the recalibration model is appropriate. These summaries can conceal local deviations, so they complement rather than replace plots and exposure-stratified checks.

Assumptions, Alternatives, and Failure Modes

The diagnostics rely on the outcome and prediction being correctly paired, the event definition being consistent, and the probabilities referring to the same population and prediction target as the observed data. Simple binomial uncertainty calculations further assume independent Bernoulli outcomes with the stated probabilities. For repeated observations, clustered data, or predictions estimated from the same data used to assess them, uncertainty needs to reflect dependence and model fitting. An external validation sample or resampling that repeats the full fitting process can help assess performance beyond the development data.

Calibration plots and residuals answer different questions from other model checks. A discrimination measure summarizes ranking ability, not whether a predicted 0.30 risk occurs about 30% of the time. A Brier score, the mean squared difference between \(Y_i\) and \(\hat p_i\), summarizes probabilistic prediction error but combines calibration and discrimination and does not reveal where misfit occurs. Likelihood-based comparisons assess relative fit among specified models; they do not by themselves show that absolute risks are calibrated. No single metric replaces inspection of the predictions and their context.

A grouped goodness-of-fit test can reduce a complex diagnostic to one statistic, but its result depends on the grouping and sample size. A non-significant result does not demonstrate calibration, and a small departure can be statistically detectable in a large sample without being clinically important. Conversely, sparse events can make plots and formal tests uninformative. Avoid treating arbitrary bins, a single influential residual, or a single p-value as a complete assessment.

  • Pitfall: treating a point off the diagonal as proof of miscalibration. Observed risks vary by chance. Compare the discrepancy with its uncertainty and look for coherent patterns.
  • Pitfall: declaring the model adequate because a grouped test is not significant. The test may have low power, and grouping can hide local errors. Examine the curve, residual patterns, and clinically relevant exposure strata.
  • Pitfall: checking only overall calibration. Average overprediction at low exposure and underprediction at high exposure can cancel. Stratify or plot against exposure and other important covariates.
  • Pitfall: using in-sample agreement as evidence of predictive performance. Fitted predictions can look optimistic. Assess predictions on data not used for fitting or use an appropriate resampling procedure.

The practical goal is not to make every observed proportion equal its prediction. It is to identify whether discrepancies are larger or more systematic than expected, whether they occur where decisions depend on accurate risk, and whether the model’s prediction target and data structure justify the uncertainty calculation.

Check Your Understanding

Answer each question, then compare your reasoning with the brief solutions.

  1. A group has 80 independent observations, mean predicted risk 0.25, and 24 events. What are its observed risk and observed-minus-predicted difference?
  2. For a non-event with predicted risk 0.90, is the raw residual positive or negative? What does its sign mean?
  3. A calibration plot follows the diagonal overall but shows overprediction at low exposure and underprediction at high exposure. Why is the overall plot insufficient?
  4. What are the ideal calibration intercept and slope in logistic recalibration, and what does a slope below one commonly suggest?
  5. Why can a non-significant grouped goodness-of-fit test not establish that a model is calibrated?

Solutions. (1) The observed risk is \(24/80=0.30\); its difference from the predicted risk is \(0.30-0.25=0.05\), or 5 percentage points. (2) The raw residual is \(0-0.90=-0.90\), so the outcome was less than predicted for that observation. (3) Opposing exposure-specific errors can cancel in an aggregate summary; inspect the strata or plot against exposure. (4) The ideal intercept is 0 and the ideal slope is 1. A slope below one commonly indicates predictions that are too extreme, subject to the recalibration model being suitable. (5) The test may have low power, and its result depends on grouping; failure to detect a departure is not proof of calibration.

Clinical Biostats