fwb.array() returns the bootstrap weights generated by fwb().
Arguments
- fwb.out
an
<fwb>object; the output of a call tofwb().
Value
A matrix with R rows and n columns, where R is the number of bootstrap replications and n is the number of observations in boot.out$data.
Details
fwb() records what is needed to reproduce the weights it drew, and fwb.array() reads that record: the saved seed when simple = FALSE, or the random number stream reserved for each replicate when simple = TRUE. Either way the weights are recovered in the calling session, so nothing needs to be set up beforehand and the result does not depend on how the original call was parallelized or on whether statistic drew random numbers of its own. The state of the random number generator is left unchanged.
Bootstrap weights are used in computing BCa confidence intervals by approximating the empirical influence function for each unit with respect to each parameter (see Examples).
See also
fwb()for performing the fractional weighted bootstrapboot::boot.array()for the equivalent function in boot
See vignette("fwb-rep") for information on replicability.
Examples
set.seed(123)
data("infert")
fit_fun <- function(data, w) {
fit <- glm(case ~ spontaneous + induced, data = data,
family = "quasibinomial", weights = w)
coef(fit)
}
fwb_out <- fwb(infert, fit_fun, R = 300,
verbose = FALSE)
fwb_weights <- fwb.array(fwb_out)
dim(fwb_weights)
#> [1] 300 248
# Recover computed estimates:
est1 <- fit_fun(infert, fwb_weights[1, ])
stopifnot(all.equal(est1, fwb_out$t[1, ]))
# Compute empirical influence function:
empinf <- lm.fit(x = fwb_weights / ncol(fwb_weights),
y = fwb_out$t)$coefficients
empinf <- sweep(empinf, 2L, colMeans(empinf))
