Why a Sandwich Appears
Many estimators are defined not by minimizing a stated loss, but by solving equations built from the observations. The sample mean solves a sample average equation; regression coefficients solve equations involving regressors and residuals; and other estimators can be specified by their own moment conditions. In each case, sampling uncertainty depends on two distinct features: how much the sample equations fluctuate, and how sensitively those equations respond to a change in the parameter.
The sandwich covariance combines those features. Its middle component measures the covariance of observation-level moment contributions. The two outer components account for the way a change in the parameter changes the equations. This formulation is useful when the estimator is defined through general moments, including when the variance of the observations is not constant.
The prime denotes transpose. Both \(A\) and \(B\) are \(p\times p\) matrices. The derivative matrix \(A\) is sometimes called the sensitivity matrix: it describes how the mean estimating function changes locally with \(\theta\). The matrix \(B\), sometimes called the variability or score-covariance matrix, describes the variation in the individual contributions. Here “score” is a general term for an estimating-function contribution; it need not be a likelihood score.
Deriving the Asymptotic Covariance
The sandwich result requires regularity conditions. The observations are independent and identically distributed; the target is an interior, well-defined root of the population moment equation; \(\psi\) is differentiable in a neighborhood of \(\theta_0\); and \(A\) is nonsingular. Assume also that the moment contributions have finite second moments, that a central limit theorem applies to their sample average, and that \(\hat{\theta}\) is consistent and solves the sample equations. Appropriate smoothness and integrability conditions are needed for the Taylor remainder to be negligible. These conditions support a local linear approximation and ensure that the resulting covariance is finite.
Write \(\bar{\psi}_n(\theta)=n^{-1}\sum_{i=1}^n\psi(W_i,\theta)\). Since \(\bar{\psi}_n(\hat{\theta})=0\), a Taylor expansion around \(\theta_0\) gives
where \(\hat{A}_n\) is an average derivative evaluated between \(\theta_0\) and \(\hat{\theta}\). Under the stated conditions, consistency and the law of large numbers imply \(\hat{A}_n\) converges in probability to \(A\), while the Taylor remainder is negligible at the \(n^{-1/2}\) scale. Rearranging yields the first-order approximation
The central limit theorem gives \(n^{-1/2}\sum_i\psi(W_i,\theta_0)\) an asymptotic normal distribution with mean zero and covariance \(B\). Multiplication by \(-A^{-1}\) on the left and its transpose on the right therefore gives the covariance below. The minus sign has no effect on covariance.
Thus the asymptotic covariance matrix of \(\hat{\theta}\), rather than of \(\sqrt{n}(\hat{\theta}-\theta_0)\), is approximately \(A^{-1}BA^{-T}/n\). The two appearances of the inverse derivative matrix are essential: one transforms fluctuations into parameter changes, and the other is the corresponding transformation on the covariance’s transposed side. In a scalar problem this reduces to \(B/(nA^2)\).
Estimating the Two Components
In practice, replace the population quantities with sample analogues evaluated at \(\hat{\theta}\). Define the observation-level fitted contribution \(\hat{\psi}_i=\psi(W_i,\hat{\theta})\). The empirical derivative and empirical moment covariance are
When these quantities converge to \(A\) and \(B\), respectively, the plug-in sandwich covariance estimate is
The factors of \(1/n\) follow from this convention: both \(\hat{A}\) and \(\hat{B}\) are averages, and the covariance of the estimator is the covariance of the scaled estimator divided by \(n\). One can instead define sums for the matrix components, but then the corresponding scaling must change consistently.
This is a general estimating-equation formula, not a rule that every problem must use exactly the same observation-level function. The moment condition determines \(\psi\), and its derivative and outer product must both be calculated from that same function. In applications, alternative consistent ways of estimating \(B\) may be available, but the empirical outer product above is the basic observation-by-observation estimator.
Worked Example: Sandwich Variance for a Sample Mean
Suppose four hypothetical measurements, in kilograms, are \(2,4,5,9\). Estimate their population mean using \(\psi(Y_i,\mu)=Y_i-\mu\), so the sample equation is \(\sum_i(Y_i-\hat{\mu})=0\). The observations are taken to be independent draws with finite variance, and this moment equation has the unique solution \(\hat{\mu}=\bar{Y}\).
The estimate is \(\hat{\mu}=(2+4+5+9)/4=5\) kg. The derivative of the observation-level moment with respect to \(\mu\) is \(-1\), so \(\hat{A}=-1\). The fitted contributions are \(-3,-1,0,4\) kg, giving
Therefore,
Here the derivative converts variation in the mean equation into variation in the estimated mean. Because its magnitude is one, it does not change the numerical value of the meat component; the remaining division by \(n=4\) converts the estimated covariance for the scaled estimator to an estimated variance for the sample mean.
Worked Example: A Ratio Estimator From One Moment Equation
Consider three hypothetical observations \((X_i,Y_i)=(1,2),(2,1),(1,4)\). Define \(\hat{\beta}\) by the sample moment equation \(\sum_i X_i(Y_i-\hat{\beta}X_i)=0\). Assume independent sampling, finite second moments for the estimating contributions, and \(E[X_i^2]>0\); these conditions allow the population root to be locally identified by this equation. This is an estimating-equation target, not automatically a causal effect.
Solving the equation gives
For \(\psi_i(\beta)=X_i(Y_i-\beta X_i)\), the derivative with respect to \(\beta\) is \(-X_i^2\). Hence \(\hat{A}=-(1+4+1)/3=-2\). The fitted contributions are \(2/3,-10/3,8/3\), whose sum is zero as required by the estimating equation. Thus
The sandwich estimate is
The standard error is in the units of \(Y\) per unit of \(X\), matching \(\hat{\beta}\). The larger the moment contributions fluctuate, the larger \(\hat{B}\) is; the derivative magnitude of two scales those fluctuations when translating them into changes in \(\hat{\beta}\).
Linear Regression as a Vector Example
For linear regression with an intercept and one regressor, let \(Z_i=(1,X_i)'\), let \(\theta=(\beta_0,\beta_1)'\), and use the moment contribution \(\psi_i(\theta)=Z_i(Y_i-Z_i'\theta)\). The two components of the sample equation set the sample residual sum and the regressor-weighted residual sum to zero. This example assumes independent observations and a nonsingular sample regressor cross-product matrix; the sandwich calculation does not require constant conditional variance.
Worked Example: A Two-Parameter Regression Sandwich
Take four hypothetical data points: \((X,Y)=(-1,0),(-1,2),(1,1),(1,9)\). The mean outcome at \(X=-1\) is \(1\), and at \(X=1\) is \(5\), so the fitted line has \(\hat{\beta}_0=3\) and \(\hat{\beta}_1=2\). Its residuals in the listed order are \(-1,1,-4,4\). Since the residuals sum to zero within each regressor group, both sample moment equations hold.
For this moment function, the derivative matrix is \(-Z_iZ_i'\). The average of \(Z_iZ_i'\) is the identity matrix: the average of \(X_i\) is zero and the average of \(X_i^2\) is one. Thus \(\hat{A}=-I\). The fitted moment contributions \(Z_i\hat{e}_i\) are \((-1,1)',(1,-1)',(-4,-4)',(4,4)'\). Their outer products average to
Since \((-I)^{-1}=-I\), the two outer factors leave \(\hat{B}\) unchanged, and division by \(n=4\) gives
The diagonal entries estimate the variances of the intercept and slope, and the off-diagonal entries estimate their covariance. The intercept variance is in squared outcome units; the slope variance is in squared units of outcome per unit of regressor. The nonzero covariance reflects the shared observation-level contributions to the two equations.
What the Sandwich Does and Does Not Do
The matrix \(B\) captures the empirical or population variability of the moment contributions without requiring a particular constant-variance model. In regression, for example, the contribution \(Z_i e_i\) varies with both the regressor and the residual. Its outer product therefore allows the contribution’s variability to differ across observations. The derivative matrix \(A\) is a separate ingredient: it is determined by the estimating equation’s response to the parameter, not by the size of the residual variation alone.
The sandwich estimates sampling uncertainty around the parameter defined by the moment condition. It does not, by itself, guarantee that the moment equation defines the scientific quantity of interest, that the model is correctly specified for every purpose, or that the estimator is unbiased in a finite sample. Its large-sample justification also depends on the sampling assumptions: independence across observations is part of the setup here, and other dependence structures require appropriate covariance estimation.
A reliable calculation follows the same sequence each time: specify the observation-level moment, identify the population root and assumptions, differentiate that moment with respect to the parameter, calculate each fitted contribution, and combine the empirical components with the correct scaling. This makes clear which part of the calculation reflects moment variability and which part reflects sensitivity.
Check Your Understanding
Use the definitions and formulas in this tutorial to answer the following questions.
- In the general sandwich formula, what does \(A\) measure, and what does \(B\) measure?
- Why does the covariance of \(\hat{\theta}\) have a factor of \(1/n\), while the asymptotic covariance of \(\sqrt{n}(\hat{\theta}-\theta_0)\) does not?
- For a scalar estimating equation, explain why the variance estimate contains \(A^{-2}\), rather than just \(A^{-1}\).
- At an exact solution to the sample equations, the fitted contributions sum to zero. Explain why their average outer product need not be zero.
- For the regression example, which matrix component accounts for the association between the intercept and slope contributions?