#The chi-square test of goodness of fit for hypothesis on Benford's distribution. #Simulation evaluation of sample size (n) # on the basis of simulated distribution of the test statistic # under fixed significance level (a) and power (b); # ls - number of replication, # dn - increase of sample size, #start sample size: n=50 dn=5 ls=10000 a=0.1 b=0.95 #H0: p=p0; H1: p=p1 k=9 czas=proc.time() #Benford's prob. function: p0=matrix(0,k,1); for (i in 1:k) p0[i]=log10(1+1/i) #uniform alternative distribution: #p1=matrix(1/k,k,1) #quasi-exponenntial alternative distributions with exp. value of Benford's distr. EX=matrix(1:9,1,9)%*%p0 #p1=as.matrix(dexp(1:9,1/EX)/sum(dexp(1:9,1/EX))) #triangular alternative distrib.: p1=matrix(c(9/45,8/45,7/45,6/45,5/45,4/45,3/45,2/45,1/45),k,1) #other alternative distrib.: p12=matrix(c(-.005,-.005,-.005,-.005,0,.005,.005,.005,.005),k,1) #p12=matrix(c(-.01,-.01,-.01,-.01,0,.01,.01,.01,.01),k,1) #p12=matrix(c(-.04,-.03,-.02,-.01,0,.01,.02,.03,.04),k,1) #p12=matrix(c(-.02,-.015,-.01,-.005,0,.005,.01,.015,.02),k,1) #p1=p0+p12 qs=matrix(0,ls,1) ws=matrix(0,ls,1) fitchi=function(n,p,w) {#evaluation of the test statistic: n*sum((w-p)*(w-p)/p)} bs=0; it=0 while ((bs=wk) bs=bs+1} bs=bs/ls it=it+1 } #evaluated sample size: n #simulated critical value of the test: wk #nuber of processed iteration: it #time of processing: proc.time()-czas alarm()