Learn R Programming

⚠️There's a newer version (3.1-1) of this package.Take me there.

Robust Covariance Matrix Estimators

Model-robust standard error estimators for cross-sectional, time series, clustered, panel, and longitudinal data. Modular object-oriented implementation with support for many model objects, including: lm, glm, fixest, survreg, coxph, mlogit, polr, hurdle, zeroinfl, and beyond.

Sandwich covariances for general parametric models:

Object-oriented implementation in R:

library("sandwich")
library("lmtest")
data("PetersenCL", package = "sandwich")
m <- lm(y ~ x, data = PetersenCL)
coeftest(m, vcov = sandwich)
## t test of coefficients:
## 
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.0297     0.0284    1.05      0.3    
## x             1.0348     0.0284   36.45   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coeftest(m, vcov = vcovCL, cluster = ~ firm)
## t test of coefficients:
## 
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.0297     0.0670    0.44     0.66    
## x             1.0348     0.0506   20.45   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Copy Link

Version

Install

install.packages('sandwich')

Monthly Downloads

199,115

Version

3.1-0

License

GPL-2 | GPL-3

Maintainer

Last Published

December 11th, 2023

Functions in sandwich (3.1-0)

vcovBS

(Clustered) Bootstrap Covariance Matrix Estimation
vcovCL

Clustered Covariance Matrix Estimation
meat

A Simple Meat Matrix Estimator
vcovHC

Heteroscedasticity-Consistent Covariance Matrix Estimation
vcovHAC

Heteroscedasticity and Autocorrelation Consistent (HAC) Covariance Matrix Estimation
sandwich

Making Sandwiches with Bread and Meat
vcovPC

Panel-Corrected Covariance Matrix Estimation
vcovPL

Clustered Covariance Matrix Estimation for Panel Data
vcovJK

(Clustered) Jackknife Covariance Matrix Estimation
vcovOPG

Outer-Product-of-Gradients Covariance Matrix Estimation
weightsAndrews

Kernel-based HAC Covariance Matrix Estimation
weightsLumley

Weighted Empirical Adaptive Variance Estimation
isoacf

Isotonic Autocorrelation Function
InstInnovation

Innovation and Institutional Ownership
PetersenCL

Petersen's Simulated Data for Assessing Clustered Standard Errors
PublicSchools

US Expenditures for Public Schools
Investment

US Investment Data
estfun

Extract Empirical Estimating Functions
bread

Bread for Sandwiches
NeweyWest

Newey-West HAC Covariance Matrix Estimation
lrvar

Long-Run Variance of the Mean
kweights

Kernel Weights