Skip to content

Instantly share code, notes, and snippets.

@nstrayer
Created December 6, 2017 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nstrayer/806711ebb783082574ad2e300f47818e to your computer and use it in GitHub Desktop.
Save nstrayer/806711ebb783082574ad2e300f47818e to your computer and use it in GitHub Desktop.
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