Robust regression inference and Sandwich estimators

Can you give me an example of the use of sandwich estimators in order to perform robust regression inference?

I can see the example in ?sandwich, but I don't quite understand how we can go from lm(a ~ b, data) (-coded) to an estimate and a p value resulting from a regression model using the variance-covariance matrix returned by the function sandwich.

• have you been through the examples in the associated vignette? – user603 Nov 18 '13 at 18:08
• (1) Link works for me. (2) Is this an r coding question? How to get the Huber-White SE after fitting a model. Or something else? – charles Nov 18 '13 at 23:09
• @charles 1) Indeed it works! Don't know what happened before. Yes it is an R coding question. 2) I don't know what are the Huber-White Standard Error and don't know how to compute them right now. Thanks for your help! – Remi.b Nov 19 '13 at 7:56
• You get p-values & standard errors in the same way as usual, substituting the sandwich estimate of the variance-covariance matrix for the least-squares one. – Scortchi - Reinstate Monica Nov 19 '13 at 11:20
• @Scortchi Ok. And once I have these estimates (OLS or sandwich estimates) what can I do with them? – Remi.b Nov 19 '13 at 11:37

I think there are a few approaches. I haven't looked at them all and not sure which is the best:

1. The sandwich package:

library(sandwich)
coeftest(model, vcov=sandwich)


But this doesn't give me the same answers I get from Stata for some reason. I've never tried to work out why, I just don't use this package.

1. The rms package: I find this a bit of a pain to work with but usually get good answers with some effort. And it is the most useful for me.

model = ols(a~b, x=TRUE)
robcov(model)

2. You can code it from scratch (see this blog post). It looks like the most painful option, but remarkably easy and this option often works the best.

A simple / quick explanation is that Huber-White or Robust SE are derived from the data rather than from the model, and thus are robust to many model assumptions. But as always, a quick Google search will lay this out in excruciating detail if you're interested.

• You should really see this answer here: stats.stackexchange.com/a/117066/12053 – chandler Oct 1 '16 at 12:23
• It like how this answers implictly assumes that there is something wrong with R, because you get different results than Stata. For people who know how the sandwich estimators works, the difference is obvious and easy to remedy. For people who dont know, just please read the vignette (guide) which ships with the package – Repmat May 18 '18 at 6:40

One can use an alternative summary function to perform a robust regression.

lm.object <- lm(a~b+c)
summary(lm.object, robust=TRUE)


To obtain robust standard errors you set the parameter ''robust'' in your summary function to TRUE.

The following blog entry provides the function and a detailed description of the function: https://economictheoryblog.com/2016/08/08/robust-standard-errors-in-r