Tutorials › Statistical Genetics › Sandwich Standard Errors for Genetic Association

Covariates, Missingness, and Robust Inference · Tutorial 329 of 989

Sandwich Standard Errors for Genetic Association

Learn to construct and interpret heteroskedasticity-robust standard errors for linear and logistic genetic association models.

Intermediate 9 min read

What You'll Learn

  • Write linear and logistic association estimating equations and identify their bread and meat matrices.
  • Derive HC0 sandwich variance estimates for quantitative-trait regression.
  • Calculate a logistic sandwich standard error for a binary genotype contrast.
  • Compare robust and model-based standard errors under their respective variance assumptions.
  • Identify why sandwich standard errors do not correct a misspecified mean model or dependent observations.

Why Use Sandwich Standard Errors?

A genetic association regression estimates the relationship between a phenotype and genotype, often while adjusting for covariates. The fitted coefficient describes the association under the specified regression model. Its standard error, however, also depends on assumptions about how outcomes vary around that model. For a quantitative trait, the usual linear-regression standard error assumes a common residual variance. If residual variability instead changes with genotype or covariates, that standard error can be inaccurate even when the conditional mean is modeled correctly.

A sandwich standard error estimates uncertainty using two ingredients: how responsive the estimating equation is to changes in the coefficients, and how variable the individual observations’ contributions to that equation are. This construction applies to both linear and logistic association models. Its validity still depends on important conditions, particularly independent observations and a suitable mean model.

Definition and General Form

Definition: Let \(\psi_i(\beta)\) be individual \(i\)'s contribution to an estimating equation, with estimate \(\hat{\beta}\) satisfying \(\sum_{i=1}^n \psi_i(\hat{\beta})=0\). Define the sensitivity matrix \(A\) as the negative expected derivative of an individual contribution, \(A=-E\{\partial\psi_i(\beta)/\partial\beta^\mathsf{T}\}\), evaluated at the target coefficient, and define \(B=\operatorname{Var}\{\psi_i(\beta)\}\). For independent individuals, the large-sample covariance of \(\hat{\beta}\) is \(n^{-1}A^{-1}B(A^{-1})^\mathsf{T}\). Its empirical sandwich estimate uses the corresponding sample sensitivity and the sum of individual outer products of contributions.

The two matrices have distinct roles. The bread describes how much the estimating equation changes when the coefficient changes; the meat records the variability of the individual contributions. In ordinary regression examples, the bread is symmetric, so the expression is often written with the bread on both sides without showing a transpose. The general formula includes the transpose: a covariance matrix must be symmetric, and an arbitrary sensitivity matrix need not be symmetric.

In finite-sample notation, let \(\hat{A}=-\sum_i \partial\psi_i(\hat{\beta})/\partial\beta^\mathsf{T}\) and \(\hat{B}=\sum_i\psi_i(\hat{\beta})\psi_i(\hat{\beta})^\mathsf{T}\). The empirical covariance estimate is \(\hat{A}^{-1}\hat{B}(\hat{A}^{-1})^\mathsf{T}\). This is commonly called the HC0 sandwich estimate in regression settings. It is a large-sample variance estimator, not a guarantee of accurate inference in a small sample.

Linear Association Regression

For individual \(i\), let \(Y_i\) be a quantitative trait and let \(x_i\) be a \(p\)-dimensional column vector containing an intercept, genotype coding, and any included covariates. The linear mean model is \(E(Y_i\mid x_i)=x_i^\mathsf{T}\beta\). The genotype coefficient is interpreted in the units of \(Y_i\) per unit of the chosen genotype coding, conditional on the included covariates.

The OLS estimator solves \(\sum_i x_i(Y_i-x_i^\mathsf{T}\beta)=0\). Its individual contribution is \(\psi_i(\beta)=x_i(Y_i-x_i^\mathsf{T}\beta)\). Differentiating gives \(-x_ix_i^\mathsf{T}\), so the empirical bread is \(X^\mathsf{T}X\), where \(X\) has rows \(x_i^\mathsf{T}\). The meat is \(\sum_i x_ix_i^\mathsf{T}\hat{e}_i^2\), where \(\hat{e}_i=Y_i-x_i^\mathsf{T}\hat{\beta}\). Thus:

