data(efc)
bs <- bootstrap(efc, 5)
# now run models for each bootstrapped sample
lapply(bs$strap, function(x) lm(neg_c_7 ~ e42dep + c161sex, data = x))
# generate bootstrap samples with 600 observations for each sample
bs <- bootstrap(efc, 5, 600)
# generate bootstrap samples with 70% observations of the original sample size
bs <- bootstrap(efc, 5, .7)
# compute standard error for a simple vector from bootstraps
# use the `as.data.frame()`-method to get the resampled
# data frame
bs <- bootstrap(efc, 100)
bs$c12hour <- unlist(lapply(bs$strap, function(x) {
mean(as.data.frame(x)$c12hour, na.rm = TRUE)
}))
# or as tidyverse-approach
if (require("dplyr") && require("purrr")) {
bs <- efc %>%
bootstrap(100) %>%
mutate(
c12hour = map_dbl(strap, ~mean(as.data.frame(.x)$c12hour, na.rm = TRUE))
)
# bootstrapped standard error
boot_se(bs, c12hour)
}
Run the code above in your browser using DataLab