Tutorials › Population Pharmacokinetics › Binned Residual Trends And Smooth Diagnostic Curves

Diagnostics: Goodness of Fit and Shrinkage · Tutorial 346 of 599

Binned Residual Trends And Smooth Diagnostic Curves

Build and interpret binned residual summaries and smooth curves while accounting for their uncertainty, dependence, and limitations.

Intermediate 12 min read

What You'll Learn

  • Construct equal-width and equal-count bins for residual-versus-covariate plots.
  • Calculate binned means and standard errors, and recognize when observations are not independent.
  • Explain how local smoothing weights nearby residuals and how span choices affect a curve.
  • Identify boundary effects and distinguish a descriptive trend from evidence of model misspecification.
  • Compare binned summaries, smooth curves, and unsmoothed residual plots.

Why Summarize Residual Trends?

A residual-versus-covariate plot can reveal whether model discrepancies vary with a continuous predictor such as body weight, age, or renal function. But when many observations are plotted, a broad pattern can be difficult to distinguish from point-to-point noise. Binned summaries and smooth curves make the overall pattern easier to see. They are aids to visual diagnosis, not replacements for the underlying observations or automatic tests of model adequacy.

The earlier material on residuals and continuous covariates establishes the basic question: do residuals show a systematic pattern across the covariate range? Here the emphasis is on how to summarize that pattern without hiding sparse regions, overstating certainty, or turning random fluctuation into an apparent trend.

Definition: A binned residual summary groups observations by covariate value and calculates a summary, commonly the mean residual, within each group. A smooth diagnostic curve estimates the local residual trend across the covariate range by giving nearby observations more influence than distant ones. Both are descriptive summaries of a residual-versus-covariate plot.

Let \(x_{ij}\) be a covariate value and \(r_{ij}\) the chosen residual for observation \(j\) in subject \(i\). The residual might be a weighted residual, but the same plotting ideas apply to other residual definitions. The covariate and residual scales must be stated clearly: for example, renal function in mL/min and conditional weighted residuals without physical units.

Constructing Binned Summaries

To create bins, divide the observed range of \(x\) into intervals, assign each observation to one interval, and calculate a residual summary for each interval. Two common choices are equal-width bins, which use intervals of the same covariate width, and equal-count bins, which aim to put similar numbers of observations in each bin. Equal-width bins make the horizontal scale straightforward to interpret, but can be nearly empty where data are sparse. Equal-count bins help keep summaries from being based on very different sample sizes, but their widths can vary considerably.

A bin summary often uses the arithmetic mean. For bin \(b\), containing \(n_b\) residuals, its mean and the usual observation-level standard error are:

$$ \bar{r}_b=\frac{1}{n_b}\sum_{k=1}^{n_b}r_{bk}, \qquad SE(\bar{r}_b)=\frac{s_b}{\sqrt{n_b}} $$

Here \(s_b\) is the sample standard deviation of the residuals in the bin. The standard error formula assumes independent observations with a common mean and finite variance within the bin. In population pharmacokinetic data, several observations may come from one subject. Those residuals may be correlated, so treating every observation as independent can make the standard error too small. Subject-level resampling or a variance calculation that accounts for clustering is more appropriate when repeated observations contribute to a bin.

A bin mean near zero is not proof that the model is correct; positive and negative residuals can cancel. Conversely, a single nonzero bin mean may reflect random variation, especially in a small bin. Plot the number of observations or subjects in each bin, and retain the underlying points where possible. Bin boundaries also matter: moving a boundary can shift observations between bins and change the summary.

Worked Example: Calculating Equal-Count Bin Means

In a hypothetical diagnostic data set, ten observations have renal-function values \(x\) in mL/min and corresponding weighted residuals \(r\). For a compact illustration, sort the observations by \(x\) and form three consecutive bins, with the first two containing three observations and the last containing four.

$$ \begin{array}{c|rrrrrrrrrr} x\ (\mathrm{mL/min})&40&45&49&50&55&59&60&65&70&75\\ r&-0.8&-0.4&-0.2&0.1&0.2&0.4&0.5&0.6&0.7&0.8 \end{array} $$

The first bin has mean residual \((-0.8-0.4-0.2)/3=-1.4/3=-0.467\). The second has mean \((0.1+0.2+0.4)/3=0.7/3=0.233\). The third has mean \((0.5+0.6+0.7+0.8)/4=2.6/4=0.650\). The summaries rise across the observed covariate range, which is a pattern worth examining in the point plot and in model context. It is not, by itself, evidence that renal function caused the residual pattern or that a particular model change is required.

These are equal-count bins, not equal-width bins: the first covers 40–49 mL/min and the final covers 60–75 mL/min. Reporting the bin limits and counts is therefore essential. The construction also shows a limitation: the edge bins summarize different covariate spans, so their means should not be interpreted as estimates at a single exact \(x\) value.

Uncertainty and Repeated Observations

A standard error describes variability in an estimated mean under its sampling assumptions; it does not account for every source of uncertainty in a model-based diagnostic. For independent observations in a bin, an approximate interval can be formed as \(\bar{r}_b\pm t_{1-\alpha/2,df}SE(\bar{r}_b)\), with \(df=n_b-1\) under the usual single-sample \(t\) assumptions. If residuals are dependent within subject, this interval is not justified simply because there are many observations. The independent information may be closer to the number of subjects than to the number of measurements.

A practical alternative for clustered data is to resample subjects, keeping all of each selected subject’s observations together, and recompute the bin summaries. The resulting bootstrap distribution can represent between-subject sampling variation more realistically, provided the subjects are representative and the number of subjects is sufficient. It does not remove bias in the residual definition or fix a poorly chosen binning scheme.

Worked Example: An Interval for an Independent Bin

Suppose a hypothetical bin contains one residual from each of five independent subjects: \(-0.6,-0.2,0.0,0.2,0.6\). Assume the residuals are sampled independently from a population with an approximately normal distribution and a common mean and variance. The sample mean is \(0\), and the sum of squared deviations is \(0.36+0.04+0+0.04+0.36=0.80\).

The sample standard deviation is \(s=\sqrt{0.80/(5-1)}=\sqrt{0.20}=0.447\), and \(SE=s/\sqrt{5}=0.447/2.236=0.200\). With \(df=4\), the two-sided 95% \(t\) critical value is approximately 2.776. Thus the interval is:

$$ 0\pm 2.776(0.200)=(-0.555,\ 0.555) $$

Under the stated sampling assumptions, this interval procedure has 95% coverage for the bin’s population mean residual over repeated samples. This particular interval includes zero and is wide relative to a small residual trend; it does not establish that the true mean is exactly zero. The calculation is not suitable if the five values are correlated measurements from fewer than five subjects.

How Local Smoothing Works

A smooth curve avoids the abrupt jumps created by bins. At a target covariate value \(x_0\), a local smoother gives greater weight to observations close to \(x_0\). A simple local-constant estimate is a weighted average:

$$ \hat{m}(x_0)= \frac{\sum_{i,j}w_{ij}(x_0)r_{ij}} {\sum_{i,j}w_{ij}(x_0)} $$

The weights \(w_{ij}(x_0)\) are nonnegative and decrease with distance from \(x_0\); observations outside a chosen neighborhood may receive zero weight. A local-linear smoother instead fits a weighted straight line near \(x_0\) and evaluates that line at \(x_0\). Local-linear fitting often reduces boundary bias compared with a local-constant weighted average, though it can be unstable when very few distinct covariate values lie nearby.

The span or bandwidth controls the neighborhood size. A small span follows local variation closely, including noise; a large span is steadier but can flatten or conceal real structure. The curve is therefore conditional on a smoothing choice. A useful diagnostic practice is to compare a small number of reasonable spans and inspect whether the broad interpretation is stable, rather than searching many settings until one produces a preferred pattern.

Worked Example: A Local Weighted Average Near the Center

Consider four hypothetical residuals at covariate values \(x=-1,0,1,2\): \(-0.4,0.1,0.5,0.9\). Estimate the smooth value at \(x_0=0\) using a triangular weight that is \(1-|x-x_0|/2\) when \(|x-x_0|<2\), and zero otherwise. The weights are \(0.5,1,0.5,0\).

The weighted average is:

$$ \hat{m}(0)= \frac{0.5(-0.4)+1(0.1)+0.5(0.5)+0(0.9)} {0.5+1+0.5+0} =\frac{-0.20+0.10+0.25}{2}=0.075 $$

This is a local-constant estimate, not a new observed residual. At \(x_0=-1\), the same rule uses weights \(1,0.5,0,0\), giving \([1(-0.4)+0.5(0.1)]/1.5=-0.233\). Near that boundary, available observations lie mostly to the right; the neighborhood is asymmetric. This example illustrates why edge behavior can differ from the center and why a smooth curve should not be treated as equally reliable everywhere.

Boundary Effects, Diagnostics, and Alternatives

At the edges of the covariate range, a smoother cannot draw on observations from both sides of the target value. Local-constant smoothing can then be pulled toward the interior values, particularly when the true trend changes rapidly. Local-linear smoothing can reduce this bias, but it does not create information beyond the observed range. Do not extrapolate the curve past the data or interpret a sharp edge bend without checking how many observations and subjects support it.

Binned means and smooth curves answer related but different visual questions. Bins are transparent: the values contributing to each point can be listed and counted, but the result depends on boundaries and may look jagged. A smoother presents a continuous trend and avoids abrupt bin transitions, but depends on its weights and span. The raw scatter shows individual observations and heterogeneity, but can be visually crowded. These approaches are complementary; none is a substitute for the others.

DisplayMain strengthMain caution
Raw residual scatterShows spread, clusters, and unusual observationsDense points can obscure an overall trend
Binned meansEasy to summarize and auditDepends on bin boundaries and counts
Locally smoothed curveShows a continuous, flexible trendDepends on span, method, and edge support

Potential warning signs include a curve that changes substantially with a modest span adjustment, bins with very few subjects, a trend driven by a small number of points, or a curve that appears different only at a sparsely observed boundary. Check the data density and subject representation along the covariate axis. For repeated measurements, consider whether a pattern is mostly between subjects or within subjects; a pooled curve can combine those sources of variation.

Most importantly, a visible nonzero trend is a prompt for investigation, not a causal conclusion or a formal rejection by itself. Consider the residual type, sampling design, covariate distribution, model structure, and other diagnostics before deciding what the pattern means. A flat curve also has limits: averaging can hide opposing subgroup trends or local features that the chosen span smooths away.

Common Mistakes

  • Reading a binned mean as a residual at one exact covariate value. It averages every observation in an interval. State the interval and its count.
  • Using an observation-level standard error for clustered data. Repeated measures from one subject are not automatically independent. Use subject-aware uncertainty methods where needed.
  • Treating a smooth curve as an objective truth. Its shape depends on bandwidth and smoother type. Check a small set of defensible choices and retain the scatter.
  • Overreading edge curvature. Boundary neighborhoods are asymmetric and sparse. Do not infer behavior outside the observed range.
  • Calling a nonzero trend proof of a particular mechanism. A diagnostic pattern can motivate investigation, but does not identify its cause on its own.
Key takeaway: Use bins to make residual averages auditable and smooth curves to reveal broad local structure. Interpret either alongside the raw points, data density, subject clustering, and sensitivity to analytical choices.

Check Your Understanding

Answer these questions, then compare your reasoning with the solutions below.

  1. When might equal-count bins be preferable to equal-width bins, and what limitation should still be reported?
  2. Four independent residuals in a bin are \(-0.3,-0.1,0.1,0.3\). Calculate the bin mean, sample standard deviation, and standard error.
  3. Why can an observation-level standard error be misleading when a bin contains repeated observations from the same subjects?
  4. What happens to a local smoother’s support near the covariate boundary, and what does that imply for interpretation?
  5. Why should a curve that changes under a modest span adjustment be interpreted cautiously?

Solutions. (1) Equal-count bins can avoid summaries based on highly unequal numbers of observations, especially when the covariate distribution is uneven. Their widths may differ substantially, so report the actual intervals and counts. (2) The mean is \((-0.3-0.1+0.1+0.3)/4=0\). The squared deviations sum to \(0.09+0.01+0.01+0.09=0.20\), so \(s=\sqrt{0.20/3}=0.258\) and \(SE=0.258/\sqrt{4}=0.129\). (3) Within-subject correlation reduces the independent information relative to the observation count, so the naive standard error may be too small. (4) Observations are available mainly on the interior side, creating an asymmetric neighborhood and potentially greater bias; avoid extrapolating or overinterpreting edge curvature. (5) The apparent pattern may depend more on the smoothing choice than on a stable feature of the data, so compare the curve with the raw scatter, bin summaries, and covariate density.

Clinical Biostats