Difference between revisions of "R robust se"

From ECLR
Jump to: navigation, search
Line 4: Line 4:
  
 
There are a number of pieces of code available to facilitate this task. Here I recommend to use the [http://cran.r-project.org/web/packages/sandwich/index.html "sandwich" package]. Which has the most comprehensive robust standard error options I am aware of.
 
There are a number of pieces of code available to facilitate this task. Here I recommend to use the [http://cran.r-project.org/web/packages/sandwich/index.html "sandwich" package]. Which has the most comprehensive robust standard error options I am aware of.
 +
 +
As described in more detail in [[R_Packages]] you should install the package the first time you use it on a particular computer:
 +
 +
    install.packages("sandwich")
 +
 +
and then call the package at the beginning of your script into the library:
 +
 +
    library(sandwich)
 +
 +
All code snippets below assume that you have done so.
  
 
== Heteroskedasticity robust standard errors ==
 
== Heteroskedasticity robust standard errors ==
  
I assume that you know that the presence of heteroskedastic standard errors renders OLS estimators of linear regression models inefficient (although they remain unbiased). More seriously, however, they also imply that the usual standard errors that are computed for your coefficient estimates (e.g. The <source enclose=none>summary()</source> as discussed in [[R_Regression]])
+
I assume that you know that the presence of heteroskedastic standard errors renders OLS estimators of linear regression models inefficient (although they remain unbiased). More seriously, however, they also imply that the usual standard errors that are computed for your coefficient estimates (e.g. when you use the <source enclose=none>summary()</source> command as discussed in [[R_Regression]]), are incorrect (or sometimes we call them biased). This implies that inference based on these standard errors will be incorrect (incorrectly sized). What we need are coefficient estimate standard errors that are correct even when regression error terms are heteroskedastic.
  
 
== Autocorrelation and heteroskedasticity robust standard errors ==
 
== Autocorrelation and heteroskedasticity robust standard errors ==

Revision as of 20:54, 5 April 2015

Here we briefly discuss how to estimate robust standard errors for linear regression models

Which package to use

There are a number of pieces of code available to facilitate this task. Here I recommend to use the "sandwich" package. Which has the most comprehensive robust standard error options I am aware of.

As described in more detail in R_Packages you should install the package the first time you use it on a particular computer:

   install.packages("sandwich")

and then call the package at the beginning of your script into the library:

   library(sandwich)

All code snippets below assume that you have done so.

Heteroskedasticity robust standard errors

I assume that you know that the presence of heteroskedastic standard errors renders OLS estimators of linear regression models inefficient (although they remain unbiased). More seriously, however, they also imply that the usual standard errors that are computed for your coefficient estimates (e.g. when you use the summary() command as discussed in R_Regression), are incorrect (or sometimes we call them biased). This implies that inference based on these standard errors will be incorrect (incorrectly sized). What we need are coefficient estimate standard errors that are correct even when regression error terms are heteroskedastic.

Autocorrelation and heteroskedasticity robust standard errors

Footnotes