Created
February 12, 2012 06:49
-
-
Save Protonk/1806894 to your computer and use it in GitHub Desktop.
Simulated "Estimated" CDF for SW 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
# Intent was to use shapiro.test() to recreate fig. 4 in | |
# Shapiro, S. S.; Wilk, M. B. (1965). "An analysis of variance test for normality (complete samples)". Biometrika 52 (3-4): 591–611 | |
plotPvalues <- function() { | |
l.norm <- rnorm(5000) | |
shap.n <- function(n) { | |
replicate(2000, unlist(shapiro.test(sample(l.norm, n, replace = TRUE))[c(1,2)])) | |
} | |
shap.l <- mapply(shap.n, seq(5, 50, 5), SIMPLIFY = FALSE) | |
plot(seq(0,1,length.out = 10), seq(0.7, 1, length.out = 10), type = "n", | |
xlab = "P", | |
ylab = "W", | |
main = "Simulated Empirical CDF for n = 5, 10, 15, ..., 50") | |
abline(v = seq(0, 1, length.out = 11), lty = 3, col = "grey") | |
abline(h = seq(0.7, 1, length.out = 7), lty = 3, col = "grey") | |
text(rep(0.21, 4), c(0.84, 0.88, 0.91, 0.98), labels = c("n = 5", "n = 10", "n = 15", "n = 50"), cex = 0.9) | |
for (n in 1:10) { | |
lines(sort(shap.l[[n]][2, ]), sort(shap.l[[n]][1, ]), col = rgb(red = (1 - 5*n/50), green = 0, blue = 5*n/50)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment