Last active
March 25, 2024 23:38
-
-
Save steveharoz/6193beeb43f0a0d5d195b75513804678 to your computer and use it in GitHub Desktop.
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
set.seed(1) | |
# genarate random paired sets and get p-values for t-test and wolcoxon test | |
ps = replicate(10000, (function() { | |
temp = tibble( | |
subject = paste0("S", 1:100), | |
before = rnorm(100, 5, 1) %>% round() %>% pmin(7) %>% pmax(1) | |
) %>% mutate(after = (before + rnorm(100,0,1)) %>% round() %>% pmin(7) %>% pmax(1)) | |
tibble( | |
p_t = t.test(temp$before, temp$after, paired = TRUE)$p.value, | |
p_w = wilcox.test(temp$before, temp$after, paired = TRUE)$p.value | |
)})(), simplify = FALSE) %>% bind_rows() | |
# what percent of p-values are below 0.05 | |
ps %>% | |
summarise( | |
p_t = mean(p_t<0.05) %>% scales::label_percent(.1)(), | |
p_w = mean(p_w<0.05) %>% scales::label_percent(.1)(), | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment