View source: R/test.intersection.R
test.intersection | R Documentation |
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.
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)
ventana1 |
A multiple-polygon window with the format |
ventana2 |
A multiple-polygon window with the format |
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 |
centroides1 |
Matrix or |
diametros1 |
Vector with the diameters of the polygons of |
centroides2 |
Matrix or |
diametros2 |
Vector with the diameters of the polygons of |
ncl |
Number of clusters for the parallel implementation. |
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.
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.
Marcelino de la Cruz Rot
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
# Ideally nsim should be at least 199
online <- interactive()
Nsim <- if(online) 19 else 3
# 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.