Author-reviewedEvidence: highv1.0.2

Deviance Residual

A deviance residual is a signed measure of how poorly a generalised linear or survival model fits each patient; in a GLM its squares sum to the deviance.

Download concept guide
Last reviewed byDr Darrin Baines

Concept Architecture

Deviance Residual in Cost Regressions and Survival Curves

Economic evaluations built on patient-level data lean on two kinds of fitted model, namely survival curves fitted to trial data and extrapolated beyond follow-up, and regressions of costs or resource use. In both, the deviance residual is the usual tool for finding the patients a model describes worst before its estimates feed a cost-effectiveness model. One version is used for generalised linear models and another, a rescaled martingale residual, for survival models, and the two rest on the same idea. Two illustrative examples are worked by hand.

Unit deviances and the deviance residual in a generalised linear model

A generalised linear model (GLM) is fitted by maximum likelihood, and its lack of fit is summarised by the deviance, which compares the fitted model with a saturated model that fits every observation exactly. For the Poisson family, whose dispersion is fixed at 1, the deviance is twice the gap in log-likelihood between the two; for families with an estimated dispersion, such as the gamma, twice that gap equals the deviance divided by the dispersion. The deviance is a sum of one non-negative contribution per observation, the unit deviance, and McCullagh and Nelder, the standard text on GLMs, define the deviance residual from it.

rD,i=sign(yi−μ^i)di,D=∑i=1ndi=∑i=1nrD,i2r_{D,i} = \mathrm{sign}(y_i - \hat{\mu}_i)\sqrt{d_i}, \qquad D = \sum_{i=1}^{n} d_i = \sum_{i=1}^{n} r_{D,i}^2

where rD,ir_{D,i} is the deviance residual for observation ii, yiy_i is the observed outcome, μ^i\hat{\mu}_i is the fitted mean, did_i is the unit deviance of observation ii, DD is the model deviance and nn is the number of observations. Because the squares add up to the deviance, the residuals show which observations contribute most to the lack of fit.

The unit deviance depends on the distribution assumed for the outcome. For the gamma family, used for costs, and the Poisson family, used for counts of resource use, Stata's GLM documentation gives the unit deviances below.

digamma=2{yi−μ^iμ^i−log⁡yiμ^i},diPoisson=2{yilog⁡yiμ^i−(yi−μ^i)}d_i^{\text{gamma}} = 2\left\{\frac{y_i - \hat{\mu}_i}{\hat{\mu}_i} - \log\frac{y_i}{\hat{\mu}_i}\right\}, \qquad d_i^{\text{Poisson}} = 2\left\{y_i \log\frac{y_i}{\hat{\mu}_i} - (y_i - \hat{\mu}_i)\right\}

where log⁡\log is the natural logarithm and the other terms are as defined above; the Poisson term yilog⁡(yi/μ^i)y_i \log(y_i / \hat{\mu}_i) is taken as zero when yi=0y_i = 0, so a zero count contributes di=2μ^id_i = 2\hat{\mu}_i. The gamma unit deviance is undefined for a cost of zero, so zero costs are commonly handled in the first part of a two-part model, with the GLM fitted to positive costs in the second part.

Healthcare costs are positively skewed and often heavy tailed, so raw differences yi−μ^iy_i - \hat{\mu}_i are dominated by a few expensive patients. The Pearson residual divides the difference by the square root of the variance function, giving (yi−μ^i)/μ^i(y_i - \hat{\mu}_i)/\hat{\mu}_i for the gamma family, but Stata's manual notes that Pearson residuals often have markedly skewed distributions for non-normal families. Deviance residuals are approximately normal when the model is correct; McCullagh and Nelder recommend them for checking GLM fit, and R returns them by default.

From the martingale residual to the survival deviance residual

Survival models need a different starting point, because a censored time cannot be compared with a fitted mean. The survival version works on the hazard scale instead. The chain starts with the Cox-Snell residual, the fitted cumulative hazard at each patient's observed time, and the martingale residual is the event indicator minus that value.

Mi=δi−H^(ti∣xi)M_i = \delta_i - \hat{H}(t_i \mid x_i)

