# generate t-distributed data
N <- 50
mu <- 2
nu <- 5
dat <- mu + rt(N, df = nu)
# create bootstrap replications
f <- \(x) {
c(
M = mean(x, trim = 0.1),
SE = sd(x) / sqrt(length(x))
)
}
booties <- replicate(399, {
sample(dat, replace = TRUE, size = N) |>
f()
})
res <- f(dat)
# calculate bootstrap CIs from full set of bootstrap replicates
bootstrap_CIs(
boot_est = booties[1,],
boot_se = booties[2,],
est = res[1],
se = res[2],
CI_type = c("normal","basic","student","percentile","bias-corrected"),
format = "long"
)
# Calculate bias-corrected-and-accelerated CIs
inf_vals <- res[1] - sapply(seq_along(dat), \(i) f(dat[-i])[1])
bootstrap_CIs(
boot_est = booties[1,],
est = res[1],
influence = inf_vals,
CI_type = c("percentile","bias-corrected","BCa"),
format = "long"
)
# calculate multiple bootstrap CIs using sub-sampling of replicates
bootstrap_CIs(
boot_est = booties[1,],
boot_se = booties[2,],
est = res[1],
se = res[2],
CI_type = c("normal","basic","student","percentile","bias-corrected"),
B_vals = 199,
reps = 4L,
format = "long"
)
# calculate multiple bootstrap CIs using sub-sampling of replicates,
# for each of several sub-sample sizes.
bootstrap_CIs(
boot_est = booties[1,],
boot_se = booties[2,],
est = res[1],
se = res[2],
CI_type = c("normal","basic","student","percentile"),
B_vals = c(49,99,199),
reps = 4L,
format = "long"
)
Run the code above in your browser using DataLab