Why Cluster the Uncertainty by Subject?
An Andersen–Gill (AG) analysis represents recurrent events using a counting process for each subject. Its partial-likelihood coefficient estimate can be useful even when events from the same person are dependent. But treating event records as if they were independent can understate or otherwise misstate uncertainty: one person’s sequence of events is a cluster, not a collection of unrelated people. Subject-level sandwich inference keeps the AG coefficient estimate and changes how its variance is estimated.
The key operation is to add a subject’s score contributions across all of that subject’s events before taking an outer product. This permits dependence among a subject’s repeated event contributions while relying on independent subjects as the sampling units. It does not make the coefficient estimate robust to every modeling error, nor does it correct bias from an inappropriate estimand or informative censoring.
Model, Score, and Assumptions
For context, the AG model specifies subject \(i\)’s event intensity at time \(t\), given the observed history just before \(t\), as
Here \(Y_i(t)\) indicates whether subject \(i\) is at risk, \(X_i(t)\) is a possibly time-varying covariate vector, and \(\lambda_0(t)\) is an unspecified baseline intensity. The score and risk sets are defined by the chosen AG partial likelihood. With distinct event times, a score contribution for an event from subject \(i\) at time \(t\) is \(X_i(t)-\bar{X}(\beta,t)\), where
The subject score \(U_i(\beta)\) adds the contributions assigned to subject \(i\) across that subject’s event times; consequently, \(\sum_i U_i(\beta)\) is the ordinary AG score. Appropriate tie handling changes the particular score contributions, but not the principle: use contributions consistent with the fitted partial likelihood and aggregate them by subject.
The sandwich argument requires more than simply having repeated observations. The subjects must be independent sampling units, and the estimating equation must be unbiased for the target coefficient, or satisfy suitable conditions for a well-defined pseudo-true target. For the usual AG interpretation, the conditional intensity specification, predictable covariates, risk-set construction, and censoring assumptions must support that estimating equation. Within-subject dependence in event histories is allowed; dependence between different subjects is not automatically accommodated.
For large-sample normal inference, regularity conditions are also needed: the number of independent subjects grows, the score contributions have finite covariance and are not dominated by a few subjects, the estimating equation has a nonsingular and consistently estimated derivative, and the empirical sandwich meat consistently estimates the variability of the summed scores. One sufficient setting is identically distributed independent subject contributions with finite covariance, together with the regularity conditions for the estimating-equation expansion. More general settings require suitable triangular-array conditions, including a Lindeberg-type condition. Independence and finite second moments alone are not enough to guarantee a normal limit.
Why the Sandwich Formula Works
Let \(\beta_0\) denote the target value and suppose \(U(\beta_0)\) has mean zero. A first-order Taylor expansion of the score around \(\beta_0\), evaluated at the root \(\hat{\beta}\), gives
where \(A(\beta_0)=-\partial U(\beta)/\partial\beta'\) at \(\beta_0\). Rearranging yields the first-order approximation
If subjects are independent, the variance of the score sum is the sum of the subject-level covariance matrices; the scores within any one subject need not be independent. Thus, writing \(B=\sum_i\operatorname{Var}\{U_i(\beta_0)\}\),
The observed derivative estimates \(A\), and the sum of subject-score outer products estimates \(B\). At the fitted value, the total score is zero, so the empirical subject scores are already centered in aggregate. This gives the sandwich estimator in the definition. In contrast, model-based variance relies on the information equality implied by the likelihood model, which gives the information inverse as the variance. The robust meat does not require that equality.
Obtain \(\hat{\beta}\) and the score contributions defined by the fitted partial likelihood.
For each subject, add that subject’s score contributions across recurrent events to obtain \(U_i(\hat{\beta})\).
Use the negative score derivative for \(\hat{A}\), and compute \(\hat{B}=\sum_i U_i(\hat{\beta})U_i(\hat{\beta})'\).
Use the diagonal of the sandwich variance for coefficient variances, take square roots for standard errors, and construct tests or intervals using the stated large-sample reference distribution.
Worked Calculations
Worked Example: Computing a Robust Standard Error
Suppose a hypothetical AG fit has one coefficient \(\hat{\beta}=0.30\), observed information \(\hat{A}=4\), and four subject-level score contributions at the fit of \(1,-1,2,-2\). The scores sum to zero, as they should at a fitted score root. Compute the robust variance and compare it with the model-based variance.
The robust meat is the sum of the squared subject scores:
For a scalar coefficient, the sandwich formula reduces to \(\hat{B}/\hat{A}^2\). Therefore,
The model-based variance is \(1/\hat{A}=1/4=0.25\), with standard error \(0.5000\). In this hypothetical fit, the robust estimate is larger. A 95% Wald interval using the robust standard error is \(0.30\pm1.96(0.7906)=[-1.2496,1.8496]\), approximately. This is an interval for the log intensity ratio coefficient; exponentiating its endpoints gives an interval of approximately \([0.2866,6.357]\) for the intensity ratio. The difference in standard errors does not change \(\hat{\beta}=0.30\).
Worked Example: Why Recurrent Contributions Must Be Aggregated First
In a second hypothetical fit, suppose four event-level score contributions are \(1,1,-1,-1\), with the first two from subject A and the last two from subjects B and C, respectively. The total score is zero. Let the observed information be \(\hat{A}=3\). Compare the subject-level meat with the result from incorrectly treating the four event contributions as independent units.
The subject totals are \(U_A=1+1=2\), \(U_B=-1\), and \(U_C=-1\). The correct subject-level meat is
Hence the robust variance is \(6/3^2=0.6667\), and the robust standard error is \(\sqrt{0.6667}=0.8165\). If the four event contributions were incorrectly squared separately, the meat would be \(1+1+1+1=4\), producing a variance of \(4/9=0.4444\). That calculation discards the covariance represented by the two contributions from subject A. It falsely treats that person’s repeated contributions as independent sampling units.
Worked Example: A Robust Wald Test and Interval
Consider a third hypothetical one-coefficient AG fit with \(\hat{\beta}=0.50\), observed information \(\hat{A}=8\), and subject-level scores \(1.5,-1.5,1,-1\). The scores sum to zero. Test \(H_0:\beta=0\) against a two-sided alternative using the robust variance.
The meat and variance are
Thus \(SE_{\mathrm{rob}}=\sqrt{0.1015625}=0.3187\), and the Wald statistic is \(z=0.50/0.3187=1.569\). The two-sided standard-normal \(p\)-value is approximately \(0.117\). At the 0.05 significance level, this is not sufficient evidence against \(H_0\); it is not evidence that the null hypothesis is true.
The 95% Wald interval is \(0.50\pm1.96(0.3187)=[-0.1246,1.1246]\), approximately. If \(\exp(\beta)\) is interpreted as an intensity ratio, the corresponding estimate is \(\exp(0.50)=1.649\), and the interval is \([\exp(-0.1246),\exp(1.1246)]\), approximately \([0.883,3.079]\). The interval includes 1, in agreement with the two-sided test.
Diagnostics, Alternatives, and Limitations
The sandwich estimator can be unstable when the number of independent subjects is small, even if the data contain many event records. Inspect subject-level scores or influence measures: a small number of unusually large score vectors can dominate \(\hat{B}\), making the standard error sensitive to individual subjects. Check that subjects, rather than event rows, are the units used to form the meat. Also verify that the fitted model uses the intended recurrent-event risk sets and that covariates are defined using information available before each event.
A large difference between robust and model-based standard errors is a reason to investigate dependence, influential subjects, and possible model misspecification; it is not by itself proof that one estimate is correct. Conversely, similar standard errors do not establish independence of repeated events. Standard errors can also be misleading when there are too few independent subjects for the large-sample approximation or when a few subjects have extreme leverage. Small-sample corrections sometimes multiply the empirical meat by a finite-sample factor, but the correction depends on the software and setting; it does not replace adequate independent-cluster information.
| Approach | What it estimates | Main requirement or limitation |
|---|---|---|
| Model-based AG variance | Variance from the fitted partial-likelihood information | Relies on the model-based information-variance relationship |
| Subject-level sandwich | Variance from the observed variability of subject score contributions | Requires many sufficiently regular independent subjects and a valid estimating equation |
| Subject-level bootstrap | Sampling variability by resampling whole subjects and refitting | Must resample subjects, not separate events; can be unreliable with few subjects or unstable fits |
The sandwich method changes estimated uncertainty, not the estimating equation: \(\hat{\beta}\), fitted relative intensity effects, and the chosen AG estimand remain the same. It cannot repair a wrong risk set, an incorrect target, informative loss to follow-up not handled by the analysis, or a systematically incorrect mean/intensity model. It also does not make subjects independent if the sampling design has related or otherwise dependent subjects; that design may require a broader clustering unit.
Common Mistakes
- Squaring event contributions separately. This ignores within-subject dependence. Sum contributions within subject first, then take the outer product.
- Thinking “robust” changes the estimate. The sandwich uses the same fitted score root and changes the covariance estimate only.
- Assuming it corrects model bias. It can protect variance estimation against some covariance misspecification, but the estimating equation still needs to target the intended parameter.
- Claiming a normal limit from independence alone. Asymptotic normality also needs regularity and suitable moment or Lindeberg-type conditions, plus a consistent derivative and meat estimate.
- Counting events as the sample size for inference. For subject-clustered sandwich inference, the independent information comes from subjects, not the total number of recurrent events.
Check Your Understanding
Answer each question, then compare with the solutions below.
- In a subject-clustered AG fit, should the meat be formed by summing event-level squared scores or by summing subject-level score outer products?
- For one coefficient, suppose \(\hat{A}=5\) and the subject scores are \(1,-1,1,-1\). Calculate the robust variance and standard error.
- Does a robust sandwich variance change the fitted AG coefficient? What does it change?
- Name two conditions or features that can make sandwich inference unreliable even when the calculation is implemented correctly.
Solutions. (1) Sum each subject’s score contributions first, then sum the outer products of those subject totals. (2) \(\hat{B}=1^2+(-1)^2+1^2+(-1)^2=4\), so the variance is \(4/5^2=0.1600\), and the standard error is \(\sqrt{0.1600}=0.4000\). (3) No. It retains the coefficient estimate and changes the estimated covariance, standard errors, and resulting tests and intervals. (4) Examples include few independent subjects, domination by a few influential subjects, failure of the score equation to target the desired parameter, or dependence between subjects that the chosen clustering does not represent.