######################################################################## Conduct the Monte Carlo Simulations to Obtain the Overall Clustering for the Cluster Detection Based on Events ######################################################################## DESCRIPTION: For specified cluster sizes and results from event.test, conducts the simulations for the overall clustering based on events. USAGE: sim.event.calc(kmat,eventmat,popmat,nnmat,resultmat,numsim,signiflevel=0.05,print.it=F) REQUIRED ARGUMENTS: kmat the cluster sizes used for the testing. If a vector, each element corresponds to the cluster size for each cell (has dimension equal to the total number of cells). If kmat is a matrix, each row contains the sequence of cluster sizes to test for each cell. The testing algorithm is employed if kmat is a matrix. Each cluster size must be > 1. eventmat array of event frequencies by cell (row), frequency (column), and stratum (layer): eventmat[i,j,s]=number of cases in cell i and stratum s that have j events. If no strata, eventmat is a matrix. popmat the matrix containing the number of population in each cell (rows) by each stratum (columns). nnmat the square matrix containing the ordered nearest neighbours: nnmat[i,1]=i, nnmat[i,j]=cell i's (j+1)th nearest neighbour. Assumes that the cells are indexed (labelled) from 1 to the total number of cells. resultmat the matrix of results output from event.test. numsim the number of simulations to conduct. OPTIONAL ARGUMENTS: signiflevel the significance level for each cluster test. The default is 0.05. print.it a flag to indicate if intermediate calculations should be printed (print.it=T) or not (print.it=F). The default is print.it=F. VALUE: a p-value for the overall testing. Prints out the frequency distribution of the number of significant clusters in the simulations. DETAILS: This method is based on the Rosychuk, Huston, and Prasad (2006) test statistic. The testing algorigthm for events described in Rosychuk, Huston, and Prasad (2006) and is based on Le, Petkau, and Rosychuk (1996). EXAMPLES: #hypothetical 10 cell region #provide the nearest neighbour for cells 1 to 10 nnEx=matrix(scan(),ncol=10,byrow=T) 1 5 2 3 9 4 10 6 7 8 2 3 5 4 1 8 9 10 6 7 3 2 4 5 1 8 9 10 6 7 4 3 2 5 8 6 7 1 9 10 5 2 3 4 1 8 10 9 6 7 6 7 4 8 3 2 5 10 9 1 7 6 8 4 3 2 5 9 10 1 8 4 10 7 3 6 2 1 5 9 9 10 7 6 4 5 2 1 3 8 10 9 7 8 6 4 5 2 1 3 #population data with 2 strata popEx=matrix(scan(),ncol=2,byrow=T) 1358 1405 1005 1089 117 120 66 62 2827 2749 152 158 16 26 67 92 1456 1444 174 180 #event data with 2 strata, at most 3 events per case eventEx=array(0,dim=c(10,3,2)) eventEx[,,1]=matrix(scan(),ncol=3,byrow=T) #for stratum 1 3 2 0 0 0 0 0 0 0 2 0 0 2 3 2 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 #the above translates to: in stratum 1, cell 1 has 3 cases with 1 event each, #cell 1 has 2 cases with 2 events each, cell 1 has 0 cases with 3 events, #...cell 9 has 1 case with 1 event, cell 9 has 1 case with 2 events,.... eventEx[,,2]=matrix(scan(),ncol=3,byrow=T) #for stratum 2 0 1 0 0 0 0 0 0 0 0 0 0 2 3 2 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 #do the testing with user supplied cluster sizes and 2 strata kEx=rep(4,10)#test each cell at cluster size=4 resultEx=event.test(kEx,eventEx,popEx,nnEx) #run the simulation 10 times for the overall test pEx=sim.event.calc(kEx,eventEx,popEx,nnEx,resultEx,10) # Output as posted on the WEB originally #output of the results #Simulation results: #Frequency of the number of clusters identified: # 0 1 2 3 4 5 #[1,] 10 0 0 0 0 0 #Number of sims= 10 Number of sims > 2 = 0 pvalue= 0 # Output I get when running code in R #Simulation results: #Frequency of the number of clusters identified: # [,1] [,2] [,3] #[1,] 9 1 0 #Number of sims= 10 Number of sims > 1 = 0 pvalue= 0 print(pEx) #print the pvalue #[1] 0