Skip to content

Instantly share code, notes, and snippets.

@steveharoz
Created June 28, 2024 19:01
Show Gist options
  • Save steveharoz/c5f59b27d118b6941a388cc9b934b0dc to your computer and use it in GitHub Desktop.
Save steveharoz/c5f59b27d118b6941a388cc9b934b0dc to your computer and use it in GitHub Desktop.
Extreme p-values
library(tidyverse)
library(ggdist)
data = expand.grid(
effect_size = c(0, 0.2, 0.4, 0.6, 0.8),
sample_size = 1000,
rep = 1:10000
) %>%
rowwise() %>%
mutate(p = t.test(rnorm(sample_size/2), rnorm(sample_size/2, effect_size))$p.value)
ggplot(data) +
aes(x = p, fill = factor(effect_size), group = effect_size, y = factor(effect_size)) +
ggdist::stat_histinterval(linetype = 0, point_alpha = 0, normalize = "groups") +
scale_x_log10() +
theme_minimal(14) + theme(legend.position = "top", legend.justification = "left") +
labs(x = "p-values", y = NULL, fill = "Cohen's d",
title = "Simulating p-values for sample size 1000")
data_ss = expand.grid(
effect_size = 0.5,
sample_size = c(50, 100, 500, 1000, 5000),
rep = 1:10000
) %>%
rowwise() %>%
mutate(p = t.test(rnorm(sample_size/2), rnorm(sample_size/2, effect_size))$p.value)
ggplot(data_ss) +
aes(x = p, fill = factor(sample_size), group = sample_size, y = factor(sample_size)) +
ggdist::stat_histinterval(linetype = 0, point_alpha = 0, normalize = "groups") +
scale_x_log10() +
theme_minimal(14) + theme(legend.position = "top", legend.justification = "left") +
labs(x = "p-values", y = NULL, fill = "Sample size",
title = "Simulating p-values for Cohen's d = 0.5")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment