vcovFWB {fwb} | R Documentation |
Fractional Weighted Bootstrap Covariance Matrix Estimation
Description
vcovFWB()
estimates the covariance matrix of model coefficient estimates using the fractional weighted bootstrap. It serves as a drop-in for stats::vcov()
or sandwich::vcovBS()
. Clustered covariances are can be requested.
Usage
vcovFWB(
x,
cluster = NULL,
R = 1000,
start = FALSE,
wtype = getOption("fwb_wtype", "exp"),
...,
fix = FALSE,
use = "pairwise.complete.obs",
verbose = FALSE,
cl = NULL
)
Arguments
x |
a fitted model object, such as the output of a call to |
cluster |
a variable indicating the clustering of observations,
a |
R |
the number of bootstrap replications. |
start |
|
wtype |
string; the type of weights to use. Allowable options include |
... |
ignored. |
fix |
|
use |
|
verbose |
|
cl |
a cluster object created by |
Details
vcovFWB()
functions like other vcov()
-like functions, such as those in the sandwich
package, in particular, sandwich::vcovBS()
, which implements the traditional bootstrap (and a few other bootstrap varieties for linear models). Sets of weights are generated as described in the documentation for fwb()
, and the supplied model is re-fit using those weights. When the fitted model already has weights, these are multiplied by the bootstrap weights.
For lm
objects, the model is re-fit using .lm.fit()
for speed, and, similarly, glm
objects are re-fit using glm.fit()
(or whichever fitting method was originally used). For other objects, update()
is used to populate the weights and re-fit the model (this assumes the fitting function accepts non-integer case weights through a weights
argument). If a model accepts weights in some other way, fwb()
should be used instead; vcovFWB()
is inherently limited in its ability to handle all possible models. It is important that the original model was not fit using frequency weights (i.e., weights that allow one row of data to represent multiple full, identical, individual units).
See sandwich::vcovBS()
and sandwich::vcovCL()
for more information on clustering covariance matrices, and see fwb()
for more information on how clusters work with the fractional weighted bootstrap. When clusters are specified, each cluster is given a bootstrap weight, and all members of the cluster are given that weight; estimation then proceeds as normal. By default, when cluster
is unspecified, each unit is considered its own cluster.
Value
A matrix containing the covariance matrix estimate.
See Also
fwb()
for performing the fractional weighted bootstrap on an arbitrary quantity; fwb.ci()
for computing nonparametric confidence intervals for fwb
objects; summary.fwb()
for producing standard errors and confidence intervals for fwb
objects; sandwich::vcovBS()
for computing covariance matrices using the traditional bootstrap
Examples
set.seed(123)
data("infert")
fit <- glm(case ~ spontaneous + induced, data = infert,
family = "binomial")
lmtest::coeftest(fit, vcov. = vcovFWB, R = 200)
# Example from help("vcovBS", package = "sandwich")
data("PetersenCL", package = "sandwich")
m <- lm(y ~ x, data = PetersenCL)
# Note: this is not to compare performance, just to
# demonstrate the syntax
cbind(
"BS" = sqrt(diag(sandwich::vcovBS(m))),
"FWB" = sqrt(diag(vcovFWB(m))),
"BS-cluster" = sqrt(diag(sandwich::vcovBS(m, cluster = ~firm))),
"FWB-cluster" = sqrt(diag(vcovFWB(m, cluster = ~firm)))
)
# Using `wtype = "multinom"` exactly reproduces
# `sandwich::vcovBS()`
set.seed(11)
s <- sandwich::vcovBS(m, R = 200)
set.seed(11)
f <- vcovFWB(m, R = 200, wtype = "multinom")
all.equal(s, f)