Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › Martingale and Deviance Residuals in Cox Models

Survival Models Review · Tutorial 120 of 697

Martingale and Deviance Residuals in Cox Models

Learn to calculate and interpret Cox martingale and deviance residuals, use them as diagnostic tools, and recognize what they cannot establish.

Intermediate 9 min read

What You'll Learn

  • Define Cox martingale residuals using each subject’s observed event indicator and fitted cumulative hazard.
  • Calculate the corresponding deviance residual, including its sign and magnitude.
  • Use martingale-residual plots to investigate the functional form of a covariate.
  • Interpret large deviance residuals as flags for review, not proof of error or influence.
  • Distinguish these diagnostics from Cox–Snell and Schoenfeld residuals.
  • Recognize the assumptions and limitations involved in residual-based Cox model checks.

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

$$ h_i(t)=h_0(t)\exp(\boldsymbol{\beta}^{\mathsf T}\mathbf{x}_i), $$

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

$$ \widehat A_i(Y_i) = \exp(\widehat{\boldsymbol{\beta}}^{\mathsf T}\mathbf{x}_i) \widehat H_0(Y_i). $$

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.

Definition: The Cox martingale residual for subject \(i\) is \( \widehat M_i=\delta_i-\widehat A_i(Y_i) \). It is the observed event indicator minus the fitted cumulative hazard through the observed time. For a censored subject, it is nonpositive; for an event subject, it can be positive or negative, but it cannot exceed 1.

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.

$$ \widehat D_i = \operatorname{sign}(\widehat M_i) \sqrt{-2\left\{\widehat M_i+ \delta_i\log\left(\delta_i-\widehat M_i\right)\right\}}. $$

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

$$ 2\left\{ \delta_i\log\left(\frac{\delta_i}{\widehat A_i(Y_i)}\right) -\left(\delta_i-\widehat A_i(Y_i)\right) \right\} = -2\left\{ \widehat M_i+ \delta_i\log\left(\delta_i-\widehat M_i\right) \right\}. $$

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

$$ \widehat D_A = +\sqrt{-2\{0.25+\log(0.75)\}} = \sqrt{-2(0.25-0.287682)} = \sqrt{0.075364} \approx 0.2745. $$

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\)
010.700.30
110.900.10
200.40-0.40
300.80-0.80
401.20-1.20
510.600.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

DiagnosticMain useWhat it does not establish
Martingale residualExploring covariate functional form and event-versus-fitted-hazard discordanceIt does not directly test proportional hazards or identify the correct transformation.
Deviance residualMaking unusually discordant subject-level outcomes easier to noticeA large value alone does not establish data error, model failure, or influence.
Cox–Snell residualAssessing overall fit by comparing transformed follow-up with an exponential reference under correct specificationIt does not isolate which covariate term may be misspecified.
Schoenfeld residualInvestigating proportional-hazards behavior for covariates over event timeIt 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

Common pitfall: “A subject has a large negative deviance residual, so the observation must be an error and should be removed.” A large residual signals discordance with the fitted model, not proof of a mistaken record or undue influence. Check the data and follow-up first, then assess influence and model sensitivity; retain a valid observation unless there is a defensible reason not to.

Check Your Understanding

Work through the questions, then compare your calculations and reasoning with the solutions.

  1. A censored subject has fitted cumulative hazard \(0.60\). Calculate the martingale and deviance residuals.
  2. An event subject has fitted cumulative hazard \(1.20\). Calculate the martingale residual and deviance residual, reporting the latter to four significant figures.
  3. 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?
  4. 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?
  5. 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.

Clinical Biostats