where MiM_i is the martingale residual of patient ii, δi\delta_i is 1 if the patient had the event and 0 if censored, tit_i is the observed event or censoring time, xix_i are the patient's covariates and H^\hat{H} is the fitted cumulative hazard. The martingale residual compares observed with expected events, but it cannot exceed 1 and has no lower bound, so it is skewed and its plots are sometimes difficult to interpret. Therneau, Grambsch and Fleming, borrowing the GLM idea, proposed in 1990 a transformation for the Cox model that makes it roughly symmetric about zero.

rD,i=sign(Mi)−2{Mi+δilog⁡(δi−Mi)}r_{D,i} = \mathrm{sign}(M_i)\sqrt{-2\left\{M_i + \delta_i \log(\delta_i - M_i)\right\}}

where rD,ir_{D,i} is the survival deviance residual and the other terms are as defined above, with δilog⁡(δi−Mi)\delta_i \log(\delta_i - M_i) taken as zero for a censored patient. For a censored patient the formula reduces to −2H^(ti∣xi)-\sqrt{2\hat{H}(t_i \mid x_i)}, so censored patients always have negative residuals, larger in size the more hazard they accumulated before censoring. A positive residual marks a patient who had the event before the model expected even one event, that is with H^(ti∣xi)<1\hat{H}(t_i \mid x_i) < 1.

The link with the GLM version is exact. Treating δi\delta_i as a Poisson count with mean H^(ti∣xi)\hat{H}(t_i \mid x_i), and substituting yi=δiy_i = \delta_i and μ^i=δi−Mi\hat{\mu}_i = \delta_i - M_i into the Poisson unit deviance, gives the term under the square root, because δilog⁡δi\delta_i \log \delta_i is zero whether δi\delta_i is 0 or 1. Stata computes the same residual after Cox proportional hazards models and extends it to parametric survival models, where it calls the underlying residuals martingale-like.

Worked example with four patients and an exponential survival curve

The figures in this example are illustrative. Four patients in one trial arm are followed for 1, 3, 5 and 11 months; the patient followed for 5 months is censored and the other three die. An exponential model is fitted, and its maximum likelihood estimate of the constant hazard is the number of deaths divided by the total time at risk.

λ^=31+3+5+11=320=0.15\hat{\lambda} = \frac{3}{1 + 3 + 5 + 11} = \frac{3}{20} = 0.15

where λ^\hat{\lambda} is the estimated monthly hazard. Under this model H^(t)=0.15 t\hat{H}(t) = 0.15\,t, so each martingale residual is δi−0.15 ti\delta_i - 0.15\,t_i. For the patient who died at month 1, M=0.85M = 0.85 and the deviance residual follows.

rD=+−2×{0.85+log⁡(0.15)}=+−2×(0.85−1.8971)=+2.0942=1.447r_D = +\sqrt{-2 \times \{0.85 + \log(0.15)\}} = +\sqrt{-2 \times (0.85 - 1.8971)} = +\sqrt{2.0942} = 1.447

where log⁡(0.15)=−1.8971\log(0.15) = -1.8971. The table repeats the steps for all four patients.

PatientTime (months)Event δi\delta_iH^(ti)\hat{H}(t_i)Martingale MiM_i−2{Mi+δilog⁡(δi−Mi)}-2\{M_i + \delta_i \log(\delta_i - M_i)\}Deviance rD,ir_{D,i}
1110.150.852.0942+1.447
2310.450.550.4970+0.705
3500.75-0.751.5000-1.225
41111.65-0.650.2984-0.546

1. Check the martingale residuals. They sum to zero, 0.85+0.55−0.75−0.65=0{0.85 + 0.55 - 0.75 - 0.65 = 0}, a property of the exponential maximum likelihood fit, in which the deaths equal λ^\hat{\lambda} times the total time at risk.

2. Read the signs. Patients 1 and 2 died while their fitted cumulative hazards were still below 1 (0.15 and 0.45), so their residuals are positive; patient 1, who died when the model expected only 0.15 events, has the largest. Patient 4 died only after accumulating a cumulative hazard of 1.65, so the residual is negative, and patient 3 is negative because censored patients always are.

3. Compare the two scales. On the martingale scale patient 4 (-0.65) lies further from zero than patient 2 (+0.55). On the deviance scale the order reverses, with the long survivor pulled in to -0.546 and the early death pushed out to +0.705, which is the symmetrising effect.

4. Add up the squares. The squared residuals sum to about 4.39, 2.0942+0.4970+1.5000+0.2984=4.3896{2.0942 + 0.4970 + 1.5000 + 0.2984 = 4.3896}, the deviance of the exponential model against a model giving each patient a separate hazard. With four patients nothing here signals misfit; the example shows the mechanics only.

