# # function gof(x) # # The function [qn,answer,lower,upper]=gof(x) implements a two-tail # 5% significance test of uniformity based on the statistic Qn, in # Fortiana and Grane (2002). H0 is the null hypothesis that the sample # is uniformly distributed in [0,1]. For a sample size of 2<=n<=50 # the exact test is performed, while for n>50 the asymptotic test is # performed. # # input: x is a column vector containing the sample. # # output: qn is the computed value of the test satistic, # answer is a string of characters: either "accept H0" or # "reject H0", # lower is the lower-tail critical value, # upper is the upper-tail critical value. # function [qn,answer,lower,upper]=gof(x) # cv is a matrix containg the two-tail critical values # for a 5% significance test. cv=[0 0; 0.01887 1.26283; 0.12573 1.20760; 0.24049 1.20177; 0.33397 1.20121; 0.40709 1.19460; 0.46459 1.18852; 0.51056 1.18321; 0.54796 1.17819; 0.57894 1.17350; 0.60502 1.16915; 0.62730 1.16513; 0.64658 1.16139; 0.66346 1.15790; 0.67837 1.15463; 0.69166 1.15158; 0.70359 1.14870; 0.71437 1.14600; 0.72416 1.14345; 0.73310 1.14103; 0.74131 1.13875; 0.74887 1.13657; 0.75586 1.13451; 0.76235 1.13254; 0.76839 1.13066; 0.77403 1.12887; 0.77931 1.12715; 0.78427 1.12550; 0.78894 1.12392; 0.79334 1.12240; 0.79750 1.12095; 0.80143 1.11954; 0.80516 1.11819; 0.80871 1.11688; 0.81208 1.11562; 0.81530 1.11441; 0.81836 1.11323; 0.82129 1.11209; 0.82409 1.11099; 0.82678 1.10992; 0.82935 1.10888; 0.83182 1.10788; 0.83420 1.10690; 0.83648 1.10595; 0.83867 1.10503; 0.84079 1.10413; 0.84283 1.10326; 0.84480 1.10241; 0.84670 1.10158; 0.84854 1.10077]; # # computing the Qn statistic n=length(x); x=sort(x); a=zeros(n,1); for i=1:n a(i,1)=(2*i-n-1); end qn=(6/n^2)*a'*x; if n<=50 # performing the exact test lower=cv(n,1); upper=cv(n,2); # checking if Qn belongs to the exact critical region if qnupper answer="reject H0"; else answer="accept H0"; endif else # performing the asymptotic test lower=-1.95996; upper=1.95996; # standardizing Qn m=(n-1)/n; s=sqrt(1/(5*n)); qn=(qn-m)/s; # checking if the standardized Qn belongs to the # asymptotic critical region if qnupper answer="reject H0"; else answer="accept H0"; endif endif endfunction