normTest(rnorm(1000, mean=97, sd=8.9))
# if p > 0.05: accept Nullhypothesis that data are normally distributed.
normTest(rexp(30))
if(requireNamespace("pbapply")) replicate <- pbapply::pbreplicate
par(mfcol=c(7,6), mar=c(0,0.1,1,0.1), oma=c(2.5,1.5,2.5,0), las=1)
invisible(sapply(c("rnorm(10)", "rnorm(100)",
"rexp(10)", "rexp(100)",
"runif(10)", "runif(100)"), function(vv){
check <- replicate(1e2, normTest(v=eval(str2lang(vv)), plot=FALSE))
for(n in rownames(check))
{hist(check[n,], breaks=seq(0,1,len=20), axes=FALSE, ylab="", xlab="", main="")
if(n=="ShapiroWilk") title(main=vv, line=1, xpd=NA)
if(vv=="rnorm(10)") title(ylab=n, line=0, xpd=NA)
abline(v=0.05, col="blue", lwd=1, xpd=TRUE)
}
axis(1, at=0:1)
}))
title(main="P values of tests for normality with", outer=TRUE, line=1.5)
Run the code above in your browser using DataLab