Worked example with three annual costs under a gamma model

The figures here are also illustrative. Three patients have annual costs of £1,000, £2,000 and £6,000, and a gamma GLM with a log link and only an intercept is fitted, so the fitted mean is the sample mean, £3,000, for every patient. For the patient costing £6,000 the unit deviance is calculated as follows.

d=2×{6000−30003000−log⁡60003000}=2×(1−0.6931)=0.6137d = 2 \times \left\{\frac{6000 - 3000}{3000} - \log\frac{6000}{3000}\right\} = 2 \times (1 - 0.6931) = 0.6137

where dd is the gamma unit deviance and log⁡2=0.6931\log 2 = 0.6931, so the deviance residual is +0.6137=+0.783+\sqrt{0.6137} = +0.783. The same steps give the other two rows of the table.

PatientCostPearson residualUnit deviance did_iDeviance residual
A£1,000-0.6670.8639-0.929
B£2,000-0.3330.1443-0.380
C£6,000+1.0000.6137+0.783

The Pearson residuals rank the expensive patient C as the most unusual, while the deviance residuals rank patient A first. The Pearson residual measures the gap in proportion to the mean, so twice the mean (+1.000) looks further out than one third of it (-0.667). The −log⁡(yi/μ^i)-\log(y_i/\hat{\mu}_i) term in the gamma deviance judges the ratio of observed to fitted cost on roughly a log scale, so a factor of 3 below the mean (log⁡3=1.10\log 3 = 1.10) outweighs a factor of 2 above it (log⁡2=0.69\log 2 = 0.69). The Pearson residuals sum to zero, as they must for an intercept-only fit, whereas the deviance residuals sum to about -0.526, so a deviance residual plot need not centre exactly on zero. The model deviance is 1.622, the sum of the three unit deviances.

Reading deviance residual plots

In practice the residuals are plotted, and the horizontal axis decides what a plot can show. Stata's survival documentation suggests plotting them against the linear predictor, survival time, rank order of survival or observation number to find aberrant observations; with uncensored data a well-fitting model gives residuals that resemble random noise, while censored patients appear as clumps near zero.

A point far from zero marks an outlier, a patient the model fits poorly. For a curve feeding a partitioned survival model, a systematic trend in the residuals against time is informative, since positive residuals concentrated among early deaths suggest the curve understates early mortality. Large negative values among censored long survivors carry little information on their own, because a censored residual is −2H^-\sqrt{2\hat{H}} and grows in size with follow-up by construction. Xue and Schifano's review of Cox model diagnostics uses ±1.96 as a rough threshold while warning that normal-based thresholds may not suit highly censored data. Poor fit also differs from influence. Stata lists likelihood displacement values, LMAX values and DFBETAs as measures of influence, so a residual plot is read alongside one of them.

Where residual checks sit in NICE survival guidance

NICE Decision Support Unit Technical Support Document 14 (TSD 14), written by Latimer in 2011 and last updated in March 2013, guides the choice of survival models for economic evaluations using patient-level trial data, and its place in that process is set out on the Cox-Snell residual page. TSD 14 does not mention deviance residuals; its only use of the word deviance refers to the deviance information criterion, a different quantity. Its review conclusions and the first step of its model selection process accept suitable residual plots in place of log-cumulative hazard plots, and its review of past appraisals records martingale residuals among the tests used in one appraisal (TA174).

TSD 14 also bears on what follows when a residual flags a patient. Its review conclusions state that data points should be excluded only when they can be clearly shown to be erroneous outliers, and that unless a very clear rationale is offered all data should be included. A large deviance residual is therefore a reason to check a record and the model, and does not by itself justify removing a patient.

Limits and common misreadings

Three properties of the deviance residual limit how far a plot can be trusted. They matter most for immature survival data and skewed costs.

The normal approximation fails with heavy censoring. Xue and Schifano report Therneau and colleagues' finding that the survival deviance residual is close to normal when censoring is light, but that with heavy censoring too many values lie near zero for normality, although the residuals remain symmetrised, and they cite simulations by Nardi and Schemper in which censoring often made the distribution bimodal. Normal cut-offs are therefore unreliable when survival data are immature. Stata's manual adds that the residuals are expected to be symmetric about zero but need not sum to zero.

The residual is designed to find outliers and says little about model form. Stata's documentation assigns deviance residuals to model accuracy and outliers, and martingale residuals to the functional form of covariates, while the proportional hazards assumption and overall goodness of fit have their own residual checks. A clean deviance residual plot does not show that hazards are proportional or that the chosen distribution is right.

Good fit within the data is a separate question from good decisions. Mihaylova and colleagues, reviewing methods for cost and resource use data, note that further parametric models outside the GLM family aim to fit better, for example in terms of deviance, without studies confirming more reliable inferences, possibly because they overfit extreme observations. In the same way, TSD 14 stresses that checks of fit to trial data address internal validity only, so a survival model with small residuals throughout follow-up can still extrapolate implausibly.

Sources

Institutional Perspectives (1)

  • NICE Decision Support Unit

    Deviance Residuals to Find Poorly Fitting Data Points

    TSD 2 assesses the fit of generalised linear models for pairwise and network meta-analysis through the posterior mean residual deviance, to which each data point should contribute about 1, so the total can be compared with the number of independent data points. A deviance residual is calculated for each data point. Where the residuals suggest poor fit, plotting each point's contribution to the effective number of parameters against its signed deviance residual shows whether poorly fitting points materially affect the model, and points beyond the curve marking a contribution of 3 to the deviance information criterion generally indicate poor fit.

    NICE DSU Technical Support Document 2: A generalised linear modelling framework for pairwise and network meta-analysis of randomised controlled trials (Dias, Welton, Sutton and Ades, August 2011, last updated September 2016), section 2.1.2 and Figures 1 and 2View source →

Functions & Formulae (2)

r_D = sign(y - mu) * sqrt(d); D = sum of d over patients

Turns each patient's contribution to a fitted model's deviance into a signed residual, so the patients a cost regression or a survival curve describes worst can be found before its estimates feed a cost-effectiveness model. The generalised linear model version takes the square root of the unit deviance with the sign of the raw residual; the survival version applies the same idea to the martingale residual, treating the event indicator as a Poisson count with mean equal to the fitted cumulative hazard. The Cox-Snell residual itself, the fitted cumulative hazard, is HE-FM-CUMH-001 on the Cumulative Hazard page. Notation follows the Deviance Residual article.

  • Gamma unit deviance and deviance residual of one patient's cost in a generalised linear model

    d = 2 * ((y - mu) / mu - log(y / mu)); r_D = (y - mu) / abs(y - mu) * sqrt(d)

    For a gamma GLM of positive costs, the unit deviance compares the observed cost with its fitted mean through the proportional gap minus the log of their ratio, so it depends only on y / mu. The deviance residual takes its square root with the sign of y minus mu, and the squared residuals add up to the model deviance. In the Math line the sign is written (y minus mu) / |y minus mu|; at y = mu the residual is 0 by convention, a case the calculator cannot show because it divides by zero there.

  • Martingale residual and survival deviance residual of one patient from a fitted cumulative hazard

    M = delta - H; r_D = M / abs(M) * sqrt(-2 * (M + delta * log(delta - M)))

    The martingale residual is the event indicator minus the fitted cumulative hazard at the patient's observed time, the Cox-Snell residual. It cannot exceed 1 and has no lower bound, so it is skewed; the deviance residual rescales it to be roughly symmetric about zero. Since delta minus M equals the fitted cumulative hazard, the log term is always defined, and for a censored patient, with delta = 0, the residual reduces to minus the square root of twice the cumulative hazard. Treating delta as a Poisson count with mean H, the quantity under the square root is the Poisson unit deviance given in Stata's glm Methods and formulas, which links the survival residual to the GLM residual of HE-FM-DEVR-001.

View all formulae

Library

Publications

3
  • Book

    Generalized Linear Models — McCullagh P, Nelder JA, 2nd edition ed., 1989 (Chapman and Hall)

    Textbook on generalised linear models, cited as the canonical source for the deviance and the deviance residual, which it recommends for examining the goodness of fit of a generalised linear model.

  • Journal article

    Martingale-based residuals for survival models — Therneau TM, Grambsch PM, Fleming TR, Vol. 77, No. 1, pp. 147-160 ed., 1990 (Biometrika)

    Paper introducing martingale-based residuals for survival models, including a deviance residual for the Cox model adapted from generalised linear models, cited through a later review's account of its findings on censoring because the paper itself was not read.

  • Guidance

    NICE DSU Technical Support Document 21: Flexible methods for survival analysis — Rutherford, Lambert, Sweeting, Pennington, Crowther, Abrams & Latimer, TSD 21 ed., 2020 (NICE Decision Support Unit (University of Sheffield))

    Guidance extending standard survival analysis to flexible parametric methods — spline-based models, fractional polynomials, mixture and cure models, and relative-survival approaches — for capturing complex hazard functions in economic evaluation.

