Tutorials › Generalized Linear Models › Residual Plots Against Fitted Means

Residuals and Deviance · Tutorial 753 of 981

Residual Plots Against Fitted Means

Compare residual plots against fitted means to identify patterns that may signal a poor mean or variance description, while recognizing what the plots cannot establish.

Intermediate 10 min read

What You'll Learn

  • Read response, Pearson, deviance, and randomized quantile residuals against fitted means
  • Distinguish systematic residual trends from the changing spread expected across GLM families
  • Use worked binomial and Poisson calculations to compare residual scales
  • Recognize curvature and isolated response discrepancies without treating them as proof of a particular cause
  • Explain why fitting and discrete outcomes complicate ideal residual reference behavior

Why Plot Residuals Against Fitted Means?

A generalized linear model describes a response distribution whose mean depends on predictors. A plot of residuals against fitted means asks whether the observed responses depart from that description in a systematic way across the range of fitted response levels. It is a compact diagnostic: a trend or curve can suggest that the mean structure is inadequate, while a widening band may reflect the variance structure—or a mismatch in it.

For observation \(i\), let \(Y_i\) be the response, \(\hat{\mu}_i\) its fitted mean, and \(\hat{y}_i\) its observed value. The horizontal coordinate in these plots is \(\hat{\mu}_i\); the vertical coordinate is a chosen residual. A horizontal reference at zero is useful for residuals centered at zero. A smooth curve can help reveal broad structure, but it is a visual summary, not a formal test.

Definition: A residual-versus-fitted-mean plot displays a residual for each observation on the vertical axis and the corresponding fitted mean \(\hat{\mu}_i\) on the horizontal axis. Common vertical coordinates are the response residual \(e_i=Y_i-\hat{\mu}_i\), the Pearson residual \(r_{Pi}=(Y_i-\hat{\mu}_i)/\sqrt{\hat{\phi}V(\hat{\mu}_i)}\), the signed deviance residual \(r_{Di}\), and the randomized quantile residual \(r_{Qi}\). Here \(V(\mu)\) is the GLM variance function and \(\hat{\phi}\) is the fitted dispersion when dispersion scaling is used.

The plots answer related but different questions. Response residuals remain in the response’s original units. Pearson residuals divide by a variance-based scale, and deviance residuals express each observation’s contribution relative to the fitted likelihood. Randomized quantile residuals transform the fitted response distribution to a normal scale, with randomization needed for discrete responses. None should be read as if the residuals were independent, identically distributed errors: fitted parameters have been estimated from the same data.

What Patterns Mean

Under a correctly specified mean model, residuals should not show a strong, systematic change in their center across fitted means. A smooth that rises or falls through the zero line, or a curved pattern, signals that the fitted means may be systematically too low in some range and too high in another. This is a reason to investigate the mean specification; the plot alone does not identify the cause.

The vertical spread needs more careful interpretation. For a GLM response with conditional mean \(\mu_i\), the variance is \(\operatorname{Var}(Y_i\mid x_i)=\phi V(\mu_i)\). Consequently, response residuals can naturally have different spreads at different means. Pearson residuals divide by an estimate of that changing standard deviation, so under known parameters their variance is one. This makes Pearson plots useful for seeing whether spread remains after variance standardization, though estimation and finite samples prevent an exact unit-variance guarantee for fitted residuals.

Result: If the model parameters are fixed at their true values and \(\operatorname{Var}(Y_i\mid x_i)=\phi V(\mu_i)\), then \(E[Y_i-\mu_i\mid x_i]=0\) and \(\operatorname{Var}(Y_i-\mu_i\mid x_i)=\phi V(\mu_i)\). Therefore the Pearson-scaled residual \((Y_i-\mu_i)/\sqrt{\phi V(\mu_i)}\) has conditional mean zero and variance one.

To verify this, subtract the nonrandom conditional mean from \(Y_i\). Linearity of expectation gives \(E[Y_i-\mu_i\mid x_i]=E[Y_i\mid x_i]-\mu_i=0\). Subtracting a constant does not change variance, so \(\operatorname{Var}(Y_i-\mu_i\mid x_i)=\operatorname{Var}(Y_i\mid x_i)=\phi V(\mu_i)\). Dividing by the fixed positive standard deviation gives variance one. For fitted residuals, \(\hat{\mu}_i\) and often \(\hat{\phi}\) are estimated, so this calculation is a reference rather than an exact statement about their joint distribution. \(\square\)

Worked Example: A Trend in Grouped Binomial Residuals

Suppose five groups each contain \(n_i=10\) trials. Their fitted success probabilities are \(0.1,0.3,0.5,0.7,0.9\), and the observed success counts are \(0,2,5,8,10\). Calculate the response and Pearson residuals, then describe the pattern against fitted probability.

For grouped binomial data, the fitted mean count is \(n_i\hat{p}_i\). The fitted counts are therefore \(1,3,5,7,9\), giving response residuals \(y_i-n_i\hat{p}_i=-1,-1,0,1,1\). Equivalently, on the proportion scale, the observed proportions are \(0,0.2,0.5,0.8,1\); subtracting the fitted probabilities gives \(-0.1,-0.1,0,0.1,0.1\).

The binomial variance of a count is \(n_i\hat{p}_i(1-\hat{p}_i)\). The Pearson residuals are thus \( -1/\sqrt{0.9}\approx-1.054\), \( -1/\sqrt{2.1}\approx-0.690\), \(0/\sqrt{2.5}=0\), \(1/\sqrt{2.1}\approx0.690\), and \(1/\sqrt{0.9}\approx1.054\).

Both versions move from negative residuals at lower fitted probabilities, through zero, to positive residuals at higher fitted probabilities. This is an increasing pattern, not a U-shaped pattern. It suggests the fitted probabilities may be systematically low at the high end and high at the low end. These five points alone do not establish why: the plot is a diagnostic signal to investigate, not a proof of a specific model defect.

Comparing Scales and Reading Spread

For a Poisson response, \(V(\mu)=\mu\) and \(\phi=1\). The response residual’s standard deviation therefore grows as \(\sqrt{\mu}\), whereas the Pearson residual divides by \(\sqrt{\hat{\mu}}\). The signed Poisson deviance residual is \( \operatorname{sign}(y-\hat{\mu})\sqrt{2\{y\log(y/\hat{\mu})-(y-\hat{\mu})\}}\), with \(y\log(y/\hat{\mu})\) taken as zero when \(y=0\). Near the fitted mean, deviance residuals are approximately on the Pearson scale; farther away, their transformation differs.

Result: For a regular model with a smooth variance function \(V(\mu)>0\), the unit deviance near \(y=\mu\) has leading term \((y-\mu)^2/V(\mu)\). Thus the signed deviance residual is locally approximately \((y-\mu)/\sqrt{V(\mu)}\), with dispersion scaling handled separately when appropriate.

The approximation follows by expanding the log-likelihood around its maximum at the mean parameter \(\mu=y\). The first derivative of the log-likelihood with respect to its mean parameter is zero there, and its second derivative, evaluated at the saturated mean \(\mu=y\), is \(-1/(\phi V(y))\) for an exponential-dispersion model. Taylor expansion gives the log-likelihood difference between the saturated mean \(y\) and a nearby mean \(\mu\) as \((y-\mu)^2/(2\phi V(y))\) to second order. Deviance is twice that difference, so its leading term is \((y-\mu)^2/(\phi V(y))\), equivalently \((y-\mu)^2/(\phi V(\mu))\) to leading order as \(\mu\to y\). Taking the signed square root gives the stated local scale, with the factor \(\phi\) included in the residual denominator when dispersion-standardized deviance residuals are used. The approximation is local; it does not claim equality for large discrepancies. \(\square\)

Worked Example: Poisson Residuals Across Fitted Means

Consider four Poisson observations with fitted means \(1,2,4,8\) and observed counts \(0,1,6,12\). Compute the response, Pearson, and signed deviance residuals to see how their scales compare.

The response residuals \(y-\hat{\mu}\) are \(-1,-1,2,4\). The Pearson residuals divide these by \(\sqrt{\hat{\mu}}\), giving \(-1,-1/\sqrt{2}\approx-0.707,2/\sqrt{4}=1\), and \(4/\sqrt{8}\approx1.414\).

For the first observation, \(y=0,\hat{\mu}=1\), so the deviance residual is \(-\sqrt{2(1)}\approx-1.414\). For \(y=1,\hat{\mu}=2\), it is \(-\sqrt{2\{1\log(1/2)-(1-2)\}}=-\sqrt{2(0.3069)}\approx-0.783\). For \(y=6,\hat{\mu}=4\), it is \(\sqrt{2\{6\log(6/4)-(6-4)\}}=\sqrt{2(0.4328)}\approx0.930\). For \(y=12,\hat{\mu}=8\), it is \(\sqrt{2\{12\log(12/8)-(12-8)\}}=\sqrt{2(0.8656)}\approx1.316\).

The response residuals grow in magnitude across these observations, but this alone does not show that the model’s spread is wrong: the Poisson variance itself grows with the mean. The Pearson and deviance residuals account for that changing variance scale. With only four observations, the values do not support a stable assessment of spread; the calculation illustrates why the vertical scale and the family’s variance matter when reading a plot.

Randomized Quantile Residuals and Isolated Discrepancies

For a continuous fitted response distribution with cumulative distribution function \(F_i\), the quantile residual is \(\Phi^{-1}(F_i(Y_i))\), where \(\Phi\) is the standard normal cumulative distribution function. For a discrete response, \(F_i(Y_i)\) has jumps and is not uniform even when the fitted distribution is correct. Randomized quantile residuals address this by drawing \(U_i\) uniformly between \(F_i(Y_i^-)\) and \(F_i(Y_i)\), then setting \(r_{Qi}=\Phi^{-1}(U_i)\).

Result: If the response has a known, correctly specified discrete distribution, the randomized probability integral transform \(U=F(Y^-)+W\{F(Y)-F(Y^-)\}\), with \(W\sim\operatorname{Uniform}(0,1)\) independent of \(Y\), is uniform on \((0,1)\). Consequently, \(\Phi^{-1}(U)\) has a standard normal distribution.

To see this, list the possible response values in order. Each value \(y\) occurs with probability \(F(y)-F(y^-)\), exactly the length of the interval assigned to it. Conditional on \(Y=y\), independent uniform \(W\) makes \(U\) uniform on that interval. These intervals partition \((0,1)\), apart from endpoints of probability zero. For any subinterval \(A\subset(0,1)\), the probability that \(U\in A\) is the sum, over the partition intervals, of the length of \(A\)'s intersection with each interval; this sum is the length of \(A\). Hence \(U\) is uniform. Applying the inverse standard normal distribution function gives a standard normal variable. With estimated parameters, this is an ideal reference, not an exact finite-sample guarantee. \(\square\)

Worked Example: One Large Poisson Discrepancy

Five observations have fitted Poisson mean \(5\). Their observed counts are \(4,5,6,4,15\). Calculate the residuals for the count of 15 and compare it with the others.

The response residuals are \(-1,0,1,-1,10\). At \(y=15\), the Pearson residual is \(10/\sqrt{5}\approx4.472\). Its signed deviance residual is \(\sqrt{2\{15\log(15/5)-(15-5)\}}=\sqrt{2\{15\log 3-10\}}\). Since \(\log 3\approx1.098612\), the quantity inside the outer square root is \(2(16.4792-10)\approx12.9582\), giving a deviance residual of approximately \(3.600\).

The count of 15 is separated from the other four on each of these scales, so it is an isolated response discrepancy relative to the fitted mean. That is a reason to check the observation and model description, not grounds by itself for deleting the case. A residual plot locates a response departure; it does not establish its cause.

Worked Example: Randomization for a Bernoulli Observation

For a Bernoulli response with fitted success probability \(0.2\), suppose the observed outcome is \(1\). Then \(F(1^-)=P(Y=0)=0.8\) and \(F(1)=1\), so the randomized probability lies uniformly between \(0.8\) and \(1\). If the recorded random draw gives \(U=0.9\), the residual is \(\Phi^{-1}(0.9)\approx1.282\).

A different allowed random draw would give a different residual for this same outcome. This is part of the definition, not a calculation error. In a residual-versus-fitted-mean plot, randomized quantile residuals can make discrete outcomes easier to compare on a common scale, but their random variation should be kept in mind when inspecting individual points.

Common Mistakes and Practical Reading

  • Calling every change in response-residual spread a variance failure. Response residuals inherit the family’s mean-dependent variance. Compare with Pearson or deviance residuals and the variance function before diagnosing a problem.
  • Describing the shape inaccurately. A sequence that rises from negative to positive is an increasing trend; it is not U-shaped. Describe what the plotted values actually do.
  • Treating a large residual as proof of a bad observation. It identifies a surprising response relative to its fitted mean, but does not distinguish data error, random variation, or model inadequacy.
  • Expecting fitted residuals to be exactly independent and standardized. The fitted means were estimated from the responses, so the ideal reference behavior under known parameters is only a guide to interpretation.
  • Overinterpreting a smooth line. A smooth can expose broad curvature, but it depends on the data and smoothing choices. Look at the points, scale, and sample size as well.

A useful reading sequence is to inspect the residual center across fitted means, then assess spread on a scale appropriate to the response family, and finally note any isolated large departures. Agreement across residual types strengthens a visual concern; disagreement can reveal that the apparent feature is mainly a consequence of the residual scale. These plots are diagnostic tools, not automatic model-selection rules.

Check Your Understanding

Use the definitions and calculations above to answer the following questions.

  1. Why can response residuals have wider spread at larger fitted means in a Poisson GLM even when its variance specification is appropriate?
  2. For a grouped binomial response, what denominator is used to form a Pearson residual for a success count?
  3. A residual sequence moves from negative values through zero to positive values as fitted means increase. What shape description is accurate, and what might the pattern suggest?
  4. Why does the randomized probability integral transform need an extra random draw for a discrete response?
  5. What can an isolated large residual establish, and what can it not establish on its own?
Clinical Biostats