set.seed(640)
num_groups <- 5
sample <- 30
one_study <- function(n = 30, k = 3) {
# k groups, all drawn from the SAME population - no real differences
d <- tibble(group = rep(LETTERS[1:k], each = n),
y = rnorm(n * k))
# run every pairwise t-test, keep the smallest p-value
combn(LETTERS[1:k], 2, simplify = FALSE) %>%
map_dbl(function(pair) {
t.test(y ~ group, data = filter(d, group %in% pair),
var.equal = TRUE)$p.value
}) %>%
min()
}
smallest_p <- map_dbl(1:1000, function(i) one_study(sample, num_groups))
prop_sig <- mean(smallest_p < .05)
tibble(smallest_p = smallest_p) %>%
ggplot(aes(x = smallest_p, fill = smallest_p < .05)) +
geom_histogram(binwidth = .025, boundary = 0, color = "white") +
geom_vline(xintercept = .05, linetype = "dashed") +
scale_fill_manual(values = c("grey70", "#B3261E"), guide = "none") +
labs(x = "Smallest p-value in the study",
y = "Number of studies",
title = paste(num_groups, "groups,", choose(num_groups, 2),
"t-tests, zero real differences"),
subtitle = paste0(round(prop_sig * 100, 1),
"% of studies found p < .05")) +
theme_bw(base_size = 16)