Last active
December 1, 2022 02:28
-
-
Save steveharoz/2dc788c1d94c17805e53f0070ffd1b3b to your computer and use it in GitHub Desktop.
Simulate multiple comparisons to show that an adjustment is needed
This file contains 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
COUNT = 100000 | |
# How often does a single t-test of random data yield p<0.05? | |
replicate(COUNT, | |
t.test(rnorm(20))$p.value < 0.05 | |
) %>% mean() | |
#> 0.05073 | |
# 5% false positive rate | |
# How often will at least one of 10 t-tests of random data yield p<0.05? | |
replicate(COUNT, | |
replicate(10, | |
t.test(rnorm(20))$p.value < 0.05 | |
) %>% any() | |
) %>% mean() | |
#> 0.4017 | |
# 40% false positive rate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment