`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,
...,
fix = FALSE,
use = "pairwise.complete.obs",
verbose = FALSE,
cl = NULL
)
```

## Arguments

- x
a fitted model object, such as the output of a call to

`lm()`

or`glm()`

. The model object must result from a function that can be updated using`update()`

and has a`weights`

argument to input non-integer case weights.- cluster
a variable indicating the clustering of observations, a

`list`

(or`data.frame`

) thereof, or a formula specifying which variables from the fitted model should be used (see examples). By default (`cluster = NULL`

), either`attr(x, "cluster")`

is used (if any) or otherwise every observation is assumed to be its own cluster.- R
the number of bootstrap replications.

- start
`logical`

; should`coef(x)`

be passed as`start`

to the`update(x, weights = ...)`

call? In case the model`x`

is computed by some numeric iteration, this may speed up the bootstrapping.- ...
ignored.

- fix
`logical`

; if`TRUE`

, the covariance matrix is fixed to be positive semi-definite in case it is not.- use
`character`

; specification passed to`stats::cov()`

for handling missing coefficients/parameters.- verbose
`logical`

; whether to display a progress bar.- cl
a cluster object created by

`parallel::makeCluster()`

, or an integer to indicate the number of child-processes (integer values are ignored on Windows) for parallel evaluations. See`pbapply::pblapply()`

for details. If`NULL`

, no parallelization will take place.

## 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.

## 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

```
data("infert")
fit <- glm(case ~ spontaneous + induced, data = infert,
family = "binomial")
lmtest::coeftest(fit, vcov. = vcovFWB, R = 200)
#>
#> z test of coefficients:
#>
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -1.70786 0.23383 -7.3040 2.793e-13 ***
#> spontaneous 1.19721 0.21267 5.6293 1.810e-08 ***
#> induced 0.41813 0.19095 2.1898 0.02854 *
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
# 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)))
)
#> BS FWB BS-cluster FWB-cluster
#> (Intercept) 0.02754526 0.02801471 0.06938390 0.06720391
#> x 0.02773697 0.02832687 0.04514005 0.05008552
```