Tutorials › Competing Risks and Multi-State Models › Martingale Residuals for Model Diagnostics

Counting Processes and Martingale Theory · Tutorial 468 of 699

Martingale Residuals for Model Diagnostics

Learn how compensated event counts are constructed and how their cumulative paths can reveal departures from a proposed event-rate structure.

Advanced 14 min read

What You'll Learn

  • Define individual and aggregate martingale residuals from an event-counting process and its fitted compensator.
  • Calculate residual paths, including the event jump and the compensator’s continuous decrease.
  • Use group- and covariate-weighted residual patterns to diagnose possible intensity misspecification.
  • Check risk-set, observation, and model-fitting conditions before interpreting a residual plot.
  • Explain why fitted residuals are not exact martingales and how to assess their variability.
  • Distinguish martingale-residual diagnostics from score-based and other model checks.

Why Compensated Counts Are Useful

An event-rate model makes a statement about the expected accumulation of events over time, given the observed history and who is currently at risk. A useful diagnostic therefore compares the events that actually occurred with the cumulative number the fitted model expected. The difference is a martingale residual. Its trajectory can reveal time periods or covariate-defined groups in which the observed event accumulation persistently exceeds, or falls short of, the model’s expectation.

The residual is not a direct test of whether a model is true. A single event produces an upward jump, while the fitted expected count accumulates between events. Random paths can consequently look uneven, especially in small samples. The diagnostic value comes from patterns that are systematic, interpretable in context, and not explained by errors in risk time, event recording, or fitting.

Definition and Conditions

For individual \(i\), let \(N_i(t)\) count the events observed by time \(t\), and let \(Y_i(t)\) indicate whether that individual is at risk immediately before \(t\). Suppose the proposed conditional intensity is \(\lambda_i(t;\theta)\), so the intensity of the observed counting process is \(Y_i(t)\lambda_i(t;\theta)\). The covariates and risk indicator used in the intensity must be predictable: their values at time \(t\) are determined by information available just before \(t\). Let \(\widehat{\theta}\) denote the fitted parameter value.

Definition: The fitted compensator and individual martingale residual process are $$ \widehat{\Lambda}_i(t)=\int_0^t Y_i(s)\lambda_i(s;\widehat{\theta})\,ds, \qquad \widehat{M}_i(t)=N_i(t)-\widehat{\Lambda}_i(t). $$ The aggregate residual is \(\widehat{M}(t)=\sum_i \widehat{M}_i(t)\). At a specified end time \(\tau\), the terminal residual for individual \(i\) is \(\widehat{M}_i(\tau)\).

The compensator is the cumulative predictable conditional intensity over the individual’s observed risk time; it accounts for expected events in the martingale-compensator sense, but is not generally the conditional expectation of the event count given the observed history. Its units are events, as are those of \(N_i(t)\); the intensity itself has units of events per unit time. For recurrent events, \(N_i(t)\) can increase more than once for the same individual. For a single-event outcome, it increases at most once.

The martingale property applies to \(M_i(t)=N_i(t)-\int_0^tY_i(s)\lambda_i(s;\theta_0)\,ds\) when the true conditional intensity is correctly specified at \(\theta_0\), with respect to the filtration containing the relevant observed history. In particular, the event process must be observed as described, and the at-risk process and covariates must be correctly represented. For the compensated process to be a true martingale on each time interval considered, it is also sufficient to require \(E[\int_0^t Y_i(s)\lambda_i(s;\theta_0)\,ds]<\infty\) for each such \(t\); without this integrability condition, it is generally only a local martingale. Censoring and entry must be handled so that the observed risk indicator represents actual observable risk time; informative loss to follow-up cannot simply be treated as ordinary independent censoring without modeling its effect.

With a fitted \(\widehat{\theta}\), the displayed residual is a plug-in residual, not generally an exact martingale: the parameter is estimated from the same event data. Its conditional mean-zero interpretation is therefore an approximation used for model checking, not an identity that holds automatically in the fitted sample. This distinction matters when assigning uncertainty to a residual plot.

How to Read the Residual Path

Between events, \(N_i(t)\) stays constant while \(\widehat{\Lambda}_i(t)\) increases, so the residual decreases at the fitted event rate during observed risk time. At an event, \(N_i(t)\) jumps upward by one for a unit-jump counting process, and the residual jumps upward by one. When the individual is not at risk, the compensator does not accumulate. These features make the direction and size of a residual change interpretable: an unusually large positive cumulative residual indicates more observed events than the fitted intensity has accumulated so far.

Under the correctly specified true intensity, the compensator balances the event count in the martingale sense. More precisely, for a predictable process \(G_i(t)\) for which the integrals exist, the weighted compensated process \(\int_0^t G_i(s)\{dN_i(s)-Y_i(s)\lambda_i(s;\theta_0)\,ds\}\) has mean zero under standard integrability conditions. Choosing \(G_i(t)=1\) gives the ordinary residual; choosing weights that select a group or emphasize a covariate produces a targeted diagnostic.

Justification: By the definition of conditional intensity, over a short interval \(dt\), the conditional expected event increment is \(E[dN_i(t)\mid\mathcal{F}_{t-}]=Y_i(t)\lambda_i(t;\theta_0)\,dt\), to first order. Thus the conditional mean of \(dN_i(t)-Y_i(t)\lambda_i(t;\theta_0)\,dt\) is zero to first order. Integrating these compensated increments gives \(M_i(t)\); the martingale property formalizes this zero conditional-mean balance over time. Replacing \(\theta_0\) by \(\widehat{\theta}\) does not preserve that argument exactly, because the fitted value depends on the observed process.

Worked Calculations

Worked Example: One Event After Changing Exposure

Suppose individual B is observed at risk for three time units, and the fitted intensity is \(0.20\) events per time unit multiplied by a predictable rate factor. The factor is 3 for the first two time units and 2 for the next one. B has one event at the end of the third time unit and no other events in this interval. Find the residual just before and just after the event.

Expected count before the event. The fitted cumulative intensity is

$$ \widehat{\Lambda}_B(3-) =(0.20)(3)(2)+(0.20)(2)(1) =1.20+0.40=1.60\ \text{events}. $$

There have been no events before time 3, so \(N_B(3-)=0\). Therefore,

$$ \widehat{M}_B(3-)=0-1.60=-1.60\ \text{events}. $$

At time 3, the observed count jumps from 0 to 1, while the compensator has no jump. The residual just after the event is \(\widehat{M}_B(3) = 1-1.60=-0.60\) events. The event raises the residual by exactly one event, from \(-1.60\) to \(-0.60\); it does not erase the earlier excess of fitted expected count over observed count.

Worked Example: Aggregate Residual Over Follow-Up

Consider three individuals in a hypothetical recurrent-event study. All remain at risk for four years, and the fitted intensity is a constant \(0.25\) events per person-year for each individual. Individual A has one event at year 1, individual B has one event at year 3, and individual C has no event. Calculate the aggregate residual at years 1, 3, and 4.

The total fitted event rate while all three are at risk is \(3(0.25)=0.75\) events per year. Immediately before year 1, the expected count is \(0.75(1)=0.75\) and no events have occurred, giving a residual of \(-0.75\) events. A’s event then raises it to \(-0.75+1=0.25\) events.

Immediately before year 3, the total fitted expected count is \(0.75(3)=2.25\) events, while A’s one event has occurred. Thus the residual is \(1-2.25=-1.25\) events. B’s event raises it to \(-1.25+1=-0.25\) events. At year 4, the expected count is \(0.75(4)=3.00\) events and the observed total is 2, so the terminal aggregate residual is \(\widehat{M}(4)=2-3.00=-1.00\) event.

The net negative value means the observed event total is one event below the fitted cumulative expectation over the 12 person-years. It is not, by itself, evidence that the model is wrong: random variation can produce a negative residual even under a correct model.

Worked Example: Checking for a Covariate-Group Pattern

A fitted common-rate model assigns every individual an intensity of \(0.20\) recurrent events per person-year. In a hypothetical five-year observation period, two individuals in group A contribute 10 person-years and experience four events in total. Two individuals in group B also contribute 10 person-years and experience one event. Calculate the residual for each group and interpret the contrast.

For group A, the fitted expected count is \((0.20)(10)=2.00\) events. Its residual is \(4-2.00=+2.00\) events. For group B, the expected count is also \((0.20)(10)=2.00\), so its residual is \(1-2.00=-1.00\) event. The aggregate residual is \(+2.00+(-1.00)=+1.00\) event, which agrees with the direct calculation \(5-(0.20)(20)=1.00\).

The contrasting group residuals suggest that the common-rate structure may underpredict events in group A and overpredict them in group B. This is a diagnostic signal to investigate, not a causal conclusion or a formal test. The groups have equal observed person-time here, so the contrast is not explained by one group simply contributing more exposure; further checks should still verify the risk-time calculation and event counts.

Using Residuals to Diagnose the Intensity

A basic diagnostic is to plot \(\widehat{M}(t)\) against time. A correctly specified intensity should not systematically leave the cumulative residual drifting in one direction, although random paths need not remain near zero. A steadily increasing path suggests that events are accumulating faster than the fitted compensator; a steadily decreasing path suggests that the fitted compensator is accumulating faster than events. A sharp change in slope or repeated clusters of jumps may point to a time-localized mismatch, a missing time-varying effect, or a recording feature that the model does not represent.

For a covariate check, sum individual residuals within prespecified covariate groups or construct a weighted process such as \(\sum_i\int_0^t g_i(s)\{dN_i(s)-Y_i(s)\lambda_i(s;\widehat{\theta})\,ds\}\). A useful weight \(g_i(s)\) might select individuals with a particular covariate value, or reflect a covariate whose association with the event rate is in question. This targets departures associated with that feature. Selecting groups after inspecting many plots, however, increases the chance of finding a striking pattern by chance.

Because parameters are estimated, uncertainty bands should reflect both event-process variation and model fitting. One practical approach is a parametric bootstrap: simulate event histories under the fitted model and the study’s observation scheme, refit the model to each simulated data set, and recalculate the residual paths. Bands from the resulting paths represent the variation expected under that fitted-model procedure. A band that accounts only for event variation while holding fitted parameters fixed may be too narrow. Any such band is a diagnostic aid, not a guarantee that all departures will be detected.

Assumptions, Failure Modes, and Alternatives

Before interpreting a residual pattern, check that the fitted intensity matches the question being diagnosed. In particular, the risk indicator must stop or resume at the correct times, delayed entry must be represented, time-varying covariates must use only information available just before each time, and the unit of exposure must be consistent with the stated rate. Event counts also need to reflect the observation process: missed events, incorrectly assigned event times, or unmodeled censoring can create patterns that look like intensity misspecification.

Residual plots can be noisy with few events, and different departures can offset in an aggregate path. A good aggregate fit can therefore conceal poor fit within a subgroup; conversely, a visually irregular path may be ordinary sampling variation. Martingale residuals are also generally asymmetric and not restricted to a fixed range, so familiar normal-error heuristics do not automatically apply. Assess multiple targeted plots, use uncertainty assessment appropriate to the fitted model, and treat a visual signal as a reason to investigate rather than proof of a particular alternative.

Martingale residuals compare counts with accumulated fitted intensity and are especially natural for event-rate structure. Score residuals instead summarize how individual event histories contribute to parameter estimation and can help identify influential observations or covariate-specific contributions to a fitted effect. Formal goodness-of-fit procedures can quantify selected departures but depend on their test construction and may miss alternatives they were not designed to detect. These approaches answer related but distinct questions; none removes the need to verify the observation and risk-set structure.

Common pitfall: Treating every residual as if it were an observed count minus a fixed expected count, without tracking time-varying risk and intensity. The correction is to integrate the fitted intensity only over the individual’s actual at-risk time, then subtract that cumulative compensator from the event count. Another mistake is to call a fitted residual an exact martingale; parameter estimation from the same data means its martingale property is only an ideal-model reference for diagnostics.

Martingale residuals matter because they translate a conditional event-rate model into an observed-versus-expected count path that can be inspected over time or across covariate groups. Their strength is the transparent accounting: each event adds a jump, and fitted expected events accumulate during risk time. Their limitation is equally important: they summarize departures relative to a model and observation process, so an incorrect risk set or a fitted-model artifact can mimic a substantive intensity failure.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. An individual is at risk for 4 time units at a constant fitted intensity of 0.15 events per time unit and experiences one event. What is the terminal residual?
  2. Why does a unit-jump event increase the martingale residual by one, even if the fitted expected count accumulated before the event is large?
  3. A group has 8 events over 30 person-years under a fitted rate of 0.20 events per person-year. Calculate its residual and state what its sign indicates.
  4. Why should a residual plot based on a fitted model not automatically be treated as an exact martingale process?

Solutions. (1) The fitted compensator is \((0.15)(4)=0.60\) events, so the terminal residual is \(1-0.60=0.40\) events. (2) The event count jumps by one and the compensator has no jump at that instant, so their difference increases by one; earlier accumulated compensator remains subtracted. (3) The expected count is \((0.20)(30)=6.00\), giving residual \(8-6.00=+2.00\) events. The positive sign means the observed count exceeds the fitted expectation by two events, which is a signal to investigate rather than proof of misspecification. (4) The fitted parameter is estimated using the same observed events, so replacing the true parameter with its data-dependent estimate does not preserve the exact martingale argument.

Clinical Biostats