Last active
April 13, 2022 20:44
-
-
Save jcreinhold/30e1a689d55eef35f728b4f5d7490a24 to your computer and use it in GitHub Desktop.
Explore the distribution of p-values
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
--- | |
title: "On the distribution of p-values" | |
output: html_notebook | |
--- | |
```{r} | |
sample.sizes <- seq(5, 100, 10) | |
num.trials <- 1000 | |
num.experiments <- 1 | |
null.mu <- 0.0 | |
alternative.mu <- 0.1 | |
sig.level <- 0.05 | |
p.values <- array(data=NA, dim=num.trials) | |
for (n in sample.sizes) { | |
for (i in 1:num.trials) { | |
p.values.all.experiments <- array(data=NA, dim=num.experiments) | |
for (j in 1:num.experiments) { | |
x <- rnorm(n, mean=alternative.mu) | |
p.values.all.experiments[j] <- t.test( | |
x, alternative = "greater", var.equal=TRUE | |
)$p.value | |
} | |
p.values[i] <- min(p.values.all.experiments) | |
} | |
mc.prob.reject <- mean(p.values < sig.level) | |
power.results <- power.t.test( | |
n = n, | |
delta = alternative.mu - null.mu, | |
sig.level = sig.level, | |
type = "one.sample", | |
alternative = "one.sided" | |
) | |
title <- paste( | |
"Min. p-values for sample size =", n, "over", num.experiments, "experiments", | |
"\nPower =", power.results$power, "; MC prob. reject =", mc.prob.reject | |
) | |
hist(p.values, main=title) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment