Extended the “Getting started” page with information on how to use sandwich in combination with the modelsummary package (Arel-Bundock) based on broom infrastructure (Robinson, Hayes, Couch). (Based on ideas from Grant McDermott.) https://sandwich.R-Forge.R-project.org/articles/sandwich.html
NA observations in
order.by indexes for
vcovPC(). Such missing observations cannot be handled in the covariance extractor functions but need to be addressed prior to fitting the model object, either by omitting these observations or by imputing the missing values. (Raised by Alexander Fischer on StackOverflow https://stackoverflow.com/questions/64849935/clustered-standard-errors-and-missing-values.)
vcovHC() if there are
estfun() rows that are all zero and
type = "const", then the working residuals for
glm objects are obtained via
residuals() rather than
estfun(). (Prompted by an issue raised by Alex Torgovitsky.)
Release of version 3.0-0 accompanying the publication of the paper “Various Versatile Variances: An Object-Oriented Implementation of Clustered Covariances in R.” together with Susanne Koell and Nathaniel Graham in the Journal of Statistcal Software at https://doi.org/10.18637/jss.v095.i01. The paper is also provided as a vignette in the package as
vignette("sandwich-CL", package = "sandwich").
Improved or clarified notation in Equations 6, 9, 21, and 22 (based on feedback from Bettina Gruen).
The documentation of the HC1 bias correction for clustered covariances in
vignette("sandwich-CL", package = "sandwich") has been corrected (Equation 15). While both the code in
vcovCL() and the corresponding documentation
?vcovCL always correctly used (n-1)/(n-k), the vignette had incorrectly stated it as n/(n-k). (Reported by Yves Croissant.)
The package is also accompanied by a
pkgdown website on R-Forge now:
This essentially uses the previous content of the package (documentation, vignettes, NEWS) and just formatting was enhanced. But a few new features were also added:
pkgdownpage (but not shipped in the package) providing an introduction to the package and listing all variance-covariance functions provided with links to further details.
pkgdownpage (but also not shipped in the package) linking the
Sweave-based PDF vignettes so that they are easily accessible online.
READMEwith very brief overview for the
All kernel weights functions in
kweights() are made symmetric around zero now (suggested by Christoph Hanck). The quadratic spectral kernal is approximated by
exp(-c * x^2) rather than
1 for very small
In case the
Formula namespace is loaded, warnings are suppressed now for processing formula specifications like
cluster = ~ id in
expand.model.frame(). Otherwise warnings may occur with the
| separator in multi-part formulas with factors. (Reported by David Hugh-Jones.)
bread() method for
mlm objects has been improved to also handle weighted
mlm objects. (Suggested by James Pustejovsky.)
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.)
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.
cluster argument (and potentially also
order.by) can be specified by a formula - provided that
expand.model.frame(x, cluster) works for the model object
order.by are processed accordingly if observations were dropped in the
NA processing of the model object
x$na.action is available).
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
qr.coef() rather than
vcovBS() methods (default, glm, and lm) facilitate parallel bootstrapping by changing the
applyfun from the default
lapply(). By setting
parallel::parLapply() (on Windows) or
parallel::mclapply() (otherwise) are used.
Default handling of missing parameter estimates in
vcovBS() changed from
"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.
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").
Bug fix in
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.
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.
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.
The new function
vcovBS() provides a basic (clustered) bootstrap covariance matrix estimate, using case-based resampling.
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.
meatHC() it is now assured that the residuals are zero in observations where all regressors and all estimating functions are zero.
Corrected errors in Equation 3 of
vignette("sandwich", package = "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).
vcovHAC()did not work when models were fitted with
na.action = na.excludebecause the
estfun()then (correctly) preserved the
NAs. This is now avoided and all functions handle the
na.excludecase like the
na.omitcase. (Thanks to John Fox for spotting the problem and suggesting the solution.)
coxphobjects incorrectly returned the unweighted estimating functions in case the objects were fitted with weights. Now the weights are properly extracted and used.
An improved error message is issued if prewhitening in
vcovHAC() cannot work due to collinearity in the estimating functions.
mlmobjects that only have an intercept.
vcovHC()and related functions.
zeroinflobjects can now handle multiple offset vectors (if any).
mlmobjects. This simply combines the “meat” for each individual regression and combines the result.
bwAndrews()so that it can be easily used in models for multivariate means.
A paper based on the
"sandwich-OOP" vignette was accepted for publication in volume 16(9) of Journal of Statistical Software at https://doi.org/10.18637/jss.v016.i09.
NAMESPACE was added for the package.
"sandwich-OOP" has been revised, extended and released as a technical report.
estfun() methods and some of the
meat*() functions have been enhanced and made more consistent.
Thanks to Henric Nilsson and Giovanni Millo for feedback and testing.
sandwich is made object-oriented, so that various types of sandwich estimators can be computed not only for
lm models, but also
survreg, etc. To achieve object orientation 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
meatHAC(). All rely on the existence of a
vignette("sandwich-OOP", package = "sandwich") has been added, explaining the new object-orientation features.
CITATION file, see
Small documentation improvements.
estfun() methods for
omega can also be a function in
Added data sets from Greene (1993):
vcovHC(): The new default is now HC3 and support was added for HC4.
First CRAN release of the
sandwich package for robust covariance matrix estimators. Provides heteroscedasticity-consistent (HC) and hetereoscedasticity- and autocorrelation-consistent (HAC) covariance matrix estimators. Based on prior work by Thomas Lumley in his
Thanks to Christian Kleiber for support, feedback, and testing.