# generate data from two distinct populations
dat <- data.frame(
group = rep(c("A","B"), c(40, 50)),
y = c(
rgamma(40, shape = 7, scale = 2),
rgamma(50, shape = 3, scale = 4)
)
)
stat <- t.test(y ~ group, data = dat)$statistic
# create bootstrap replications under the null of no difference
boot_dat <- dat
booties <- replicate(399, {
boot_dat$group <- sample(dat$group)
t.test(y ~ group, data = boot_dat)$statistic
})
# calculate bootstrap p-values from full set of bootstrap replicates
bootstrap_pvals(boot_stat = booties, stat = stat)
# calculate multiple bootstrap p-values using sub-sampling of replicates
bootstrap_pvals(
boot_stat = booties, stat = stat,
B_vals = 199,
reps = 4L
)
# calculate multiple bootstrap p-values using sub-sampling of replicates,
# for each of several sub-sample sizes.
bootstrap_pvals(
boot_stat = booties, stat = stat,
B_vals = c(49,99,199),
reps = 4L
)
Run the code above in your browser using DataLab