$$ \widehat{\operatorname{Var}}_{\mathrm{HC0}}(\hat{\beta}) =(X^\mathsf{T}X)^{-1} \left(\sum_{i=1}^n x_ix_i^\mathsf{T}\hat{e}_i^2\right) (X^\mathsf{T}X)^{-1}. $$

Here the bread is symmetric, which is why the final factor can be written without a transpose. The diagonal element for the genotype coefficient estimates its variance; its square root is the sandwich standard error. The formula requires a full-rank design matrix. For consistency, the linear conditional mean must be appropriate, observations must be independent, and the data must have suitable finite moments. The key advantage over the conventional variance is that the error variance need not be constant across \(x_i\).

Under the stronger homoskedastic model, \(\operatorname{Var}(Y_i\mid x_i)=\sigma^2\), the model-based covariance is estimated by \(s^2(X^\mathsf{T}X)^{-1}\), where \(s^2=\sum_i\hat{e}_i^2/(n-p)\). If the conditional variance is constant, the expected meat is proportional to the bread, and the robust and model-based estimates target the same large-sample covariance. If conditional variances differ, the model-based formula generally misses that pattern; the sandwich estimates it through the squared residuals and design vectors.

Worked Example: Robust Versus Model-Based Linear Standard Error

Suppose a hypothetical sample has four unrelated individuals, genotype dosages \(G=(0,1,2,0)\), and quantitative trait values \(Y=(1,3,4,2)\). Fit an intercept-and-dosage model. These deliberately small data illustrate the arithmetic; they are not adequate for reliable large-sample inference.

The design matrix has rows \((1,G_i)\), and \(X^\mathsf{T}X=\begin{pmatrix}4&3\\3&5\end{pmatrix}\). The sample means are \(\bar{G}=0.75\) and \(\bar{Y}=2.5\). The OLS dosage slope is \(\sum_i(G_i-\bar{G})(Y_i-\bar{Y})/\sum_i(G_i-\bar{G})^2=3.5/2.75=1.2727\); the intercept is \(2.5-(1.2727)(0.75)=1.5455\). The fitted residuals, in the given order, are \((-6/11,\,2/11,\,-1/11,\,5/11)\).

The inverse bread is \((X^\mathsf{T}X)^{-1}=\frac{1}{11}\begin{pmatrix}5&-3\\-3&4\end{pmatrix}\). The meat is \(\sum_i x_ix_i^\mathsf{T}\hat{e}_i^2=\frac{1}{121}\begin{pmatrix}66&6\\6&8\end{pmatrix}\). For the dosage slope, the relevant row of the inverse bread is \((-3,4)/11\). Therefore, \(\widehat{\operatorname{Var}}_{\mathrm{HC0}}(\hat{\beta}_G)=578/14641=0.03948\), and the HC0 standard error is \(\sqrt{0.03948}=0.1987\) trait units per dosage unit.

For comparison, the residual sum of squares is \((36+4+1+25)/121=66/121=0.5455\). With \(n-p=2\), \(s^2=0.5455/2=0.2727\). The model-based slope variance is \(s^2/2.75=0.09917\), giving a standard error of \(0.3149\) trait units per dosage unit. The numerical difference illustrates that the two formulas use different variance assumptions; this tiny example does not establish which assumption is appropriate for any real study.

Logistic Association Regression

For a binary trait \(Y_i\in\{0,1\}\), the logistic mean model specifies \(P(Y_i=1\mid x_i)=p_i\), with \(\operatorname{logit}(p_i)=x_i^\mathsf{T}\beta\). The coefficient for genotype is a conditional log odds ratio per unit of the genotype coding, when the other covariates are held fixed. The individual score contribution is \(\psi_i(\beta)=x_i(Y_i-p_i)\). Its negative derivative is \(p_i(1-p_i)x_ix_i^\mathsf{T}\), giving bread \(\sum_i p_i(1-p_i)x_ix_i^\mathsf{T}\) at the fitted values. The empirical meat is \(\sum_i x_ix_i^\mathsf{T}(Y_i-\hat{p}_i)^2\).

$$ \widehat{\operatorname{Var}}_{\mathrm{sand}}(\hat{\beta}) =\hat{A}^{-1}\hat{B}(\hat{A}^{-1})^\mathsf{T},\quad \hat{A}=\sum_i\hat{p}_i(1-\hat{p}_i)x_ix_i^\mathsf{T},\quad \hat{B}=\sum_i x_ix_i^\mathsf{T}(Y_i-\hat{p}_i)^2. $$

For an independent Bernoulli outcome with a correctly specified conditional probability, the conditional variance is \(p_i(1-p_i)\). Consequently, \(E\{(Y_i-p_i)^2\mid x_i\}=p_i(1-p_i)\), so the expected meat equals the expected bread. This explains why the robust and usual model-based logistic covariance estimates are asymptotically equivalent under the correctly specified independent Bernoulli model. The robust form is useful when the variance or likelihood assumptions used for model-based inference are not trusted, but it does not make a wrong conditional mean correct. If that mean is misspecified, the coefficient may target a best-fitting, model-dependent value rather than the intended association parameter.

Worked Example: Logistic Sandwich for a Binary Genotype Contrast

Imagine eight hypothetical unrelated individuals, split equally between \(G=0\) and \(G=1\). Among the four with \(G=0\), one has \(Y=1\); among the four with \(G=1\), three have \(Y=1\). Fit a logistic model with intercept and binary genotype indicator. The two fitted probabilities are the observed group proportions, \(0.25\) and \(0.75\). The intercept is \(\log(0.25/0.75)=-\log 3\), and the genotype coefficient is \(\log(0.75/0.25)-(-\log 3)=2\log 3=\log 9=2.197\). The estimated odds ratio comparing \(G=1\) with \(G=0\) is \(9\).

For each group, the sum of fitted-mean weights \(p_i(1-p_i)\) is \(4(0.25)(0.75)=0.75\). Thus the bread is \(\hat{A}=0.75\begin{pmatrix}1&0\\0&0\end{pmatrix}+0.75\begin{pmatrix}1&1\\1&1\end{pmatrix}=\begin{pmatrix}1.5&0.75\\0.75&0.75\end{pmatrix}\). Within either group, the residual sum of squares is \(1(0.75)^2+3(0.25)^2=0.75\) (the three and one outcomes exchange roles across groups). Hence the meat is the same matrix, \(\hat{B}=\begin{pmatrix}1.5&0.75\\0.75&0.75\end{pmatrix}\).

Its inverse is \(\begin{pmatrix}4/3&-4/3\\-4/3&8/3\end{pmatrix}\). Since \(\hat{B}=\hat{A}\), the sandwich covariance is \(\hat{A}^{-1}\), and the genotype-coefficient standard error is \(\sqrt{8/3}=1.633\) log-odds units. In this constructed example the robust and model-based estimates coincide. The small sample and large standard error caution against treating the calculation as dependable evidence about an association.

Why the Transpose Matters

The sandwich form is not merely a convenient way to write a variance. Its matrix order follows from propagating the variability of the estimating equation through the coefficient estimator. Linearizing the estimating equation around its target gives a coefficient error approximately equal to the inverse sensitivity times the average contribution. Taking the covariance of that expression places the transpose on the second inverse:

$$ \hat{\beta}-\beta \ \approx\ A^{-1}\frac{1}{n}\sum_i\psi_i(\beta), \qquad \operatorname{Var}(\hat{\beta})\ \approx\ \frac{1}{n}A^{-1}B(A^{-1})^\mathsf{T}. $$

For example, suppose an estimating system has \(A=\begin{pmatrix}1&1\\0&1\end{pmatrix}\) and \(B=I\), the two-dimensional identity matrix. Then \(A^{-1}=\begin{pmatrix}1&-1\\0&1\end{pmatrix}\), and the covariance calculation is \(A^{-1}B(A^{-1})^\mathsf{T}=\begin{pmatrix}2&-1\\-1&1\end{pmatrix}\). It is symmetric, as a covariance matrix must be. Omitting the transpose would give \(\begin{pmatrix}1&-2\\0&1\end{pmatrix}\), which is not symmetric and cannot be a covariance matrix. In the OLS and logistic examples above, the bread is symmetric, so the transpose does not change the displayed regression formula.

Worked Example: Checking a General Sandwich Calculation

Use the nonsymmetric sensitivity matrix and identity meat from the preceding calculation. The inverse is \(C=A^{-1}=\begin{pmatrix}1&-1\\0&1\end{pmatrix}\). First multiply \(CB=C\). Then multiply by \(C^\mathsf{T}=\begin{pmatrix}1&0\\-1&1\end{pmatrix}\): \(CB C^\mathsf{T}=\begin{pmatrix}1&-1\\0&1\end{pmatrix}\begin{pmatrix}1&0\\-1&1\end{pmatrix}=\begin{pmatrix}2&-1\\-1&1\end{pmatrix}\).

The off-diagonal entries match, and the matrix is positive definite: its upper-left entry is \(2>0\), and its determinant is \(2(1)-(-1)^2=1>0\). By contrast, the expression \(CBC\) is \(\begin{pmatrix}1&-2\\0&1\end{pmatrix}\), which is not symmetric. This check is especially useful when working with estimating equations whose sensitivity matrix is not symmetric.

Assumptions, Limitations, and Common Mistakes

A sandwich standard error concerns uncertainty under the chosen estimating equation; it is not a general repair for an association analysis. In the linear model, the robust covariance protects against nonconstant conditional residual variance when the conditional mean is correctly specified. In logistic regression with independent Bernoulli observations, the model-based and sandwich forms agree asymptotically if the probability model is correct. In either setting, the usual individual-level sandwich assumes independent observations and adequate sample information for large-sample approximation. In particular, it does not account for dependence among relatives; that requires a method that treats the dependence appropriately.

Robust standard errors also do not remove confounding, correct an inappropriate genotype coding, fix selection bias, or resolve bias from missing data. Nor do they compensate for a misspecified mean relationship between phenotype, genotype, and covariates. A robust standard error can quantify uncertainty around the coefficient estimated by the fitted model while that coefficient remains a poor estimate of the scientific target.

  • Mistake: “Robust” means robust to any model failure. The correction is that sandwich variance estimates address specified forms of variance misspecification under their sampling assumptions. They do not fix a wrong mean model or dependence between observations.
  • Mistake: Dropping the transpose in the general formula. The correction is to use \(A^{-1}B(A^{-1})^\mathsf{T}\). Writing \(A^{-1}BA^{-1}\) is justified in these regression formulas because their bread matrix is symmetric, not as a general rule.
  • Mistake: Treating HC0 as a small-sample guarantee. The correction is that HC0 is a large-sample estimator; it can perform poorly with few observations or influential design points. Variants such as HC1 multiply the HC0 covariance by \(n/(n-p)\) in OLS, a finite-sample adjustment that does not make it exact.
Key takeaway: Sandwich standard errors combine sensitivity of the estimating equation with empirical variability of individual contributions. Use the model-based comparison to understand which variance assumptions are being relaxed, and always check the mean model and independence assumptions separately.

Check Your Understanding

Answer each question using the model assumptions and notation introduced above.

  1. In an OLS association model, what does the meat matrix estimate, and how does it enter the HC0 covariance estimate?
  2. Under what condition does the linear model-based variance \(s^2(X^\mathsf{T}X)^{-1}\) have the same large-sample target as the sandwich variance?
  3. For an independent, correctly specified Bernoulli logistic model, why do the expected meat and bread agree?
  4. Why must the general sandwich covariance include a transpose on the second inverse sensitivity matrix?
  5. Name two problems that a sandwich standard error does not correct in a genetic association analysis.
Clinical Biostats