dgp <- function(N, mu, nu) {
mu + rt(N, df = nu)
}
estimator <- function(
dat,
B_vals = c(49,59,89,99),
m = 4,
trim = 0.1
) {
# compute estimate and standard error
N <- length(dat)
est <- mean(dat, trim = trim)
se <- sd(dat) / sqrt(N)
# compute booties
booties <- replicate(max(B_vals), {
x <- sample(dat, size = N, replace = TRUE)
data.frame(
M = mean(x, trim = trim),
SE = sd(x) / sqrt(N)
)
}, simplify = FALSE) |>
dplyr::bind_rows()
# confidence intervals for each B_vals
CIs <- bootstrap_CIs(
boot_est = booties$M,
boot_se = booties$SE,
est = est,
se = se,
CI_type = c("normal","basic","student","percentile"),
B_vals = B_vals,
reps = m,
format = "wide-list"
)
res <- data.frame(
est = est,
se = se
)
res$CIs <- CIs
res
}
#' build a simulation driver function
simulate_bootCIs <- bundle_sim(
f_generate = dgp,
f_analyze = estimator
)
boot_results <- simulate_bootCIs(
reps = 50, N = 20, mu = 2, nu = 3,
B_vals = seq(49, 199, 50),
)
extrapolate_coverage(
data = boot_results,
CI_subsamples = CIs,
true_param = 2
)
extrapolate_coverage(
data = boot_results,
CI_subsamples = CIs,
true_param = 2,
B_target = 999,
format = "long"
)
Run the code above in your browser using DataLab