Tutorials › Marginal Structural Models › Person-Level Clustering in Repeated-Interval Survival Fits

Fitting MSMs for Survival Outcomes · Tutorial 181 of 501

Person-Level Clustering in Repeated-Interval Survival Fits

See why start-stop rows must be combined at the person level, how to construct the cluster sandwich for a weighted Cox fit, and how to diagnose errors in its implementation.

Advanced 11 min read

What You'll Learn

  • Explain why repeated start-stop intervals from one person are not independent clusters.
  • Construct interval-level weighted Cox martingale score contributions.
  • Aggregate interval contributions into person-level scores.
  • Derive the person-cluster sandwich variance estimator.
  • Compare person-level clustering with row-level and model-based uncertainty estimates.
  • Diagnose common errors in risk-set centering and cluster definition.

Why the Person, Not the Interval, Is the Cluster

A start-stop data set may contain several records for each person: one for each period during which covariates, treatment, or risk status are represented as constant. Those records help express a time-varying survival model, but they do not create new independent people. Repeated intervals from one person share a history and are linked by the same event and censoring process. Treating them as independent units can therefore give an incorrect estimate of uncertainty.

The key operation is to form the score contribution for each interval and then add all contributions belonging to the same person. The sandwich “meat” is built from these person-level sums. For a Cox fit, a useful interval contribution accounts not only for an observed event, but also for the interval’s fitted contribution through the risk set. This distinction matters: assigning the whole event-time score only to the person who experienced the event is not, in general, the right person-level decomposition for robust variance.

Definition: A person-level cluster is the complete set of start-stop records belonging to one independent person. A cluster score is the sum of the score-residual contributions over that person’s intervals. In the sandwich variance, each person contributes one outer product of their cluster score, regardless of how many intervals they have.

Interval Contributions in a Weighted Cox Fit

Let \(i=1,\ldots,n\) index people, and let \(k\) index the start-stop intervals for person \(i\). Write \(Y_{ik}(t)\) for the interval’s at-risk indicator, \(X_{ik}(t)\) for its covariate vector, and \(W_{ik}(t)\) for its weight. The weight is assumed predictable: its value at time \(t\) is determined by information available before the event increment at \(t\). Let \(\beta\) be the Cox regression parameter.

At time \(t\), define the weighted risk-set sums and the corresponding weighted covariate mean by

$$ S^{(r)}(\beta,t) = \sum_{i,k}Y_{ik}(t)W_{ik}(t) \exp\{\beta^\mathsf{T}X_{ik}(t)\} X_{ik}(t)^{\otimes r}, \qquad r=0,1, \qquad \bar X(\beta,t)=\frac{S^{(1)}(\beta,t)}{S^{(0)}(\beta,t)}. $$

Here \(X^{\otimes 0}=1\) and \(X^{\otimes 1}=X\). For simplicity, the formulas below use a Breslow-style weighted risk-set denominator; with tied-event handling based on another specified convention, the contributions must follow that same convention.

Let \(N_{ik}(t)\) count events on interval \(ik\), and let \(\widehat{\Lambda}_0(t)\) be the fitted baseline cumulative hazard. At a candidate value \(\beta\), a martingale-style score-residual contribution for the interval is

$$ q_{ik}(\beta) = \int W_{ik}(t) \{X_{ik}(t)-\bar X(\beta,t)\} \left\{ dN_{ik}(t) - Y_{ik}(t)\exp\{\beta^\mathsf{T}X_{ik}(t)\} d\widehat{\Lambda}_0(t) \right\}. $$

The first term inside braces records the observed event increment; the second is the fitted event increment. The risk-set centering in \(X_{ik}(t)-\bar X(\beta,t)\) is essential. Define the person-level contribution by summing across that person’s records:

$$ U_i(\beta)=\sum_k q_{ik}(\beta), \qquad U(\beta)=\sum_{i=1}^n U_i(\beta). $$

Worked Example: A Weighted Risk-Set Calculation

At an event time, suppose three people are at risk, with covariates \(X_A=1\), \(X_B=0\), and \(X_C=2\), weights \(W_A=1\), \(W_B=2\), and \(W_C=1\), and \(\beta=0\). Person A has the event. Use the Breslow weighted risk set to calculate the centered score and the three martingale-style contributions at this time.

Risk-set mean. Since \(\exp(\beta X)=1\),

$$ S^{(0)}=1+2+1=4, \qquad S^{(1)}=1(1)+2(0)+1(2)=3, \qquad \bar X=\frac{3}{4}=0.75. $$

The weighted event count is \(1\), so the Breslow baseline-hazard increment is \(d\widehat{\Lambda}_0=1/4\). The event-time weighted partial-likelihood score is

$$ 1(1-0.75)=0.25. $$

For person A, the observed-minus-fitted increment is \(1-1(1/4)=0.75\), giving \(q_A=1(1-0.75)(0.75)=0.1875\). For B it is \(0-1/4=-0.25\), giving \(q_B=2(0-0.75)(-0.25)=0.375\). For C it is also \(-0.25\), giving \(q_C=1(2-0.75)(-0.25)=-0.3125\). Their sum is \(0.1875+0.375-0.3125=0.25\), the event-time score above.

The three individual contributions are not the same as assigning \(0.25\) to A and zero to everyone else. The fitted-risk part distributes score-residual contributions over the people at risk. If any of these people have further intervals at other times, those contributions are also included in their respective person-level sums.

Cluster Sandwich Variance

Let \(\hat\beta\) solve the weighted Cox score equation \(U(\hat\beta)=0\), and let

$$ \widehat A = -\left. \frac{\partial U(\beta)}{\partial\beta^\mathsf{T}} \right|_{\beta=\hat\beta}, \qquad \widehat B_{\mathrm{cluster}} = \sum_{i=1}^n U_i(\hat\beta)U_i(\hat\beta)^\mathsf{T}. $$

The person-cluster sandwich estimate of the covariance matrix is

$$ \widehat{\operatorname{Var}}_{\mathrm{cluster}}(\hat\beta) = \widehat A^{-1} \widehat B_{\mathrm{cluster}} \widehat A^{-\mathsf{T}}. $$

The bread \(\widehat A\) measures the sensitivity of the fitted score to changes in \(\beta\); the meat sums one outer product per independent person. This formula uses the total-score scaling shown above, so the covariance estimate already has the appropriate sample-size scaling. Small-sample software corrections may multiply it by a factor such as \(G/(G-1)\), where \(G\) is the number of independent clusters. Such a correction does not change which records must be clustered together.

Theorem: Suppose people are independent; the weighted Cox score is consistent for the target parameter \(\beta_0\); the interval weights and covariates are predictable; the required score and derivative moments are finite; a cluster-level central limit theorem applies; and the limiting score derivative is nonsingular. If the person-level score contributions have finite covariance, then the sandwich estimator based on person-level score residuals estimates the large-sample covariance of \(\hat\beta\), under the corresponding fitted-model and weight conditions.

To see the argument, write \(U_i(\beta)\) for the person-level estimating contribution, with \(U(\beta)=\sum_i U_i(\beta)\). A first-order expansion of the estimating equation around \(\beta_0\) gives

$$ 0 = U(\hat\beta) = U(\beta_0) - A_n(\tilde\beta)(\hat\beta-\beta_0), $$

where \(A_n(\beta)=-\partial U(\beta)/\partial\beta^\mathsf{T}\), and \(\tilde\beta\) lies between \(\hat\beta\) and \(\beta_0\). Under consistency and convergence of the normalized derivative, \(A_n(\tilde\beta)/n\xrightarrow{p} A\) for a nonsingular matrix \(A\). Therefore

$$ \sqrt n(\hat\beta-\beta_0) = \{A_n(\tilde\beta)/n\}^{-1} \frac{1}{\sqrt n}\sum_{i=1}^n U_i(\beta_0). $$

The cluster contributions, not the interval records, are the independent terms in this sum. The cluster-level central limit theorem gives a limiting covariance equal to \(A^{-1}BA^{-\mathsf T}\), where \(B\) is the covariance of a person’s score contribution under the chosen normalization. Replacing \(A\) and \(B\) by the empirical bread and the sum of person-level outer products yields the stated sandwich estimator. The argument fails if rows from the same person are incorrectly treated as independent summands. \(\square\)

This derivation concerns the uncertainty calculation conditional on the weights used in the outcome fit. It does not, by itself, account for uncertainty from estimating those weights.

Worked Example: Aggregating Interval Contributions Before Forming the Meat

Suppose three people have the following interval-level score-residual contributions at the fitted parameter. Person 1 has two intervals contributing \(0.1875\) and \(-0.1000\); person 2 has two contributing \(0.3750\) and \(0.0500\); person 3 has two contributing \(-0.3125\) and \(-0.2000\). These are contributions after the observed-minus-fitted increments and risk-set centering have been applied.

First sum within person:

$$ U_1=0.1875-0.1000=0.0875,\quad U_2=0.3750+0.0500=0.4250,\quad U_3=-0.3125-0.2000=-0.5125. $$

The total score-residual sum is \(0.0875+0.4250-0.5125=0\), as expected at a fitted root. For a scalar coefficient, the cluster meat is

$$ \widehat B_{\mathrm{cluster}} = 0.0875^2+0.4250^2+(-0.5125)^2 = 0.00765625+0.180625+0.26265625 = 0.4509375. $$

By contrast, forming outer products for all six intervals separately gives \(0.3259375\). That is a different calculation: it omits the cross-products between intervals from the same person. If the scalar bread is \(\widehat A=2\), the person-cluster variance is \(0.4509375/2^2=0.112734375\), whereas the row-based calculation would give \(0.3259375/4=0.081484375\). The discrepancy illustrates the effect of ignoring within-person dependence; it does not establish that person-level clustering must always increase the variance.

Implementation, Diagnostics, and Alternatives

A reliable implementation keeps the unit of the outcome model separate from the unit of independent sampling. Intervals determine when each person contributes to risk sets and which covariates apply. People determine the independent clusters used in the meat. In practice, verify that the cluster identifier is the person identifier, that every interval has been assigned to the right person, and that the contribution being summed is the appropriate Cox score residual for the selected tie and weighting conventions.

1
Fit the weighted model.
Use start-stop intervals, the intended time-varying covariates, risk-set weights, and tie convention.
2
Obtain interval score residuals.
Use contributions consistent with the fitted weighted Cox score, including risk-set centering and fitted increments.
3
Sum by person.
For every person, add the contributions from all of their intervals before taking an outer product.
4
Build the sandwich.
Combine the person-level meat with the derivative of the full fitted score, then inspect the result for stability and plausible scale.

Useful checks include confirming that the sum of person-level residual contributions agrees with the fitted score, that there is one meat contribution per person rather than per interval, and that the number of independent clusters is reported separately from the number of rows. A large change in standard errors after correcting the cluster identifier is a reason to inspect the data structure and score-residual calculation, not a reason to choose whichever result is smaller.

The model-based Cox variance is an alternative when its information-based variance assumptions are appropriate. It is not a substitute for clustering merely because the data are stored in a Cox model. Row-level sandwich calculations likewise do not protect against dependence between intervals of one person. A person-level bootstrap, which resamples whole people and retains all their intervals, is a different way to assess sampling variation; resampling rows independently would break the observed within-person structure.

Cluster-robust uncertainty has limitations. It relies on having enough independent people for the large-sample approximation, and a few highly influential people can make the meat unstable. It does not repair a misspecified causal estimand, invalid weights, an incorrectly formed risk set, or an inappropriate cluster definition. It also does not automatically incorporate estimation of the weights. These issues require separate checks and methods.

Common Mistakes

  • Clustering by interval. Multiple records from one person are not independent just because they occupy separate rows. Use the person as the cluster.
  • Squaring before summing. The correct scalar meat contribution is \((\sum_k q_{ik})^2\), not \(\sum_k q_{ik}^2\). In vector form, it is \(U_iU_i^\mathsf{T}\), formed after aggregation.
  • Giving all event-time score to the event person. The Cox score-residual decomposition also has fitted-risk contributions for people at risk. Use score residuals consistent with the weighted risk-set score.
  • Assuming clustering fixes everything. A robust sandwich changes the uncertainty calculation; it does not correct an invalid weighting model, poor positivity, or a wrongly specified outcome model.

Worked Example: Choosing the Resampling Unit

A study includes 240 people and 1,080 start-stop rows. Some people contribute two intervals and others contribute up to eight. The analyst wants a bootstrap check of the person-cluster sandwich.

The independent sampling units are the 240 people, not the 1,080 rows. In each bootstrap replicate, sample 240 person identifiers with replacement, and retain all intervals for each selected person, including the person’s event or censoring record. If a person is selected twice, that person contributes twice as a resampled cluster. Resampling 1,080 rows would instead split histories across replicates and treat dependent intervals as independent selections, so it would not reproduce the study’s cluster sampling structure.

Check Your Understanding

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

  1. A person contributes four start-stop rows. How many outer products from this person belong in the cluster meat, and what is the score used to form one?
  2. Why can a person with no event still have a nonzero score-residual contribution over an interval when they are at risk?
  3. Three scalar interval contributions for one person are \(0.4\), \(-0.1\), and \(0.2\). What is that person’s meat contribution?
  4. There are 500 interval rows but only 125 independent people. Which count is the relevant cluster count for the sandwich, and why?

Solutions. (1) One outer product is included, formed from the person’s total score \(U_i=\sum_k q_{ik}\). (2) The fitted-risk part of the martingale-style residual can be nonzero even when the observed event increment is zero; it represents that interval’s contribution through the risk set. (3) First sum: \(0.4-0.1+0.2=0.5\). The meat contribution is \(0.5^2=0.25\), not \(0.4^2+(-0.1)^2+0.2^2\). (4) The relevant count is 125 because independent people, rather than interval rows, are the clusters.

Clinical Biostats