test.intersection: Test Overlapping of Polygons Against Random Rotation

Description Usage Arguments Details Value Author(s) Examples

View source: R/test.intersection.R

Description

These functions test the overlaping surface area of a colection of polygons against a a null model of random rotation. test.auto.intersection test for overlapping between polygons of the same type (i.e., the same species) whereas test.intersection test for overlapping between polygons of different types (i.e., between different species). test.auto.intersection.p and test.intersection.p functions are parallelized versions which might significantly reduce computing times.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
test.auto.intersection(ventana1, nsim = 199, win = NULL,
    prop=1, centroides1= NULL,    diametros1 =NULL)
test.intersection(ventana1, ventana2, nsim, prop = 1, win = NULL,
   centroides1 = NULL, diametros1 = NULL, centroides2 = NULL, 
   diametros2 = NULL)
test.auto.intersection.p(ventana1, nsim = 199, win = NULL,
    prop=1, centroides1= NULL,    diametros1 =NULL, ncl=2)
test.intersection.p(ventana1, ventana2, nsim, prop = 1, win = NULL,
   centroides1 = NULL, diametros1 = NULL, centroides2 = NULL, 
   diametros2 = NULL, ncl=2)

Arguments

ventana1

A multiple-polygon window with the format owin of spatstat. The "accessory" species in the case of test.intersection.

ventana2

A multiple-polygon window with the format owin of spatstat. The species whose polygons will be rotated (i.e., the "focal" species) in the case of test.intersection.

nsim

Number of simulations for the Monte Carlo test.

prop

Proportion of the diameter of each polygon which will be employed to select potential close neighbours. See details.

win

Observation window, employed to control for edge effects. An objetct with the format owin of spatstat. If not provided, it will be estimated by the x and y ranges from ventana.

centroides1

Matrix or data.frame with the coordinates of the centroids of the polygons of ventana1.

diametros1

Vector with the diameters of the polygons of ventana1.

centroides2

Matrix or data.frame with the coordinates of the centroids of the polygons of ventana2.

diametros2

Vector with the diameters of the polygons of ventana2.

ncl

Number of clusters for the parallel implementation.

Details

The summary statistic employed in the test is the overall sum of the overlapping areas of intersecting polygons. To reduce the computing burden, area intersections are only computed for polygon pairs for which the distance between their centoids is smaller than the sum of their largest diameters (weighted by the argument prop). To avoid edge effects, the test only considers polygons whose centroids are separated from the border of the observation window by a distance larger than their largest diameter. In the pairwise tests, the polygons of ventana1 are kept fixed in their original positions (i.e., the accessory species) and the polygons of ventana2 (i.e., the focal species) are rotated.

Value

Both test.auto.intersection and test.intersection return a vector of length nsim+1, with the sum of observed overlaping areas in the first position and subsequently with the sum of overlapping areas in each the simulated (i.e., randomly rotated) realizations of the null model.

Author(s)

Marcelino de la Cruz Rot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
data(Astragalus)
data(Sesleria)
# Test overlapping between Astragalus individuals
  # Ideally nsim should be at least 199
   Astragalus.test<- test.auto.intersection(Astragalus, nsim=19)
   # Observed overlapping area
   Astragalus.test[1]
   # p-value (negative value indicates that the observed overlapping is smaller 
   # than expected)
   pval(Astragalus.test)


# Test overlapping between Astragalus  and Sesleria individuals.
# Here, Sesleria is the accesory species (its individuals are kept fixed during the
# test) and Astragalus  the focal one (its individuals are rotated)
# Ideally nsim should be at least 199
   Sesleria.Astragalus.test<- test.intersection(ventana1= Sesleria, 
                                                   ventana2= Astragalus, nsim=19)
   # Observed overlapping area
   Sesleria.Astragalus.test[1]
   # p-value (negative value indicates that the observed overlapping is smaller
   # than expected)
   pval(Sesleria.Astragalus.test)
   
 
# Reducing computing burden when making repetitive testing
# First, put all the polygonal regions in a list, i.e.
 owins<- list(Astragalus, Sesleria)
 
 # compute diameters and centroids of the individual polygons 
 # in each polygonal region
 
centroids<- list()
diams<- list()
  for ( i in 1: length(owins)){
    cd<- centroidiam(owins[[i]])
    centroids[[i]] <- cd$centroids
    diams[[i]] <- cd$diams
}

# set the number of simulations for each test
nsim<-199

# create an array to store the results
result <- array(NA, dim=c(length(owins),length(owins),nsim+1))

t0<-Sys.time()
for ( i in 1: length(owins)){
   for ( j in 1: length(owins)){
     cat(i,j,"\n")
       if(j!=i) result[i,j,] <- test.intersection(owins[[i]], owins[[j]], nsim=nsim,
		centroides1=centroids[[i]], diametros1=diams[[i]],
		centroides2=centroids[[j]], diametros2=diams[[j]]) else
		result[i,j,] <-  test.auto.intersection(owins[[i]], nsim=nsim,
		centroides1=centroids[[i]], diametros1=diams[[i]])
   }
}
 Sys.time()-t0
 
 # observed values (focal species in columns)
 (observed<-  t(result[,,1]))
 # p-values
 tabla.p<- apply(result,c(1,2),pval)
 (p_values <- t(tabla.p))
 
 # Compare with parallelized versions:
  
# create an array to store the result.ps
result.p<- array(NA, dim=c(length(owins),length(owins),nsim+1))

t0<-Sys.time()
for ( i in 1: length(owins)){
   for ( j in 1: length(owins)){
     cat(i,j,"\n")
       if(j!=i) result.p[i,j,] <- test.intersection.p(owins[[i]], owins[[j]], nsim=nsim,
		centroides1=centroids[[i]], diametros1=diams[[i]],
		centroides2=centroids[[j]], diametros2=diams[[j]]) else
		result.p[i,j,] <-  test.auto.intersection.p(owins[[i]], nsim=nsim,
		centroides1=centroids[[i]], diametros1=diams[[i]])
   }
}
 Sys.time()-t0
 
 # observed values (focal species in columns)
 (observed.p<-  t(result.p[,,1]))
 # p-values
 tabla.p.p<- apply(result.p,c(1,2),pval)
 (p_values.p <- t(tabla.p.p))
 
 

 

overlapptest documentation built on March 16, 2021, 1:08 a.m.