Tools & Resources

2
  • Other

    Stata Base Reference Manual, Release 19 — StataCorp, Release 19, entries glm and glm postestimation ed., 2025 (Stata Press)

    Software manual entries for the Stata glm command and its postestimation tools, cited for the formulas for deviance and Pearson residuals, the gamma and Poisson unit deviances and the statement that deviance residuals are approximately normally distributed if the model is correct.

  • Other

    glm.summaries: Accessing generalized linear model fits — R Core Team, R package stats, version 4.6.0, accessed 2 October 2026 ed., 2026 (R Core Team)

    Documentation for the R stats functions that access generalised linear model fits, cited for residuals returning deviance residuals by default, with Pearson, working, response and partial residuals as the alternatives.

Frequently Asked Questions (6)

  • What is a deviance residual?

    A deviance residual is a signed measure of how poorly a generalised linear or survival model fits each patient; in a GLM its squares sum to the deviance.

    Source: McCullagh & Nelder 1989

  • What does a deviance residual measure for an individual?

    A deviance residual measures how much a single observation contributes to the overall lack of fit of a survival or generalised linear model, scaled so the residuals are roughly symmetric around zero. A large positive or negative value flags a patient whose observed outcome the model predicts poorly, such as someone who survived far longer or died far sooner than expected. Plotting the residuals against covariates or time can reveal where the model systematically misfits. They localise poor fit to individuals. Collett (2015) describes them.

    Source: Collett 2015

  • How are deviance residuals used?

    Deviance residuals are used to assess a model's fit and to detect observations that the model fits poorly, by examining their size and pattern. Because their squared sum is the deviance, large deviance residuals mark observations contributing most to lack of fit. They are plotted against predicted values or covariates to check for systematic patterns indicating misspecification, and unusually large values flag potential outliers. In survival models, deviance residuals help diagnose fit and identify individuals whose survival departs from the model's expectation.

    Source: McCullagh & Nelder 1989

  • How do deviance residuals differ from Cox-Snell residuals?

    Deviance residuals and Cox-Snell residuals are both used to check survival model fit but differ in form and use. Cox-Snell residuals assess overall fit by checking whether they follow a standard exponential distribution, but they are skewed and less suited to identifying individual poorly fitted observations. Deviance residuals are a transformation making the residuals more symmetric and interpretable, better for spotting outliers and patterns for individual observations. So Cox-Snell residuals assess overall fit, while deviance residuals are more useful for examining individual observations.

    Source: Cox & Snell 1968

  • Why are deviance residuals more symmetric?

    Deviance residuals are constructed as a transformation that makes them more symmetric and closer to normally distributed than raw or Cox-Snell residuals, which are typically skewed. This symmetry makes them easier to interpret, since values can be judged against a roughly symmetric reference, and large positive or negative residuals more readily indicate observations poorly fitted above or below the prediction. The improved symmetry is why deviance residuals are preferred for identifying outliers and examining fit at the level of individual observations.

    Source: McCullagh & Nelder 1989

  • What do patterns in deviance residuals indicate?

    Patterns in deviance residuals indicate potential problems with a model: systematic trends when plotted against predicted values or covariates suggest misspecification, such as an incorrect functional form or omitted variable, while unusually large residuals mark observations poorly fitted, which may be outliers or influential points. A well-fitting model should show residuals scattered without pattern. By revealing such structure, deviance residuals guide diagnosis of how the model fails to fit, complementing overall fit measures with information about specific observations and departures.

    Source: McCullagh & Nelder 1989

Trust Record

Verified by Dr Darrin Baines

British health economist

Professional identity: darrinbaines.org

Verification date: 27 Oct 2026

Content version: 1.0.2

Canonical Identity

Term code
HE-EM-SM-016

Stable URI · Machine-readable · Resolvable · CC BY 4.0