11
$\begingroup$

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.

$\endgroup$
10
  • $\begingroup$ have you been through the examples in the associated vignette? $\endgroup$
    – user603
    Commented Nov 18, 2013 at 18:08
  • $\begingroup$ (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? $\endgroup$
    – charles
    Commented Nov 18, 2013 at 23:09
  • $\begingroup$ @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! $\endgroup$
    – Remi.b
    Commented Nov 19, 2013 at 7:56
  • $\begingroup$ 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. $\endgroup$ Commented Nov 19, 2013 at 11:20
  • $\begingroup$ @Scortchi Ok. And once I have these estimates (OLS or sandwich estimates) what can I do with them? $\endgroup$
    – Remi.b
    Commented Nov 19, 2013 at 11:37

2 Answers 2

9
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ You should really see this answer here: stats.stackexchange.com/a/117066/12053 $\endgroup$
    – chandler
    Commented Oct 1, 2016 at 12:23
  • 2
    $\begingroup$ 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 $\endgroup$
    – Repmat
    Commented May 18, 2018 at 6:40
11
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.