/* Frequency(Equal Probability) test for U(0,1) sequence */ new; cls; x=rndu(100,1); k=10; call eqprobtest(x,k); proc eqprobtest(x,k); local n,v,y,i,count,x2,pval; if ismiss(x); errorlog "Warning: missing data found."; x=packr(x); endif; if not(x>=0 and x<=1); errorlog "Error: This is not U(0,1)."; retp("."); endif; n=rows(x); v=seqa(1,1,k)/k; y=zeros(n,1); i=1; do while i<=n; y[i]=sumc((x[i].>=v')')+1; i=i+1; endo; count=zeros(k,1); i=1; do while i<=k; count[i]=sumc(y.==i); i=i+1; endo; x2=sumc((count-(n/k))^2/(n/k)); pval=cdfchic(x2,k-1); /* results */ print "Frequency(Eqaul Probability) Test:"; print/rz "n =" n; print/rz "k =" k; print "x2 =" x2;; print/lz " d.f.=" k-1; print "pval=" pval; /* graphs */ library pgraph; graphset; pqgwin auto; call hist(x,v-0.000000000001); retp(x2); endp;