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.
where is the deviance residual for observation , is the observed outcome, is the fitted mean, is the unit deviance of observation , is the model deviance and 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.
where is the natural logarithm and the other terms are as defined above; the Poisson term is taken as zero when , so a zero count contributes . 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 are dominated by a few expensive patients. The Pearson residual divides the difference by the square root of the variance function, giving 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.
where is the martingale residual of patient , is 1 if the patient had the event and 0 if censored, is the observed event or censoring time, are the patient's covariates and 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.
where is the survival deviance residual and the other terms are as defined above, with taken as zero for a censored patient. For a censored patient the formula reduces to , 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 .
The link with the GLM version is exact. Treating as a Poisson count with mean , and substituting and into the Poisson unit deviance, gives the term under the square root, because is zero whether 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.
where is the estimated monthly hazard. Under this model , so each martingale residual is . For the patient who died at month 1, and the deviance residual follows.
where . The table repeats the steps for all four patients.
| Patient | Time (months) | Event | Martingale | Deviance | ||
|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 0.15 | 0.85 | 2.0942 | +1.447 |
| 2 | 3 | 1 | 0.45 | 0.55 | 0.4970 | +0.705 |
| 3 | 5 | 0 | 0.75 | -0.75 | 1.5000 | -1.225 |
| 4 | 11 | 1 | 1.65 | -0.65 | 0.2984 | -0.546 |
1. Check the martingale residuals. They sum to zero, , a property of the exponential maximum likelihood fit, in which the deaths equal 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, , 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.
where is the gamma unit deviance and , so the deviance residual is . The same steps give the other two rows of the table.
| Patient | Cost | Pearson residual | Unit deviance | Deviance residual |
|---|---|---|---|---|
| A | £1,000 | -0.667 | 0.8639 | -0.929 |
| B | £2,000 | -0.333 | 0.1443 | -0.380 |
| C | £6,000 | +1.000 | 0.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 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 () outweighs a factor of 2 above it (). 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 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
- Latimer N. NICE DSU Technical Support Document 14: Survival analysis for economic evaluations alongside clinical trials, extrapolation with patient-level data. Sheffield: Decision Support Unit, ScHARR, University of Sheffield; 2011, last updated March 2013. Sections 3.4, 3.5, 4.2, 4.6, 5 (conclusions 4 and 8) and 6. https://doi.org/10.15131/shef.data.33745843
- McCullagh P, Nelder JA. Generalized Linear Models. 2nd ed. London: Chapman and Hall; 1989.
- Mihaylova B, Briggs A, O'Hagan A, Thompson SG. Review of statistical methods for analysing healthcare resources and costs. Health Economics. 2011;20(8):897-916. https://doi.org/10.1002/hec.1653
- R Core Team. glm.summaries: Accessing generalized linear model fits. R package stats, version 4.6.0. Accessed 2 October 2026. https://stat.ethz.ch/R-manual/R-devel/library/stats/html/glm.summaries.html
- StataCorp. Stata Base Reference Manual, Release 19. Entries glm and glm postestimation. College Station, TX: Stata Press; 2025. https://www.stata.com/manuals/rglm.pdf, https://www.stata.com/manuals/rglmpostestimation.pdf
- StataCorp. Stata Survival Analysis Reference Manual, Release 19. Entries stcox postestimation and streg postestimation. College Station, TX: Stata Press; 2025. https://www.stata.com/manuals/ststcoxpostestimation.pdf, https://www.stata.com/manuals/ststregpostestimation.pdf
- Therneau TM, Grambsch PM, Fleming TR. Martingale-based residuals for survival models. Biometrika. 1990;77(1):147-160. https://doi.org/10.1093/biomet/77.1.147
- Xue Y, Schifano ED. Diagnostics for the Cox model. Communications for Statistical Applications and Methods. 2017;24(6):583-604. https://doi.org/10.29220/CSAM.2017.24.6.583
Related Concepts (5)
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
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)
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)))
Library
Publications
3
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.
BookView source →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.
Journal ArticleView source →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
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.
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.
Web (Open Access)View source →
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
- Persistent URI
- https://healtheconomics.wiki/concept/deviance-residual
- Term code
- HE-EM-SM-016
Stable URI · Machine-readable · Resolvable · CC BY 4.0
