/* The Runs Test[of Old FIPS 140-1] for 01 random sequence (full version required) */ /* Notice: This program does not work on Light version of GAUSS. */ new; cls; x=rndu(20000,1); x=(x.>0.5); /* x=rev(x); if you need the reverse order of it. */ call runs(x); proc runs(x); local c,s,count,n,i,freq,minfreq,maxfreq,label; if ismiss(x); errorlog "Warning: missing data found."; x=packr(x); endif; if rows(x)<20000; errorlog "Error: This test requires the sample of at least 20000."; retp("."); endif; x=x[1:20000]; /* Use the first 20000. */ n=rows(x); c=miss(0,0); count=1; if x[1]==1; s=1; else; s=0; endif; i=2; do while i<=n; if x[i-1]/=x[i] and i/=n; c=c|count; count=0; if x[i]==1; s=s|1; else; s=s|0; endif; elseif x[i-1]/=x[i] and i==n; c=c|count|1; if x[i]==1; s=s|1; else; s=s|0; endif; elseif x[i-1]==x[i] and i==n; count=count+1; c=c|count; endif; count=count+1; i=i+1; endo; c=c[2:rows(c)]; freq=zeros(6,2); i=1; do while i<=5; freq[i,1]=sumc(c.==i .and s.==1); freq[i,2]=sumc(c.==i .and s.==0); i=i+1; endo; freq[6,1]=sumc(c.>=6 .and s.==1); freq[6,2]=sumc(c.>=6 .and s.==0); minfreq={2267,1079,502,223,90,90}; maxfreq={2733,1421,748,402,223,223}; label={"freq" "1's" "0's" "min" "max"}; print "The Runs Test:"; print $label;; print/rz seqa(1,1,6)~freq~minfreq~maxfreq;; if freq>=minfreq and freq<=maxfreq; print " Pass"; else; print " Fail"; endif; print " +"; retp(freq); endp;