looney<-function(y,nbs=2000,alpha=0.05) { ############################################################ # # looney - get the correlation of the data and their # expected value under normality # estimate the pval and critical value via parametric bootstrap # for testing # H0: Data are Normal # HA: Data are not Normal # ie no need for the Looney Table # # input # y - data you would like tested for normality # nbs - number of bootstrap samples to take # alpha - approximates a cv for this size test # # output # cor - the correlation between the data and there # expected value under normality # pval - a bootstrap estimate of the pvalue for th # ecv - the estimated critical value # (should be quite close to the value in the Looney Table) # ############################################################ n<-length(y) ey<-qnorm((rank(y) - 0.375)/(n+0.25)) est<-cor(ey,y) cors<-rep(0,nbs) for( i in 1:nbs ) { z<-rnorm(n) ez<-qnorm((rank(z) - 0.375)/(n+0.25)) cors[i]<-cor(ez,z) } pval=sum( cors < est )/nbs ecv=sort(cors)[nbs*alpha] list(cor=est, pval=pval, ecv=ecv) }