/* Anderson-Darling test for normality */ /* This program is a GAUSS version of 'ad.test' */ /* by Juergen Gross in library 'nortest' of R. */ /* Notice: Anderson-Darling Statistic in 'gofnorm' in library 'fBasics' of R */ /* indicates Z(or Astar) rather than A2. AD statistic in 'ad.test' in */ /* 'nortest' of R indicates A2 itself, which might be worng in its */ /* implementation. Be careful. */ new; cls; x=rndn(100,1); call ADtest(x); proc ADtest(x); local n,p,A2,Z,pval; if ismiss(x); errorlog "Warning: missing data found."; x=packr(x); endif; n=rows(x); x=sortc(x,1); p=cdfn((x-meanc(x))/stdc(x)); A2=-n-sumc((2*seqa(1,1,n)-1)/n.*(ln(p)+ln(1-rev(p)))); Z=A2*(1+0.75/n+2.25/n^2); if Z<0.2; pval=1-exp(-13.436+101.14*Z-223.73*Z^2); elseif Z<0.34; pval=1-exp(-8.318+42.796*Z-59.938*Z^2); elseif Z<0.6; pval=exp(0.9177-4.279*Z-1.38*Z^2); else; pval=exp(1.2937-5.709*Z+0.0186*Z^2); endif; /* results */ print "Anderson-Darling Test:"; print/rz "n =" n; print "A* =" Z; print "pval=" pval; retp(Z); endp;