Tutorials › Competing Risks and Multi-State Models › Frailty Model Diagnostics Using Residuals and Calibration

Frailty and Clustered Events · Tutorial 634 of 699

Frailty Model Diagnostics Using Residuals and Calibration

Use residual patterns and cluster-aware calibration to evaluate frailty-model fit without mistaking shrinkage or within-cluster dependence for evidence of model failure.

Advanced 10 min read

What You'll Learn

  • Define conditional and marginal martingale residuals for recurrent-event frailty models.
  • Interpret cluster-level residual patterns while accounting for frailty-induced dependence.
  • Construct and interpret deviance-style residuals for observed and expected event counts.
  • Assess calibration of predicted risks using held-out clusters and explicit frailty integration.
  • Distinguish possible baseline-hazard misspecification from unmodeled cluster heterogeneity.
  • Recognize why same-data empirical Bayes predictions can make diagnostics look too favorable.

Why Frailty Models Need More Than a Convergence Check

A frailty model can converge and still describe the data poorly. Its baseline hazard may have the wrong time pattern, its frailty distribution may fail to capture cluster differences, or its predicted risks may be systematically too high or too low. Diagnostics ask whether these failures leave recognizable discrepancies between observed and model-implied event experience.

For recurrent events, observations within a cluster are dependent. A cluster with unusually many events can reflect a high latent frailty, a misspecified baseline hazard, or chance variation. A useful diagnostic therefore examines both when events occur and how event experience varies across clusters. Calibration adds a separate question: do clusters assigned a given predicted risk experience events at about that rate?

Model and Residual Definitions

Let \(N_{ij}(t)\) count recurrent events for individual \(j\) in cluster \(i\) by time \(t\), and let \(Y_{ij}(t)\) indicate that the individual is under observation and at risk just before \(t\). A shared-frailty proportional hazards intensity can be written

$$ \lambda_{ij}(t\mid Z_i,\mathcal{F}_{t-}) =Y_{ij}(t)Z_i\lambda_0(t)\exp\{\beta^\mathsf{T}X_{ij}(t)\}. $$

Here \(Z_i>0\) is shared by members of cluster \(i\), \(\mathcal{F}_{t-}\) is the observed history just before time \(t\), and the frailty is conventionally scaled so \(E(Z_i)=1\). The model assumes independent clusters, a correctly specified conditional intensity, predictable covariates and risk indicators, and censoring that is non-informative conditional on the model variables. The frailty distribution must also be specified for likelihood-based fitting and marginal prediction. Diagnostics assess these assumptions; they do not make them true.

With known parameters and the actual frailty, the compensator is the accumulated conditional intensity. Its difference from the event count is a martingale residual:

Definition: The conditional martingale residual through time \(\tau\) is \(M_{ij}(\tau)=N_{ij}(\tau)-\int_0^\tau Y_{ij}(t)Z_i\lambda_0(t)\exp\{\beta^\mathsf{T}X_{ij}(t)\}\,dt\). The cluster residual is the sum of these residuals over the cluster's individuals. In fitted-data diagnostics, parameters are estimated and \(Z_i\) is unobserved, so residuals using fitted or predicted frailties are approximations whose construction must be stated.

A residual based on a frailty estimate learned from the very same events it is meant to diagnose can be misleading: a high observed count tends to produce a high empirical Bayes frailty estimate, which then raises the fitted expected count. When feasible, calculate residuals for a later validation period using a frailty prediction based only on earlier history, or use leave-one-period-out predictions. For a new cluster, use the population frailty distribution rather than an estimate informed by that cluster's outcomes.

Why Cluster-Level Variation Matters

Frailty induces extra variation even when the conditional model is correct. For illustration, suppose that over a fixed interval the conditional event count \(N_i\), given \(Z_i\), is Poisson with mean \(Z_i\mu_i\), and \(Z_i\) has mean 1 and variance \(\theta\). Then

$$ E(N_i)=E\{E(N_i\mid Z_i)\}=\mu_i, \qquad \operatorname{Var}(N_i) =E\{\operatorname{Var}(N_i\mid Z_i)\} +\operatorname{Var}\{E(N_i\mid Z_i)\} =\mu_i+\theta\mu_i^2. $$

The second variance term is cluster-level variation. Thus, a set of cluster counts should not be judged as though all event counts were independent Poisson observations with variance \(\mu_i\). This calculation is exact under the stated conditional Poisson model; more general recurrent-event processes need not have that count distribution, but the dependence warning remains.

Worked Example: A Validation-Period Martingale Residual

Consider a hypothetical cluster with a single member. From an earlier observation period, the fitted model predicts a frailty of \(1.4\). For a later validation period, the member is at risk throughout, and the fitted baseline-and-covariate cumulative intensity before multiplying by frailty is \(2.0\) events. The validation period contains four events. Calculate the conditional residual using the earlier frailty prediction.

