Why Deviance Residuals Are Signed
A generalized linear model (GLM) gives a fitted mean for each observation. A residual diagnostic should show not only how far the observation departs from that fit, but also whether the observed response is above or below it. A deviance residual does both: its magnitude is the square root of that observation’s deviance contribution, and its sign records the direction of the departure.
The formulas depend on the response distribution. This tutorial derives and applies them for ordinary binomial and Poisson GLMs, with dispersion fixed at 1. The response is assumed to follow the stated distribution conditional on the model predictors; fitted means or probabilities come from the fitted GLM. These residuals summarize model-data disagreement, but their signs and magnitudes alone do not establish that a model is wrong or that a case is statistically unusual.
The square root preserves the nonnegative deviance contribution as a magnitude, while the sign supplies information lost by squaring. A positive residual means the observed response exceeds its fitted mean; a negative residual means it falls below. If the observed response equals the fitted mean, the contribution and residual are both zero.
From Likelihood Contributions to Residuals
For each observation, the deviance contribution compares the likelihood at the fitted model with the likelihood at a saturated model. The saturated model fits that observation exactly, while retaining the same response distribution and observation structure. Deviance is twice the log-likelihood advantage of the saturated fit. For independent observations, the total deviance is the sum of the observation-level contributions.
Use the binomial likelihood for a number of successes in a fixed number of trials, or the Poisson likelihood for a count.
For the saturated likelihood, use the observation-specific fitted value that matches the observed response.
Take twice the log-likelihood difference. Use the standard boundary convention \(0\log(0)=0\).
Take the square root of the contribution and give it the sign of observed minus fitted response.
The sign convention is important: residuals are positive when the observed response is larger than predicted, not when the fitted value is larger than observed.
Binomial Deviance Residuals
Suppose observation \(i\) records \(y_i\) successes in \(m_i\) trials, with \(0\leq y_i\leq m_i\). Under the fitted binomial model, \(Y_i\sim\operatorname{Binomial}(m_i,\hat{p}_i)\), where \(0<\hat{p}_i<1\). Its fitted success count is \(\hat{\mu}_i=m_i\hat{p}_i\). The observation-level deviance contribution and signed deviance residual are
A term with zero numerator is defined as zero by the limit \(x\log(x/c)\to 0\) as \(x\to0^+\), for fixed \(c>0\). This convention handles observations with no successes or with all successes. If the response is recorded as a proportion \(y_i/m_i\), the same formula applies using the trial count \(m_i\); the proportion alone does not identify the binomial likelihood without its denominator.
Worked Example: A Grouped Binomial Observation
A hypothetical screening program records 8 positive outcomes among 10 independent participants in one group. A fitted binomial GLM assigns each participant in that group a positive-outcome probability of \(\hat{p}=0.60\). Calculate the observation’s deviance contribution and deviance residual. The response distribution is \(\operatorname{Binomial}(10,0.60)\) under the fitted model. No interest rate or mortality assumption is involved.
Step 1: Find the fitted success count. Here \(m=10\), \(y=8\), and \(\hat{\mu}=m\hat{p}=10(0.60)=6\). Since \(8>6\), the residual sign must be positive.
Step 2: Calculate the contribution. Using natural logarithms, \(y/(m\hat{p})=8/6=4/3\), and \((m-y)/(m(1-\hat{p}))=2/4=1/2\). Thus
Step 3: Take the signed square root. The square root is \(\sqrt{1.830324}\approx1.353\). The sign is positive, so the deviance residual is approximately \(+1.353\).
Check. The contribution is nonnegative, and the sign agrees with 8 observed successes versus 6 fitted successes. The calculation avoids a common error: taking the sign from \(y-\hat{p}\) instead of \(y-m\hat{p}\). Here that mistake is especially clear because the count and probability are on different scales.
Poisson Deviance Residuals
Suppose the response \(Y_i\) is a count and, conditional on its predictors, \(Y_i\sim\operatorname{Poisson}(\hat{\mu}_i)\) under the fitted model, with \(\hat{\mu}_i>0\). The Poisson deviance contribution and residual are
When \(y_i=0\), the logarithmic term is defined as zero, giving \(d_i=2\hat{\mu}_i\). In that case the residual is negative because zero observed events are below the positive fitted mean. A positive count can also give a negative residual whenever it is less than the fitted mean; the sign is determined by the comparison, not by whether the count is zero.
Worked Example: Zero and Positive Poisson Counts
A hypothetical monitoring system models event counts for two independent locations using Poisson GLMs. The first location has observed count \(y_1=0\) and fitted mean \(\hat{\mu}_1=2\); the second has \(y_2=5\) and \(\hat{\mu}_2=3\). Calculate both contributions and residuals. The fitted distributions are \(Y_1\sim\operatorname{Poisson}(2)\) and \(Y_2\sim\operatorname{Poisson}(3)\). No interest rate or mortality assumption is involved.
Location 1. Since \(y_1=0\), the logarithmic term is zero. Therefore \(d_1=2(2)=4\), and \(\sqrt{d_1}=2\). Because \(0<2\), \(r_{D,1}=-2\).
Location 2. The count ratio is \(5/3\), and \(5-3=2\). Therefore
The square root is approximately \(1.053\). Since \(5>3\), \(r_{D,2}\approx+1.053\).
Check. The first residual is negative for an observed count below its fitted mean; the second is positive for a count above its mean. Both contributions are nonnegative. At the first location the zero-count convention gives a finite contribution, not an undefined residual.
Why the Formulas Have This Form
The formulas follow by subtracting the fitted log-likelihood from the saturated log-likelihood and multiplying by 2. The following derivation shows the comparison for each distribution. Terms that are constant across the fitted and saturated models cancel.
For \(y\) successes in \(m\) trials, the log-likelihood at probability \(p\) is \(\log {m\choose y}+y\log p+(m-y)\log(1-p)\). The saturated probability is \(p=y/m\), which matches the observed proportion.
The binomial coefficient cancels. Twice the saturated-minus-fitted difference is \(2[y\log(y/(m\hat{p}))+(m-y)\log((m-y)/(m(1-\hat{p})))]\), the stated binomial contribution.
For a count \(y\), the log-likelihood at mean \(\mu\) is \(y\log\mu-\mu-\log(y!)\). The saturated mean is \(\mu=y\); subtracting the fitted log-likelihood cancels \(\log(y!)\) and gives \(2[y\log(y/\hat{\mu})-(y-\hat{\mu})]\).
Each deviance contribution is nonnegative because the saturated likelihood fits at least as well as the constrained fitted model. Taking its square root gives a nonnegative magnitude; multiplying by the sign of observed minus fitted response restores direction without changing the squared value.
For independent observations, summing the squares of these signed residuals recovers residual deviance:
The sign disappears on squaring, so a residual plot or table is needed to see direction. Also, deviance residuals are not automatically standardized residuals: their magnitudes should not be read as exact standard-deviation units or as standard normal scores. Their distribution depends on the response type, fitted mean, sample structure, and model estimation.
Worked Example: Comparing Poisson Residuals at Equal Count Deviations
A hypothetical claim-reporting model gives two independent exposure groups the same fitted count mean, \(\hat{\mu}=4\), under Poisson distributions. One group reports \(y_1=2\) events and the other \(y_2=6\). Compare their deviance residuals. Both fitted response distributions are \(\operatorname{Poisson}(4)\). No interest rate or mortality assumption is involved.
Group 1. The observed count is two below the fitted mean, so the sign is negative. Its contribution is
Thus \(r_{D,1}=-\sqrt{1.227412}\approx-1.108\).
Group 2. The observed count is two above the fitted mean, so the sign is positive. Its contribution is
Thus \(r_{D,2}=+\sqrt{0.865581}\approx+0.930\).
Check and interpretation. The counts are equally far from 4 on the raw count scale, but their deviance residual magnitudes differ. The Poisson deviance is asymmetric around its mean; equal raw differences need not produce equal deviance contributions. The signs correctly distinguish a lower-than-fitted count from a higher-than-fitted count.
Interpretation and Common Traps
A deviance residual is an observation-level measure of discrepancy on a likelihood scale. Its sign is directly interpretable relative to the fitted response: positive means more successes or events than fitted, and negative means fewer. Its magnitude reflects how poorly the fitted distribution accounts for that observation compared with an exact fit. Because the contribution is distribution-specific, residuals from different response families should not be compared as if they were on a common standardized scale.
For binomial observations, compare successes with fitted successes \(m_i\hat{p}_i\), not with the probability \(\hat{p}_i\). For Poisson observations, compare the count with its fitted mean. In either case, do not put an absolute value inside the deviance formula: the likelihood comparison already produces a nonnegative contribution, while the separate sign supplies the direction.
- Wrong sign: using \(\operatorname{sign}(\hat{\mu}_i-y_i)\) reverses the interpretation. Use observed minus fitted.
- Wrong binomial scale: for grouped data, \(y_i\) is a count, so the fitted comparison is \(m_i\hat{p}_i\), not \(\hat{p}_i\).
- Wrong boundary calculation: when \(y_i=0\), treat \(y_i\log(y_i/\hat{\mu}_i)\) as zero. Do not take the logarithm of zero as an ordinary numeric operation.
- Overinterpreting magnitude: a deviance residual is not automatically a standardized residual or a p-value. Use the model context and appropriate diagnostics before drawing conclusions.
Check Your Understanding
For each problem, calculate the deviance residual using the stated fitted distribution, then check the direction and magnitude.
- A hypothetical grouped binomial observation has \(m=12\) trials, \(y=9\) successes, and fitted probability \(\hat{p}=0.50\). Find its signed deviance residual. (Answer: \(+1.7719\))
- A hypothetical binomial model has \(m=8\), \(y=0\), and fitted probability \(\hat{p}=0.25\). Find the deviance contribution and signed residual. (Answer: \(d=4.6029,\ r_D=-2.1454\))
- A hypothetical Poisson count is \(y=4\) with fitted mean \(\hat{\mu}=2\). Find its signed deviance residual. (Answer: \(+1.2431\))
- A hypothetical Poisson model predicts a mean of \(\hat{\mu}=1.5\) for a case with observed count \(y=0\). Find the deviance contribution and residual, using the zero-count convention. (Answer: \(d=3.0000,\ r_D=-1.7321\))