TangoF.test<-function(oo, ee, d, lam, Nrep){ # ----------------------------------------------------------------- # An example of execution # # d<-0:9; Nrep<-999 ; lam<- 2*(1:20) # ob<- c(0, 1, 3, 2, 1, 8, 7, 4, 0, 2) # ex<- c(0.041,0.701,1.128,1.634,1.868,5.738,4.550,3.617,3.792,4.931) # out<-TangoF.test(ob,ex,d,lam,Nrep) # # --------------------------------------------------------------------- # ARGUEMENTS # oo : a vector of observed number of cases sorted in the ascending # order of the distance to the point source # ee : a vector of conditional expected number of cases sorted # in the ascending order of the distance to the point source # d : a vector of distances to the point source # lam : a vector of values of lambda # Nrep : The number of Monte Carlo replications, e.g., 999, 9999 # # VALUES # Test.statistic : a vector of test statistic T_decline for each of lambda # Max.statistic : max(T_decline) # p.value : simulated p-value # Freq : a vector of simulated test statistics under the null # #----------------------------------------------------------------------- p<-ee/sum(ee) q<-oo/sum(oo) len<-length(lam) tval0<-1:len tval<-1:len nn<-sum(oo) nr<-length(oo) for (i in 1:len){ ram<-lam[i] g<- exp( -4 * ( d / ram)^2 ) h1<- sum( g * (q-p) ) * nn h2<- ( sum( g*g * p ) - sum( g * p )^{2} ) * nn tval0[i]<- h1 / sqrt( h2 ) } plot(lam, tval0) Twl<-max(tval0) # nloop<-Nrep+1 for (i in 2:nloop){ aa<-rmultinom(1,nn,p) q<-aa/nn for (i in 1:len){ ram<-lam[i] g<-exp( -4 * (d/ram)^2 ) h1<- sum( g * (q-p) ) * nn h2<- ( sum( g*g * p ) - sum( g * p )^{2} ) * nn tval[i]<- h1/ sqrt( h2 ) } Twl1<-max(tval) Twl<- c(Twl, Twl1) } p1<- rank(-Twl)[1]/(Nrep+1) list(Max.statistic=Twl[1], Test.statistics=tval0, p.value=p1, Freq=Twl) }