## Column 1 is the p-value, column 2 is the proportion of null test ## statistics exceeding the actual test statistic. Q = array(0, c(1000,2)) ## Null data for checking the accuracy of the p-values. Z = array(rnorm(1000*20), c(1000,20)) M2 = apply(Z, 1, mean) for (r in 1:1000) { ## Generate an alternative data set. X = runif(1) + rnorm(20) ## Get the p-value, assuming that the variance is known to be 1. M1 = mean(X) p = 1-pnorm(sqrt(20)*M1) ## Store the p-value, and the proportion of null draws with a test ## statistic that is larger than the actual test statistic. Q[r,1] = p Q[r,2] = mean(M2 > M1) }