The predicted integrated intensity is \(1.4(2.0)=2.8\) events. Therefore,

$$ M=O-E=4-2.8=1.2\ \text{events}. $$

The positive residual means that the validation period had 1.2 more events than the conditional fitted intensity predicted. It is a discrepancy to investigate, not by itself proof of model failure. The frailty estimate came from earlier history, so the calculation avoids directly using these four validation events to inflate their own expected count. It still treats estimated parameters and the frailty prediction as fixed, so it is not a fully standardized test statistic.

Residual Patterns and Deviance-Style Summaries

A single residual is rarely decisive. Plot cumulative residuals against time, and inspect cluster-level sums against fitted expected counts, covariates, cluster size, and follow-up. Under a well-specified intensity, the conditional martingale residual has mean zero over repeated realizations when the parameters and frailty are known. A systematic time trend in residual accumulation suggests that the model predicts event timing poorly. It may indicate a baseline-hazard problem, but time-varying covariate effects, changing risk-set composition, or informative censoring can create similar patterns.

For a simple count summary with observed count \(O_i\) and expected count \(E_i>0\), a signed Poisson-deviance-style transformation is

$$ r_{D,i}=\operatorname{sign}(O_i-E_i) \sqrt{2\left\{O_i\log\left(\frac{O_i}{E_i}\right)-(O_i-E_i)\right\}}, $$

where the term \(O_i\log(O_i/E_i)\) is defined as zero when \(O_i=0\). This is the deviance residual for a Poisson count likelihood. For recurrent-event frailty data, it can be used as a descriptive transformation of observed and expected counts, but it is not generally an exact deviance residual from the full event-process likelihood. Its usual Poisson reference behavior also does not account for estimated frailties, parameter fitting, or extra cluster variation.

Worked Example: Transforming an Observed Count

A hypothetical validation cluster has \(O=5\) events, with \(E=3.0\) expected events. Its signed Poisson-deviance-style residual is

$$ r_D=+\sqrt{2\left\{5\log(5/3)-(5-3)\right\}} =+\sqrt{2\{5(0.5108)-2\}} =+\sqrt{1.108} =1.053. $$

The positive sign indicates more events than expected. The value \(1.053\) is a compact measure of discrepancy on a deviance scale; it is not automatically a standard-normal score or a p-value. In particular, shared frailty means that unusually large residuals can cluster together even when the model is correct. For an individual count of zero and \(E=3\), the same formula gives \(r_D=-\sqrt{2(3)}=-2.449\), using the zero-count convention.

A useful qualitative distinction is the shape of the discrepancy. If many clusters show residual accumulation in the same time interval, the baseline hazard or a common time effect deserves scrutiny. If some clusters remain consistently above expectation while others remain below it across periods, the model may not capture the degree or structure of cluster heterogeneity. This distinction is suggestive rather than definitive: a wrongly specified baseline can interact with unequal follow-up, and an incorrectly specified frailty distribution can alter both the size and timing of residuals.

Calibration of Predicted Cluster Risk

Calibration compares predicted event risk with observed event frequency. Define the prediction target first: for example, the probability that a new cluster has at least one event in a specified period, or the expected number of events in that period. Predictions for a new cluster integrate over the population frailty distribution. Predictions for an observed cluster can use its earlier event history to update frailty, but must not use the validation outcome being assessed.

For a new cluster in a first-event setting, suppose the cumulative baseline-and-covariate hazard over the period is \(H\), and conditional survival given frailty is \(\exp(-Z H)\). The marginal risk of at least one event is \(1-E\{\exp(-ZH)\}\). For gamma frailty with mean 1 and variance \(\theta\), its Laplace transform gives

$$ P(\text{at least one event})=1-(1+\theta H)^{-1/\theta}. $$

This formula assumes the stated gamma frailty model and the conditional hazard specification. It is not a generic risk formula for every frailty distribution. With recurrent events, the probability of at least one event can use the same expression when the conditional count process has probability of no events equal to \(\exp(-ZH)\); otherwise the event-process model must determine that probability.

Worked Example: Calibrating Risk for New Clusters

A hypothetical model uses gamma frailty with \(\theta=0.5\). For each of 40 new clusters, the covariate-specific cumulative hazard over a defined period is \(H=0.4\). Suppose 15 of the 40 clusters experience at least one event. Calculate the predicted risk and compare it with the observed proportion.

The model's marginal predicted risk is

$$ 1-(1+0.5(0.4))^{-1/0.5} =1-(1.2)^{-2} =1-0.6944 =0.3056. $$

The expected number with an event is \(40(0.3056)=12.22\) clusters. The observed proportion is \(15/40=0.3750\), or 37.50%, which is 6.94 percentage points above the predicted risk; the observed count is \(15-12.22=2.78\) clusters above its expected count. This is evidence to examine calibration in an independent set of clusters, not a stand-alone test of misfit. A naive calculation using frailty fixed at its mean would give \(1-\exp(-0.4)=0.3297\), a different risk because it fails to integrate over frailty.

Calibration can be summarized by comparing observed and predicted risk across groups of clusters ordered by predicted risk, or by comparing total observed events with the sum of predicted counts. Calibration-in-the-large asks whether predictions are systematically too high or too low overall; calibration across risk groups asks whether the model separates lower- and higher-risk clusters appropriately. Use cluster-level resampling or other methods that preserve dependence when quantifying uncertainty. A validation set with few clusters or few events can give a noisy calibration assessment, even if it contains many individuals within each cluster.

Separating Baseline-Hazard Problems from Cluster Heterogeneity

Diagnostic patternPossible explanationUseful follow-up
Residuals accumulate in the same period across many clustersBaseline hazard or a common time pattern is misspecifiedCompare observed and predicted event timing; inspect time-specific residuals and risk sets
A subset of clusters repeatedly has positive residuals while others have negative residualsResidual cluster heterogeneity, dependence, or an inadequate frailty structurePlot cluster summaries across periods and compare predictions for new versus observed clusters
Overall calibration is poor but residuals show no clear time or cluster patternRisk scale, covariate effects, or prediction target may be wrongCheck the target definition, covariate specification, and calibration by predicted-risk group

These are diagnostic clues, not a way to identify a unique cause from one plot. In particular, a flexible baseline hazard cannot repair unmodeled dependence, and a frailty term cannot repair a systematic time trend in the conditional event rate. Review risk-set definitions, censoring, covariate histories, and the prediction horizon before attributing a pattern to either component.

The main alternatives answer different questions. Martingale residuals emphasize signed discrepancies in event counts and their timing. Deviance-style residuals make count discrepancies more comparable in magnitude, but their reference interpretation is limited under frailty. Calibration directly assesses predicted risks or counts, usually on held-out clusters, but may conceal compensating errors: overprediction in one subgroup can offset underprediction in another. Use these tools together rather than treating one as a universal goodness-of-fit test.

Common Pitfalls and Practical Workflow

A frequent mistake is to compute an empirical Bayes frailty from all events in a cluster, use it to predict the same events, and conclude that small residuals establish good fit. The correction is to make the information boundary explicit: use earlier cluster history to predict a later period, or evaluate entirely new clusters using population-integrated predictions. Another mistake is to treat each individual or event as independent when calculating uncertainty. Shared frailty creates within-cluster dependence, so validation and uncertainty summaries should respect the cluster as the independent sampling unit.

1
Specify the target and information set.
State whether the diagnostic concerns event timing, a count, or risk, and whether the cluster is new or previously observed.
2
Construct predictions without outcome leakage.
For new clusters integrate over the frailty distribution; for observed clusters use only history available before the validation period.
3
Inspect time and cluster patterns.
Plot cumulative martingale residuals over time and compare cluster-level observed counts with their fitted expectations.
4
Assess calibration and uncertainty.
Compare observed with predicted risks or counts at the cluster level, and use uncertainty methods that preserve cluster dependence.

Diagnostics have limits. Residuals depend on estimated parameters and, for observed clusters, on how frailty is predicted. Calibration can be unstable with few independent clusters, while good aggregate calibration does not guarantee correct individual predictions. No residual plot can establish that the frailty distribution is correct. The strongest assessment combines temporal patterns, cluster-level discrepancies, and out-of-sample calibration, then reports the population and prediction horizon to which each conclusion applies.

Check Your Understanding

Answer each question before reading the solutions.

  1. A cluster has 3 events and a predicted integrated intensity of 4.2 events in a validation period. What is its martingale residual, and how should its sign be interpreted?
  2. Why can a residual based on a frailty estimate calculated from the same events being assessed appear too small?
  3. Under the gamma-frailty model with \(\theta=0.5\), calculate the marginal probability of at least one event when \(H=0.2\).
  4. Many clusters show residuals that rise in the same late period. Name one possible explanation and one reason this pattern is not conclusive.
  5. Why is it generally inappropriate to assess uncertainty for cluster calibration as if every individual event were independent?

Solutions. 1. \(M=3-4.2=-1.2\) events; the cluster had 1.2 fewer events than predicted. 2. The observed events raise the estimated frailty, which raises the expected count used to calculate the residual; the same outcomes influence both sides of the comparison. 3. \(1-(1+0.5(0.2))^{-2}=1-(1.1)^{-2}=1-0.8264=0.1736\), or 17.36%. 4. A misspecified baseline hazard or omitted common time effect is possible; changing risk-set composition or time-varying covariate effects could produce a similar pattern. 5. Shared frailty induces within-cluster dependence, so event-level independence understates how much observations within a cluster move together.

Clinical Biostats