Tutorials › Competing Risks and Multi-State Models › Sandwich Variance Across Transition Contributions

Regression for Multi-State Data · Tutorial 374 of 699

Sandwich Variance Across Transition Contributions

Learn to aggregate transition scores by subject, construct the sandwich covariance, and interpret its cross-transition terms.

Advanced 12 min read

What You'll Learn

  • Define subject-level score contributions by summing a subject’s contributions across transitions.
  • Derive the sandwich covariance from a Taylor expansion of the estimating equation.
  • Calculate robust variances while retaining within-subject covariance between transitions.
  • Compare the subject-level sandwich with model-based and transition-by-transition variance calculations.
  • Recognize assumptions and diagnostics relevant to a reliable sandwich estimate.

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.

Definition: Let \(\theta\) be a \(q\)-dimensional parameter vector and let \(U_{ik}(\theta)\) be subject \(i\)'s score or estimating-function contribution for transition \(k\). Define the subject-level contribution as \(U_i(\theta)=\sum_{k=1}^{K}U_{ik}(\theta)\), with all contributions expressed in the same \(q\)-dimensional parameterization. The total estimating function is \(U(\theta)=\sum_{i=1}^{n}U_i(\theta)\), and the estimate \(\hat\theta\) solves \(U(\hat\theta)=0\).

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.

$$ \widehat{\operatorname{Var}}(\hat\theta) = H(\hat\theta)^{-1} \left\{\sum_{i=1}^{n} U_i(\hat\theta)U_i(\hat\theta)^\mathsf{T}\right\} H(\hat\theta)^{-\mathsf{T}}. $$

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.

Assumptions: The independent sampling units are subjects, and their subject-level contributions are independent (or satisfy an appropriate large-sample dependence condition). The estimating equation is unbiased at the target parameter, its derivative has a nonsingular probability limit, and the usual smoothness and finite-moment conditions for a central limit theorem hold. The fitted model and observation process must also support valid estimating contributions—for example, censoring and observation mechanisms must be handled appropriately. A sandwich variance does not repair bias from a misspecified mean model, invalid risk sets, or informative censoring that has not been addressed.

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.

$$ 0 \approx U(\theta_0)-H(\theta_0)(\hat\theta-\theta_0), \qquad \hat\theta-\theta_0 \approx H(\theta_0)^{-1}\sum_{i=1}^{n}U_i(\theta_0). $$

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}\)
1123
2-110
32-11
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:

$$ M=3^2+0^2+1^2+(-4)^2=26. $$

Thus the estimated variance and standard error are

$$ \widehat{\operatorname{Var}}(\hat\theta)=\frac{26}{8^2} =\frac{26}{64}=0.40625, \qquad SE(\hat\theta)=\sqrt{0.40625}\approx 0.6374. $$

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

$$ M= \begin{pmatrix} 74 & 1\\ 1 & 18 \end{pmatrix}. $$

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

$$ \widehat{\operatorname{Var}} \begin{pmatrix}\hat\beta_1\\\hat\beta_2\end{pmatrix} = \frac{1}{121} \begin{pmatrix}74&1\\1&18\end{pmatrix}. $$

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

$$ \widehat{\operatorname{Var}}(\hat\beta_1-\hat\beta_2) = \frac{74}{121}+\frac{18}{121}-2\left(\frac{1}{121}\right) = \frac{90}{121} \approx 0.7438. $$

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

$$ M= 2\begin{pmatrix}4&2\\2&1\end{pmatrix} +2\begin{pmatrix}1&1\\1&1\end{pmatrix} +2\begin{pmatrix}1&-1\\-1&1\end{pmatrix} = \begin{pmatrix}12&4\\4&6\end{pmatrix}. $$

Since \(H^{-1}=\operatorname{diag}(1/8,1/6)\), the covariance estimate is

$$ H^{-1}MH^{-\mathsf{T}} = \begin{pmatrix} 12/64 & 4/48\\ 4/48 & 6/36 \end{pmatrix} = \begin{pmatrix} 0.1875 & 0.08333\\ 0.08333 & 0.1667 \end{pmatrix}. $$

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.

1
Specify the joint estimating equation.
State the parameters and transition contributions, including how shared parameters are represented.
2
Aggregate within subject.
For each subject, sum the contribution vectors across transitions before forming an outer product.
3
Calculate bread and meat.
Evaluate the negative derivative of the total estimating function and sum the subject-level score outer products.
4
Check and interpret.
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.

ApproachWhat it usesMain limitation for multiple transitions
Model-based inverse informationThe fitted likelihood’s assumed information structureCan be unreliable if within-subject dependence or variance assumptions are wrong
Separate transition variancesEach transition model’s own variance estimateDoes not by itself provide cross-transition covariance for contrasts or joint inference
Subject-level sandwichObserved variability of the full subject-level score vectorRequires 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.
Key takeaway: Preserve dependence by adding all transition score contributions within each independent subject before forming the meat. The sandwich combines that subject-level variability with the sensitivity of the estimating equation, producing standard errors and covariances for the full regression parameter vector.

Check Your Understanding

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

  1. Why are score contributions from two transitions belonging to one subject combined before their outer product is formed?
  2. For a scalar estimate with total bread \(H=5\) and subject-level scores \(1,-1,2,-2\), calculate the sandwich variance and standard error.
  3. If two coefficient variances are \(0.40\) and \(0.25\), and their covariance is \(-0.05\), calculate the variance of their difference.
  4. 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.

Clinical Biostats