> #7.3 Examination Marks Example > x<-c(53,15,70,73,79,48,91,20,24,91,87,15,3,78,78,62,16,15,20,32) > > ADtest<-function(z) #assumes cdf has been applied + { + n<-length(z) + z<-sort(z) + -n-sum((2*(1:n)-1)*(log(z)+log(1-z[n:1])))/n + } > > #Find mean, standard deviation and normal scores and apply AD test > mean(x) [1] 48.5 > sd(x) [1] 30.7973 > n<-length(x) > z<-sort(pnorm((x-mean(x))/sd(x))) > ADtest(z) [1] 0.9312634 > > #QQplot > qqnorm(x) > > #Hermite-Chebyshev polynomials > g<-function(n,y) + { + if (n==0) return(1) + if (n==1) return(y) + if (n==2) return((y^2-1)/sqrt(2)) + if (n==3) return((y^3-y)/sqrt(6)) + if (n==4) return((y^4-6*y^2+3)/sqrt(24)) + if (n==5) return((y^5-10*y^3+15*y)/sqrt(120)) + if (n==6) return((y^6-15*y^4+45*y^2-15)/sqrt(720)) + if (n>6) print("generate more polynomials") + } > #Vr test statistics > Vr<-function(r,x) + { + n<-length(x) + y<-(x-mean(x))/(sd(x)*sqrt((n-1)/n)) + sum(g(r,y)/sqrt(n)) + } > Vr(1,x) [1] 9.107298e-18 > Vr(2,x) [1] 5.516421e-16 > Vr(3,x) [1] 0.03612702 > Vr(4,x) [1] -1.465615 > Vr(5,x) [1] -0.0461477 > Vr(6,x) [1] 1.89065 > S4<-0 > for (i in 3:6) {S4<-S4+Vr(i,x)^2} > S4 [1] 5.726018 > 1-pchisq(S4,6-3+1) [1] 0.2205650 >