Learn R Programming

fwb (version 0.5.0)

fwb.array: Recover Bootstrap Weights

Description

fwb.array() returns the bootstrap weights generated by fwb().

Usage

fwb.array(fwb.out)

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.

Arguments

fwb.out

an fwb object; the output of a call to fwb().

Details

The original seed is used to recover the bootstrap weights before being reset.

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 bootstrap; boot::boot.array() for the equivalent function in boot; vignette("fwb-rep") for information on replicability.

Examples

Run this code
set.seed(123, "L'Ecuyer-CMRG")
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)

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

Run the code above in your browser using DataLab