Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
library(tidyverse)
get_boot_int <- function(n){
data <- data_frame(
outcome = rnorm(n, 60, 20),
treat = sample(c(0,1), n, replace = T)
) %>%
mutate(outcome = ifelse(treat == 1, outcome + 5, outcome))
data %>%
group_by(treat) %>%
summarise(
bs_mean = replicate(1000, mean(sample(outcome, replace = T))) %>%
quantile(c(0.025, 0.975)) %>%
paste(collapse = '-')
) %>%
separate(bs_mean, c('lower', 'upper'), sep = '-') %>%
mutate(lower = as.numeric(lower),
upper = as.numeric(upper),
treat = as.character(treat),
size = n)
}
all_sizes <- seq(250, 2500, 250) %>%
purrr::map_df(get_boot_int)
all_sizes %>%
ggplot(aes(x = size, ymin = lower, ymax = upper)) +
geom_ribbon(aes(fill = treat), alpha = 0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment