In a previous post we looked at the properties of the ordinary least squares linear regression estimator when the covariates, as well as the outcome, are considered as random variables. In this post we’ll look at the theory sandwich (sometimes called robust) variance estimator for linear regression. See this post for details on how to use the sandwich variance estimator in R.
In the earlier post we assumed that , where is a column vector of regression coefficients to be estimated.
Using estimating equation theory, we showed that the estimator has variance
where denotes the matrix is equal to minus the derivative of the estimating function with respect to the parameter , denotes the variance covariance matrix of the estimating function, and denotes the true value of . We then found expressions for these population quantities, and estimators for them. We found that
and that this could be estimated by its empirical mean
The matrix was given as the variance of the estimating function
In the previous post, we then derived an expression for this assuming that the residuals have constant variance (as the covariates vary). Here we will relax that assumption, such that may have a variance that varies with . In this case, how might we estimate ? Since by assumption the residuals have mean zero conditional on , if subject has predictor values , remembering that the variance is the average squared deviation around the mean, we can estimate by the square of the estimated residual residual , i.e.
The matrix can then be estimated by taking the average of across the sample, substituting in place of the unknown (true) value:
An alternative route to getting to the same estimator is to directly estimate by its sample variance, and using the fact that the this estimating function has mean zero.
The variance estimator we have derived here is consistent irrespective of whether the residuals in the regression model have constant variance. It is called the sandwich variance estimator because of its form in which the B matrix is sandwiched between the inverse of the A matrix.
When we suspect, or find evidence on the basis of a test for heteroscedascity, that the variance is not constant, the standard OLS variance should not be used since it gives biased estimate of precision. A by-product of this is that p-values for hypothesis tests and confidence intervals, which use the estimated variance, will not perform as they should – the type I error rate may not be correct, and the coverage rate of the confidence intervals will in general not meet their nominal level.
In this case, the sandwich estimator we have derived here can be used. This is sometimes called the robust estimator of variance, since it is robust to non-constant residual variance. An alternative to using the robust sandwich variance estimator would be to use bootstrapping.
For more details on the robust sandwich variance estimator, and semiparametric methods more generally, I recommend Tsiatis’ book ’Semiparametric Theory and Missing Data’.