Skip to content

Instantly share code, notes, and snippets.

@Dpananos
Created September 15, 2018 16:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Dpananos/6d4a156fa45e58c12e44655594dd2a86 to your computer and use it in GitHub Desktop.
Save Dpananos/6d4a156fa45e58c12e44655594dd2a86 to your computer and use it in GitHub Desktop.
Confidence interval simulation
library(tidyverse)
n.samples = 25
set.seed(5)
rerun(20,rnorm(n.samples)) %>%
map_dfr(~data_frame(data = list(.x)), .id = 'samples') %>%
mutate(mu = map_dbl(data,mean),
se = map_dbl(data,~sd(.x)/sqrt(length(.x))),
top = mu +1.96*se,
bottom = mu - 1.96*se,
false.positive = pmap_lgl(list(x = 0,left = bottom, right = top), between) ) %>%
ggplot(aes(x = samples,y = mu, ymin = bottom, ymax = top, color = false.positive))+
geom_pointrange()+
geom_hline(aes(yintercept = 0), color = 'black')+
scale_color_brewer(palette = 'Set1')+
scale_y_continuous(limits = c(-1,1))+
theme_void()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment