Why Look at Subject-Level Residuals?
A fitted Cox model summarizes how covariates are associated with the hazard, but a coefficient table does not show whether the model describes every subject’s event experience equally well. Subject-level residuals compare what happened to a subject with what the fitted model expected by that subject’s observed time. Martingale residuals are especially useful for investigating whether a continuous covariate has been given a plausible functional form. Deviance residuals re-express the same information on a scale that can make unusual observations easier to spot.
These residuals are diagnostic summaries, not independent tests of model validity. Their interpretation depends on the fitted model, its risk sets, the handling of tied event times, and the assumptions behind the survival analysis.
Definitions and Assumptions
Consider independent subjects indexed by \(i\), with event time \(T_i\) and right-censoring time \(C_i\). The observed time is \(Y_i=\min(T_i,C_i)\), and \(\delta_i=1\) if the event is observed and \(\delta_i=0\) if the observation is censored. A Cox proportional hazards model specifies
where \(h_0(t)\) is the baseline hazard and \(\mathbf{x}_i\) is the covariate vector. Let \(\widehat{\boldsymbol{\beta}}\) and \(\widehat H_0(t)\) be the fitted regression coefficients and baseline cumulative hazard, estimated using a tie-handling method appropriate to the analysis. The fitted cumulative hazard for subject \(i\) through their observed time is
This quantity is the fitted cumulative hazard contribution for that subject. It is not a probability; cumulative hazards can exceed 1. The calculations below assume a standard Cox model with one event type, independent subjects, and censoring that is noninformative conditional on the modeled covariates. Correct construction of risk sets and a consistent treatment of ties are also required. These residuals do not remedy violations of those assumptions.
The residual has a useful event-versus-expectation interpretation. An observed event contributes 1, while a censored observation contributes 0; the fitted cumulative hazard is subtracted in either case. A positive residual means the observed event contribution exceeds the fitted cumulative hazard. A negative residual means the fitted cumulative hazard is larger than the observed event contribution. Because censoring stops observation at \(Y_i\), the residual does not claim to describe what would have happened after that time.
Worked Example: Calculating Martingale Residuals
Suppose a hypothetical fitted Cox model gives the following subject-specific cumulative hazards at each subject’s observed time. The values already include the fitted covariate multiplier. Calculate each martingale residual.
Subject A has an observed event and \(\widehat A_A(Y_A)=0.75\). Thus \( \widehat M_A=1-0.75=0.25 \). The observed event contribution is larger than the fitted cumulative hazard by 0.25 on this residual scale.
Subject B is censored and \(\widehat A_B(Y_B)=0.40\). Thus \( \widehat M_B=0-0.40=-0.40 \). The residual is negative because no event was observed before censoring, while the fitted cumulative hazard accumulated to 0.40.
Subject C has an observed event and \(\widehat A_C(Y_C)=1.50\). Thus \( \widehat M_C=1-1.50=-0.50 \). An event occurred, but the fitted cumulative hazard through that time exceeded the observed event contribution. A negative residual does not mean the event was recorded incorrectly.
Deviance Residuals
Martingale residuals have a constrained, asymmetric distribution: they are bounded above by 1, while negative values can be arbitrarily large in magnitude. Deviance residuals transform them to a scale with positive and negative values and often make exceptionally discordant observations more visible.
Here \(\operatorname{sign}(m)\) is positive for \(m>0\) and negative for \(m<0\). In the event case, \(\delta_i-\widehat M_i=\widehat A_i(Y_i)\). The logarithm is therefore of the fitted cumulative hazard for an event subject. For a censored subject the logarithmic term is zero, so the formula reduces to \( -\sqrt{-2\widehat M_i} \). The deviance residual keeps the martingale residual’s sign, but its magnitude is transformed; it is not measured in the original covariate’s units.
Why the Deviance Transformation Has This Form
The transformation is motivated by the Poisson deviance for an observed count \(\delta_i\) and fitted mean \(\widehat A_i(Y_i)\). For a count \(y\) and fitted mean \(\mu\), the Poisson deviance contribution is \(2\{y\log(y/\mu)-(y-\mu)\}\), with \(0\log(0/\mu)\) defined as 0. Applying this expression to \(y=\delta_i\) and \(\mu=\widehat A_i(Y_i)\) gives
The equality follows because \(\widehat M_i=\delta_i-\widehat A_i(Y_i)\), so \(\delta_i-\widehat M_i=\widehat A_i(Y_i)\); when \(\delta_i=1\), \(\log(\delta_i/\widehat A_i)= -\log(\widehat A_i)\), and when \(\delta_i=0\), the logarithmic term is defined as zero. Taking the square root of the deviance magnitude and restoring the sign of \(\widehat M_i\) gives \(\widehat D_i\). This is a useful deviance-based transformation of the Cox residual, not a claim that Cox observations are independent Poisson counts.
Worked Example: Transforming Martingale Residuals
For subject A in the previous example, \(\delta_A=1\) and \(\widehat A_A(Y_A)=0.75\), so \(\widehat M_A=0.25\). The deviance residual is
For subject B, \(\delta_B=0\) and \(\widehat M_B=-0.40\), so \( \widehat D_B=-\sqrt{-2(-0.40)}=-\sqrt{0.80}\approx-0.8944 \). The minus sign is retained because the martingale residual is negative. The two deviance residuals are not simply the original residuals rescaled by a common constant.
Using the Residuals as Diagnostics
A common use of martingale residuals is to investigate the functional form of a continuous covariate. If a model assumes a linear effect of \(x\) on the log hazard, the linear predictor contains \(\beta x\). To examine whether that form is adequate, fit a model omitting \(x\), calculate its martingale residuals, and plot them against \(x\), often with a smooth curve. A systematic pattern in the smooth may suggest that the omitted covariate has an association not captured by a simple linear term. This is an exploratory diagnostic: it does not by itself specify the correct transformation or establish a formal significance level.
Worked Example: A Pattern Suggesting a Nonlinear Covariate Effect
In a hypothetical data set, a Cox model omitting a continuous exposure gives these martingale residuals for six subjects:
| Exposure \(x\) | Event indicator \(\delta\) | Fitted cumulative hazard \(\widehat A(Y)\) | Martingale residual \(\widehat M\) |
|---|---|---|---|
| 0 | 1 | 0.70 | 0.30 |
| 1 | 1 | 0.90 | 0.10 |
| 2 | 0 | 0.40 | -0.40 |
| 3 | 0 | 0.80 | -0.80 |
| 4 | 0 | 1.20 | -1.20 |
| 5 | 1 | 0.60 | 0.40 |
For example, at \(x=3\), the subject is censored, so \( \widehat M=0-0.80=-0.80 \); at \(x=5\), an event is observed, so \( \widehat M=1-0.60=0.40 \). The sequence is not a smooth monotone trend, but its negative values over the middle exposure range and positive values at the ends could prompt a closer look at a smoothed residual plot. With only six subjects this pattern is highly uncertain and could be chance variation. In a larger data set, a reproducible curved trend would motivate considering a nonlinear term, such as a spline, and comparing the resulting model. The table alone does not prove nonlinearity.
Deviance residuals are often inspected for unusually large absolute values. A large value identifies a subject whose event/censoring outcome is relatively discordant with the fitted cumulative hazard. It is a reason to verify the record and examine the subject’s covariates and follow-up, not a reason to delete the subject automatically. Influence requires assessing how much the fitted model changes when an observation is perturbed or omitted; residual size alone does not measure that change.
Worked Example: Flagging an Unusual Observation
Suppose a hypothetical subject is censored with fitted cumulative hazard \(\widehat A(Y)=3.20\). Then \( \widehat M=0-3.20=-3.20 \), and \( \widehat D=-\sqrt{-2(-3.20)}=-\sqrt{6.40}\approx-2.530 \). This relatively large negative deviance residual flags a subject for review: the model accumulated substantial hazard before the subject was censored without an observed event. It does not prove the model is wrong. The analyst should check the event and censoring records, covariate values, and follow-up, then consider whether the case is influential using an appropriate influence analysis.
Comparison, Diagnostics, and Limitations
| Diagnostic | Main use | What it does not establish |
|---|---|---|
| Martingale residual | Exploring covariate functional form and event-versus-fitted-hazard discordance | It does not directly test proportional hazards or identify the correct transformation. |
| Deviance residual | Making unusually discordant subject-level outcomes easier to notice | A large value alone does not establish data error, model failure, or influence. |
| Cox–Snell residual | Assessing overall fit by comparing transformed follow-up with an exponential reference under correct specification | It does not isolate which covariate term may be misspecified. |
| Schoenfeld residual | Investigating proportional-hazards behavior for covariates over event time | It is not a substitute for checking a continuous covariate’s functional form. |
Residual patterns can be affected by a small sample, heavy censoring, influential subjects, omitted covariates, and the fitted risk sets. Martingale residuals are inherently asymmetric, so a cloud need not look like normally distributed regression errors. Deviance residuals may be more balanced in appearance, but they are not guaranteed to be independent, normally distributed, or bounded. Neither residual should be interpreted with ordinary linear-regression rules.
A practical diagnostic sequence is to verify the analysis data and risk-set construction, inspect martingale residuals against candidate continuous covariates when assessing functional form, and examine deviance residuals to identify observations for follow-up. Then assess other model features with appropriate tools. In particular, proportional hazards is a separate question; Schoenfeld residuals address that question. Residual plots are most informative when interpreted alongside substantive knowledge and sensitivity to plausible alternative specifications.
Common Mistake
Check Your Understanding
Work through the questions, then compare your calculations and reasoning with the solutions.
- A censored subject has fitted cumulative hazard \(0.60\). Calculate the martingale and deviance residuals.
- An event subject has fitted cumulative hazard \(1.20\). Calculate the martingale residual and deviance residual, reporting the latter to four significant figures.
- For an event subject with fitted cumulative hazard \(0.40\), determine the signs of the martingale and deviance residuals. What does the sign tell you?
- Which residual would you examine to investigate a continuous covariate’s functional form, and which would you use to flag unusually discordant subject-level outcomes?
- Why does a large deviance residual not, by itself, justify deleting a subject?
Solutions. (1) \( \widehat M=0-0.60=-0.60 \), and \( \widehat D=-\sqrt{1.20}\approx-1.095 \). (2) \( \widehat M=1-1.20=-0.20 \), so \( \widehat D=-\sqrt{-2\{-0.20+\log(1.20)\}}=-\sqrt{0.03536}\approx-0.1880 \). (3) \( \widehat M=1-0.40=0.60 \), so both residuals are positive; the observed event contribution exceeds the fitted cumulative hazard. (4) Use martingale residuals plotted against the covariate to explore functional form; use deviance residuals to help flag unusually discordant observations. (5) The residual signals discordance, not data error or influence. Verify the record and evaluate model sensitivity before deciding how to handle the observation.