#Assessing critical value # on the basis of simulated distribution of the test statistic # under fixed significance level (a) and sample size (n); # ls - number of replication, n=100 ls=10000 a=0.05 #H0: p=p0; H1: p=p1 czas=proc.time() #chi-square test: k=9 p0=matrix(0,k,1); #tested distribution: for (i in 1:k) p0[i]=log10(1+1/i) 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; for (t in 1:ls) {ws=rmultinom(1,n,p0)/n; qs[t]=fitchi(n,p0,ws)} qs=sort(qs) wk=qs[floor((1-a)*ls)+1] #sample size: n #simulated critical value: wk; #significance level: a proc.time()-czas alarm()