Skip to content

Instantly share code, notes, and snippets.

@steveharoz
Last active March 25, 2024 23:38
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 steveharoz/6193beeb43f0a0d5d195b75513804678 to your computer and use it in GitHub Desktop.
Save steveharoz/6193beeb43f0a0d5d195b75513804678 to your computer and use it in GitHub Desktop.
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