Why Aggregate Contributions by Subject?
A person in a multi-state study may contribute information to more than one transition model. For example, the same person may be at risk for an initial transition and later contribute data after entering another state. Those contributions are not generally independent: they come from the same subject and may share covariates, follow-up, or event history. A variance calculation that treats every transition contribution as independent can therefore misstate uncertainty.
The sandwich variance addresses this dependence by first adding each subject’s contributions across transitions and then calculating variability across subjects. The key unit for the variance calculation is the independent subject, not the individual transition contribution. This tutorial develops that construction for regression estimates obtained from a joint estimating equation.
The contributions may arise from transition-specific regression terms, shared effects, or a joint model. If a transition has no contribution for a particular subject, its corresponding term is zero. When parameters are transition-specific, a contribution is represented in the appropriate coordinates of the full parameter vector; when a parameter is shared, contributions from all relevant transitions enter its coordinate. The subject-level sum must match the estimating equation used to obtain \(\hat\theta\).
Deriving the Subject-Level Sandwich
Let \(H(\theta)=-\partial U(\theta)/\partial\theta^\mathsf{T}\) be the negative derivative, or “bread,” of the total estimating function. It is a \(q\)-by-\(q\) matrix. Define the “meat” at the estimate by \(M(\hat\theta)=\sum_i U_i(\hat\theta)U_i(\hat\theta)^\mathsf{T}\). The resulting covariance estimate uses the outer product of each subject’s complete score vector.
Here \(H^{-\mathsf{T}}\) means the transpose of \(H^{-1}\). If the estimating function is a likelihood score and the model is correctly specified, the inverse information may also provide a model-based covariance estimate. The sandwich instead uses the observed across-subject variability of the estimating functions in its middle factor. It can remain asymptotically valid when the variance structure within subjects is more complicated than the working model, provided the estimating equation has the correct mean and the other regularity assumptions hold.
A short Taylor expansion gives the variance formula. Write \(H(\theta_0)=-\partial U(\theta_0)/\partial\theta^\mathsf{T}\) at the true parameter \(\theta_0\). Expanding the equation \(U(\hat\theta)=0\) around \(\theta_0\), and ignoring a remainder that is smaller in probability than the leading term, gives the following relationship.
The sum on the right is a sum of independent subject-level contributions. Its covariance is the sum of their covariance matrices; cross-products between transition contributions from the same subject are part of each subject’s covariance. Replacing the unknown derivative and covariance by their empirical counterparts yields the sandwich estimate above. In normalized form, if \(H/n\) converges to a nonsingular matrix \(A\), then the asymptotic covariance of \(\hat\theta\) is \(A^{-1}BA^{-\mathsf{T}}/n\), where \(B\) is the covariance matrix of a subject-level contribution.
Worked Calculations
Worked Example: Two Transition Contributions to One Estimate
Suppose a hypothetical fitted model has one scalar coefficient and four independent subjects. The table gives each subject’s score contribution from transitions A and B at the fitted estimate. For this illustration, the total derivative is \(H(\hat\theta)=8\).
| Subject | \(U_{iA}\) | \(U_{iB}\) | \(U_i=U_{iA}+U_{iB}\) |
|---|---|---|---|
| 1 | 1 | 2 | 3 |
| 2 | -1 | 1 | 0 |
| 3 | 2 | -1 | 1 |
| 4 | -2 | -2 | -4 |
The score sums for A and B are both zero, so the total score also sums to zero, as expected at this fitted estimate. The subject-level meat is the sum of squared total scores:
Thus the estimated variance and standard error are
The transition-level sums of squares are \(1^2+(-1)^2+2^2+(-2)^2=10\) for A and \(2^2+1^2+(-1)^2+(-2)^2=10\) for B. Their within-subject cross-product sum is \(1(2)+(-1)(1)+2(-1)+(-2)(-2)=3\). Therefore the combined meat is \(10+10+2(3)=26\). Omitting the cross-product would give \(20/64=0.3125\), an underestimate here because the net cross-transition covariance is positive. The direction of the error is not guaranteed; the cross-product could instead be negative.
Worked Example: A Contrast Between Two Transition Coefficients
Consider a hypothetical joint fit with two transition-specific coefficients, \(\hat\beta_1\) and \(\hat\beta_2\). Suppose the bread is \(11I\), where \(I\) is the two-by-two identity matrix, and the subject-level meat is
The off-diagonal entry records the summed cross-products of the two subject-level score coordinates. Since \(H^{-1}=(1/11)I\), the estimated covariance matrix is
For the contrast \(\hat\beta_1-\hat\beta_2\), its variance is the first variance plus the second variance minus twice their covariance. Keeping the exact fractions through the calculation gives
The estimated standard error is \(\sqrt{90/121}\approx 0.8624\), in the units of the coefficient contrast. If the covariance were incorrectly set to zero, the variance would instead be \((74+18)/121=92/121\approx0.7603\), with standard error \(\sqrt{92/121}\approx0.8720\). The difference is modest in this example, but it illustrates why a contrast’s uncertainty depends on cross-transition covariance. The covariance matrix also supports joint or simultaneous inference using the relevant multivariate procedures.
Worked Example: A Two-Parameter Sandwich With Correlated Scores
For a hypothetical two-parameter fit, suppose six subjects have the following total score vectors, each already summed across all transitions for that subject: \((2,1)^\mathsf{T},(-2,-1)^\mathsf{T},(1,1)^\mathsf{T},(-1,-1)^\mathsf{T},(1,-1)^\mathsf{T},(-1,1)^\mathsf{T}\). These vectors sum to zero. Suppose the total bread is \(H=\operatorname{diag}(8,6)\), which is nonsingular.
The meat is obtained by adding the six outer products. Pairing each vector with its negative doubles its outer product, so
Since \(H^{-1}=\operatorname{diag}(1/8,1/6)\), the covariance estimate is
The standard errors are \(\sqrt{0.1875}\approx0.4330\) and \(\sqrt{0.1667}\approx0.4082\). The estimated covariance, \(0.08333\), is positive. This calculation shows why the meat is a matrix: subject-level score coordinates can co-vary even when the bread is diagonal.
Implementation, Diagnostics, and Alternatives
A reliable implementation follows the unit of independent sampling. For each subject, collect all relevant transition score contributions, map them into the full parameter vector, add them, and take one outer product of the resulting vector. Add those outer products across subjects. Then sandwich this meat between the inverse total bread and its transpose. This order matters: summing outer products transition by transition discards the within-subject cross-products.
State the parameters and transition contributions, including how shared parameters are represented.
For each subject, sum the contribution vectors across transitions before forming an outer product.
Evaluate the negative derivative of the total estimating function and sum the subject-level score outer products.
Form the sandwich, verify its dimensions and numerical properties, and use its diagonal and off-diagonal entries for standard errors and contrasts.
Useful checks include confirming that subject-level score vectors sum to the score used in fitting, that every vector has the same parameter ordering, and that the bread is numerically invertible. The estimated covariance should be symmetric up to numerical rounding and positive semidefinite up to small numerical error. A failure of these checks can indicate a coding or parameter-mapping problem; a nearly singular bread can indicate weakly identified parameter combinations. Also verify that all records from a subject—including later transitions—are assigned to the same cluster.
The sandwich is not a universal correction. With few independent subjects, its large-sample approximation can be poor; a suitable finite-sample correction or a design-appropriate resampling method may be considered. It also cannot compensate for biased estimating equations, inadequate adjustment for the observation process, or incorrect identification of independent clusters. If subjects are dependent within a higher-level unit, such as a site, the independent unit used for the variance calculation must reflect that design.
| Approach | What it uses | Main limitation for multiple transitions |
|---|---|---|
| Model-based inverse information | The fitted likelihood’s assumed information structure | Can be unreliable if within-subject dependence or variance assumptions are wrong |
| Separate transition variances | Each transition model’s own variance estimate | Does not by itself provide cross-transition covariance for contrasts or joint inference |
| Subject-level sandwich | Observed variability of the full subject-level score vector | Requires valid subject-level estimating contributions and enough independent subjects for its approximation |
The earlier material on simultaneous inference for transition coefficients uses covariance information to assess multiple coefficients together. The subject-level sandwich supplies that information when a coefficient vector combines transition contributions: its off-diagonal entries should not be discarded merely because the coefficients refer to different transitions. Conversely, fitting transitions entirely separately may be appropriate for some analyses, but separate fits alone do not recover the cross-transition covariance needed for a joint contrast.
Common Mistakes
- Treating transition records as independent subjects. This loses within-subject cross-products. Aggregate a subject’s transition contributions first.
- Adding transition variances but omitting covariance. For a difference, the variance is \(\operatorname{Var}(\hat\beta_1)+\operatorname{Var}(\hat\beta_2)-2\operatorname{Cov}(\hat\beta_1,\hat\beta_2)\), not just the sum of the variances.
- Applying the sandwich to a misspecified mean model and assuming it fixes the estimate. Robust variance addresses covariance misspecification under valid estimating equations; it does not generally remove bias.
- Using the wrong cluster definition. If a subject contributes to several transitions, the subject is the cluster for this construction, not each transition row.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- Why are score contributions from two transitions belonging to one subject combined before their outer product is formed?
- For a scalar estimate with total bread \(H=5\) and subject-level scores \(1,-1,2,-2\), calculate the sandwich variance and standard error.
- If two coefficient variances are \(0.40\) and \(0.25\), and their covariance is \(-0.05\), calculate the variance of their difference.
- Name one condition a sandwich variance cannot repair.
Solutions. (1) Their outer product includes cross-products that represent within-subject dependence; separate outer products omit these terms. (2) The meat is \(1^2+(-1)^2+2^2+(-2)^2=10\). The variance is \(10/5^2=0.4000\), and the standard error is \(\sqrt{0.4000}\approx0.6325\). (3) The variance is \(0.40+0.25-2(-0.05)=0.75\). (4) Examples include a biased estimating equation, invalid risk sets, or unaddressed informative censoring.