data(efc)
bs <- bootstrap(efc, 100)
# now run models for each bootstrapped sample
bs$models <- lapply(
bs$strap,
function(.x) lm(neg_c_7 ~ e42dep + c161sex, data = .x)
)
# extract coefficient "dependency" and "gender" from each model
bs$dependency <- vapply(bs$models, function(x) coef(x)[2], numeric(1))
bs$gender <- vapply(bs$models, function(x) coef(x)[3], numeric(1))
# get bootstrapped confidence intervals
boot_ci(bs$dependency)
# compare with model fit
fit <- lm(neg_c_7 ~ e42dep + c161sex, data = efc)
confint(fit)[2, ]
# alternative function calls.
boot_ci(bs$dependency)
boot_ci(bs, "dependency")
boot_ci(bs, c("dependency", "gender"))
boot_ci(bs, c("dependency", "gender"), method = "q")
# compare coefficients
mean(bs$dependency)
boot_est(bs$dependency)
coef(fit)[2]
Run the code above in your browser using DataLab