Tutorials › Competing Risks and Multi-State Models › Sandwich Inference For Andersen-Gill Models

Recurrent-Event Estimands and Models · Tutorial 578 of 699

Sandwich Inference For Andersen-Gill Models

Learn how to form and interpret subject-clustered sandwich standard errors for Andersen–Gill coefficients without changing the fitted coefficients.

Advanced 12 min read

What You'll Learn

  • Define subject-level score contributions for an Andersen–Gill partial-likelihood fit.
  • Derive the sandwich variance from an estimating-equation expansion.
  • Calculate robust standard errors by aggregating recurrent-event contributions within subjects.
  • Compare robust and model-based uncertainty without changing the coefficient estimate.
  • Diagnose influential clusters and recognize limitations of sandwich inference.

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.

Definition: For \(n\) independent subjects, let \(U_i(\beta)\) be subject \(i\)’s contribution to the AG partial-likelihood score at coefficient vector \(\beta\). The total score is \(U(\beta)=\sum_{i=1}^n U_i(\beta)\), and the fitted coefficient \(\hat{\beta}\) solves \(U(\hat{\beta})=0\). The subject-level sandwich variance estimate is \(\hat{A}^{-1}\hat{B}(\hat{A}^{-1})'\), where \(\hat{A}=-\partial U(\beta)/\partial\beta'\) evaluated at \(\hat{\beta}\), and \(\hat{B}=\sum_{i=1}^n U_i(\hat{\beta})U_i(\hat{\beta})'\).

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

$$ \lambda_i(t\mid \mathcal{H}_i(t-)) = Y_i(t)\lambda_0(t)\exp\{\beta'X_i(t)\}. $$

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

$$ \bar{X}(\beta,t)= \frac{\sum_{j=1}^n Y_j(t)\exp\{\beta'X_j(t)\}X_j(t)} {\sum_{j=1}^n Y_j(t)\exp\{\beta'X_j(t)\}}. $$

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

$$ 0=U(\hat{\beta})\ \approx\ U(\beta_0)-A(\beta_0)(\hat{\beta}-\beta_0), $$

where \(A(\beta_0)=-\partial U(\beta)/\partial\beta'\) at \(\beta_0\). Rearranging yields the first-order approximation

$$ \hat{\beta}-\beta_0\ \approx\ A(\beta_0)^{-1}\sum_{i=1}^n U_i(\beta_0). $$

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)\}\),

$$ \operatorname{Var}(\hat{\beta})\ \approx\ A(\beta_0)^{-1}B\{A(\beta_0)^{-1}\}'. $$

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.

1
Fit the AG model.
Obtain \(\hat{\beta}\) and the score contributions defined by the fitted partial likelihood.
2
Aggregate by subject.
For each subject, add that subject’s score contributions across recurrent events to obtain \(U_i(\hat{\beta})\).
3
Form bread and meat.
Use the negative score derivative for \(\hat{A}\), and compute \(\hat{B}=\sum_i U_i(\hat{\beta})U_i(\hat{\beta})'\).
4
Calculate inference.
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:

$$ \hat{B}=1^2+(-1)^2+2^2+(-2)^2=10. $$

For a scalar coefficient, the sandwich formula reduces to \(\hat{B}/\hat{A}^2\). Therefore,

$$ \widehat{\operatorname{Var}}_{\mathrm{rob}}(\hat{\beta}) =\frac{10}{4^2}=0.625,\qquad SE_{\mathrm{rob}}=\sqrt{0.625}=0.7906. $$

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

$$ \hat{B}_{\mathrm{subject}}=2^2+(-1)^2+(-1)^2=6. $$

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

$$ \hat{B}=1.5^2+(-1.5)^2+1^2+(-1)^2=6.5,\qquad \widehat{\operatorname{Var}}_{\mathrm{rob}}(\hat{\beta})=\frac{6.5}{8^2}=0.1015625. $$

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.

ApproachWhat it estimatesMain requirement or limitation
Model-based AG varianceVariance from the fitted partial-likelihood informationRelies on the model-based information-variance relationship
Subject-level sandwichVariance from the observed variability of subject score contributionsRequires many sufficiently regular independent subjects and a valid estimating equation
Subject-level bootstrapSampling variability by resampling whole subjects and refittingMust 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.
Key takeaway: For AG sandwich inference, aggregate the partial-likelihood score contributions within each subject, form the meat from those subject totals, and combine it with the inverse score derivative. Dependence is accommodated within subjects; the coefficient estimate and its target are not changed.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. 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?
  2. For one coefficient, suppose \(\hat{A}=5\) and the subject scores are \(1,-1,1,-1\). Calculate the robust variance and standard error.
  3. Does a robust sandwich variance change the fitted AG coefficient? What does it change?
  4. 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.

Clinical Biostats