Robust Covariance Matrix Estimators

Object-oriented software for model-robust covariance matrix estimators. Starting out from the basic robust Eicker-Huber-White sandwich covariance methods include: heteroscedasticity-consistent (HC) covariances for cross-section data; heteroscedasticity- and autocorrelation-consistent (HAC) covariances for time series data (such as Andrews' kernel HAC, Newey-West, and WEAVE estimators); clustered covariances (one-way and multi-way); panel and panel-corrected covariances; outer-product-of-gradients covariances; and (clustered) bootstrap covariances. All methods are applicable to (generalized) linear model objects fitted by lm() and glm() but can also be adapted to other classes through S3 methods. Details can be found in Zeileis et al. (2020) , Zeileis (2004) and Zeileis (2006) .


Changes in Version 2.5-1

o In various vcov*() functions assuring that the variance-covariance matrix is positive-definite (via fix=TRUE) erroneously dropped the dimnames. Now these are properly preserved. (Reported by Joe Ritter.)

o Added suppressWarnings(RNGversion("3.5.0")) in those places where set.seed() was used to assure exactly reproducible results from R 3.6.0 onwards.

Changes in Version 2.5-0

o Enhanced vignette("sandwich-CL", package = "sandwich") by better describing the background of clustered covariances and being more precise in the mathematical notation. Documentation for the new features (see below, e.g., the formula cluster specification and the vcovBS() methods) has been added.

o In vcovCL(), vcovPL(), vcovPC(), and vcovBS(), the "cluster" argument (and potentially also "") can be specified by a formula - provided that expand.model.frame(x, cluster) works for the model object x.

o The "cluster" and/or "" are processed accordingly if observations were dropped in the NA processing of the model object x (provided x$na.action is available).

o New dedicated vcovBS() method for "lm" objects that (a) provides many more bootstrapping techniques applicable to linear models (e.g., residual-based or wild bootstrap), (b) computes the bootstrap coefficients more efficiently with or qr.coef() rather than update().

o New dedicated vcovBS() method for "glm" objects that uses "xy" bootstrap like the default method but uses instead of update() and hence is slightly faster.

o All vcovBS() methods (default, glm, and lm) facilitate parallel bootstrapping by changing the "applyfun" from the default lapply(). By setting "cores" parallel::parLapply (on Windows) or parallel::mclapply() (otherwise) are used.

o Default handling of missing parameter estimates in vcovBS() changed from "everything" to "pairwise.complete.obs" and allow modification of cov(..., use = ...). This is relevant if not all parameters can be re-estimated on the bootstrap samples, e.g., for dummy variables of relatively rare events.

o Fix of a bug in vcovHC.mlm (reported by James Pustejovsky). The off-diagonal values of the vcovHC were computed without preserving the sign of the underlying residuals. This issue did not affect the diagonal because the underlying cross product amounts to squaring all values - but it does matter for the off-diagonal. Also, type="const" was disabled in this scenario and vcov(...) is simply used instead of vcovHC(..., type = "const").

o Bug fix in vcovCL/meatCL for multi-way clustering (reported by Brian Tsay). If patterns of levels in one clustering variable also occured in another clustering variable, their interactions were sometimes not computed correctly.

o In vcovCL() for multi-way clustering without cluster adjustment, all cluster adjustment factors are omitted entirely. In previous versions they were scaled with (Gmin - 1)/Gmin, where Gmin is the minimal number of clusters across clustering dimensions.

o meatHC() and meatHAC() now pass their "..." argument to estfun(), just as meatCL(), meatPL(), and meatPC() do as well.

Changes in Version 2.4-0

o Various flavors of clustered sandwich estimators in vcovCL(), panel sandwich estimators in vcovPL(), and panel-corrected estimators a la Beck & Katz in vcovPC(). The new vignette("sandwich-CL", package = "sandwich") introduces all functions and illustrates their use and properties.

o The new function vcovBS() provides a basic (clustered) bootstrap covariance matrix estimate, using case-based resampling.

Changes in Version 2.3-4

o In meatHAC(), bwAndrews(), and bwNeweyWest() it is now assured that the estfun is transformed to a plain matrix. Otherwise for time series regression with irregular zoo data, the bandwidth estimation might have failed.

o In meatHC() it is now assured that the residuals are zero in observations where all regressors and all estimating functions are zero.

Changes in Version 2.3-3

o Now the default methods of vcovHC() and vcovHAC() are also correctly registered as S3 methods in the NAMESPACE.

o Corrected errors in Equation 3 of vignette("sandwich"). The equation incorrectly listed the error terms "u" instead of the observations "y" on the right-hand side (pointed out by Karl-Kuno Kunze).

Changes in Version 2.3-2

o sandwich(), vcovHC(), and vcovHAC() did not work when models were fitted with na.action = na.exclude because the estfun() then (correctly) preserved the NAs. This is now avoided and all functions handle the na.exclude case like the na.omit case. (Thanks to John Fox for spotting the problem and suggesting the solution.)

Changes in Version 2.3-1

o The estfun() methods for "survreg" and "coxph" objects incorrectly returned the unweighted estimating functions in case the objects were fitted with weights. Now the weights are properly extracted and used.

Changes in Version 2.3-0

o Updated Depends/Imports: Package "zoo" is only in Imports now.

Changes in Version 2.2-10

o Added estfun() and bread() methods for ordered response models from MASS::polr and ordinal::clm.

o Added output of examples and vignettes as for R CMD check.

Changes in Version 2.2-9

o Added convenience function lrvar() to compute the long-run variance of the mean of a time series: a simple wrapper for kernHAC() and NeweyWest() applied to lm(x ~ 1).

o lm/mlm/glm models with aliased parameters were not handled correctly (leading to errors in sandwich/vcovHC etc.), fixed now.

o An improved error message is issued if prewhitening in vcovHAC() cannot work due to collinearity in the estimating functions.

Changes in Version 2.2-8

o fixed a bug in bwNeweyWest() for "mlm" objects that only have an intercept.

Changes in Version 2.2-7

o HC4m and HC5 estimators, as suggested by Cribari-Neto and coauthors, have been added to vcovHC() and related functions.

Changes in Version 2.2-6

o bug fix in estfun() method for "survreg" objects

Changes in Version 2.2-5

o estfun() methods for "hurdle"/"zeroinfl" objects can now handle multiple offset vectors (if any)

Changes in Version 2.2-4

o new vcovHC() method for "mlm" objects. This simply combines the "meat" for each individual regression and combines the result.

Changes in Version 2.2-3

o new bread() method for "mlm" objects.

Changes in Version 2.2-2

o updates in estfun() methods for hurdle/zeroinfl objects.

Changes in Version 2.2-1

o documentation enhancements for new Rd parser.

Changes in Version 2.2-0

o added/enhanced bread() and estfun() methods for "rlm" and "mlogit" objects (from MASS and mlogit, respectively).

o made vcovHC() and vcovHAC() generic with previous function definitions as default methods.

o updated vignettes (in particular using the more convenient tobit() interface from the AER package).

Changes in Version 2.1-0

o added bread() and estfun() methods for "hurdle"/"zeroinfl" objects as computed by hurdle()/zeroinfl() in package "pscl".

o fixed bread() and estfun() methods for negative binomial "glm" objects: now dispersion = 1 is used.

Changes in Version 2.0-3

o bread() method for "lm" objects now calls summary.lm() explicitely (rather than the generic) so that it also works with "aov" objects.

Changes in Version 2.0-2

o Added new vcovOPG() function for computing the outer product of gradients estimator (works for maximum likelihood estfun() methods only).

o Scaled estfun() and bread() method for "glm" objects by dispersion estimate. Hence, this corresponds to maximum likelihood and not deviance methods.

Changes in Version 2.0-1

o Minor fix to bwAndrews() so that it can be easily used in models for multivariate means.

Changes in Version 2.0-0

o A paper based on the "sandwich-OOP" vignette was accepted for publication in volume 16(9) of Journal of Statistical Software at

o A NAMESPACE was added for the package.

Changes in Version 1.9-0

o The vignette "sandwich-OOP" has been revised, extended and released as a technical report.

o Several estfun() methods and some of the meat() functions have been enhanced and made more consistent.

Changes in Version 1.1-1

o estfun() methods now use directly the model.matrix() method instead of the terms() and model.frame() methods.

Changes in Version 1.1-0

o sandwich is made object-oriented, so that various types of sandwich estimators can be computed not only for "lm" models, but also "glm", "survreg", etc. To achieve object orientation this various changes have been made: a sandwich() function is provided which needs a bread and a meat matrix. For the bread, a generic bread() function is provided, for the meat, there are meat(), meatHC() and meatHAC(). All rely on the existence of a estfun() method.

o vcovHC() and vcovHAC() have been restructured to use sandwich() together with meatHC() and meatHAC(), respectively.

o A new vignette "sandwich-OOP" has been added, explaining the new object-orientation features.

o Various methods to bread() and estfun() have been added, particularly for "survreg" and "coxph".

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


3.0-1 by Achim Zeileis, 7 months ago

Report a bug at

Browse source code at

Authors: Achim Zeileis [aut, cre] , Thomas Lumley [aut] , Nathaniel Graham [ctb] , Susanne Koell [ctb]

Documentation:   PDF Manual  

Task views: Econometrics, Empirical Finance, Robust Statistical Methods, Statistics for the Social Sciences

GPL-2 | GPL-3 license

Imports stats, utils, zoo

Suggests AER, car, geepack, lattice, lmtest, MASS, multiwayvcov, parallel, pcse, plm, pscl, scatterplot3d, stats4, strucchange, survival

Imported by ARpLMEC, ConvergenceClubs, DChaos, DMLLZU, DirectEffects, FindIt, GLMpack, GVARX, GenericML, Greg, HARModel, HDTSA, LMMstar, ModTools, OOS, PlackettLuce, PointFore, Rchoice, StackImpute, Zelig, acrt, adventr, autostsm, bayesdistreg, betareg, binsreg, bucky, censReg, chantrics, clubSandwich, clusterSEs, cmprskcoxmsm, contrast, crch, cregg, crseEventStudy, dLagM, ecm, eventglm, factorEx, fglsnet, fixest, fxregime, gcmr, glmx, glogis, gravity, grf, highfrequency, interflex, invacost, ivdoctr, lavaSearch2, lax, lfe, lineartestr, lpirfs, maczic, maxLik, medflex, memochange, mixl, mlt, model4you, monotonicity, multcomp, multiwayvcov, nonnest2, nse, outreg, party, pdR, plm, pubh, quickmatch, radiant.model, rddtools, rdlocrand, refitME, regmedint, rigr, scDIFtest, semtree, slm, sovereign, ssym, systemfit, tbm, tradepolicy, tram, tramnet, trtf, vcrpart, weibulltools.

Depended on by AER, CADFtest, COUNT, PeerPerformance, RcmdrMisc, cjoint, dhglm, evian, gmm, iClick, inference, ivpack, ivregEX, list, mediation, merDeriv, mfx, midasr, momentfit, prais, rdd, regtools, strucchange, strucchangeRcpp, vars.

Suggested by ANOM, ARDL, Disequilibrium, DoubleML, FinTS, HSAUR2, HSAUR3, MarkowitzR, MatchIt, SharpeR, SimEngine, StratifiedMedicine, broom, car, chandwich, dfadjust, dyn, dynlm, eflm, estimatr, finalfit, geex, ggeffects, huxtable, insight, interactions, ivreg, jtools, lmtest, madness, marginaleffects, margins, memisc, miceadds, mlt.docreg, modelsummary, modmarg, npcp, panelr, parameters, partykit, performance, pscl, psycModel, psychotools, sjPlot, spatialreg, tangram, texreg, tukeytrend, wpa.

See at CRAN