-
-
Save tbates/3889794 to your computer and use it in GitHub Desktop.
distribution of p-values at high power
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
library(MASS) | |
library(ggplot2) | |
# move n around to alter sample size | |
# move r around to alter effect size | |
n = 1000; r = .5 | |
desiredCovMatrix = matrix(c(1,r,r, 1) ,nrow=2, ncol=2); | |
count = 1000 # number of replications | |
out = rep(NA,count) # array to store the results | |
for (i in 1:count) { | |
xy = MASS::mvrnorm (n, mu = c(0,0), Sigma = desiredCovMatrix); # simulate data | |
xy = data.frame(xy); names(xy) <- c("x", "y"); | |
result = cor.test(~x+y, data=xy) | |
out[i] = result$p.value | |
} | |
ggplot2::qplot(out, binwidth=.0001) | |
max(out) # .01 for n= 100; essentially 0 for n = 500 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment