Created
September 15, 2018 16:39
-
-
Save Dpananos/6d4a156fa45e58c12e44655594dd2a86 to your computer and use it in GitHub Desktop.
Confidence interval simulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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