Similarity between rangemaps can allow the detection of associations among species distributions, with important applications in macroecology, biogeography, environmental conservation and management. Commonly used similarity indices use counts of species occurrences and co-occurrences in discrete localities, regions or grid cells. However, gridding rangemaps distorts species’ distribution limits, generally overestimating their overlap and sometimes overriding important geographical barriers (Barbosa & Estrada, 2016). This tutorial shows how to calculate similarity between ungridded rangemaps with R. First, download, install and open R, which is freely available at CRAN.
Functions to calculate the areas of pairwise intersection and union between rangemaps and to assess rangemap similarity are implemented in R package fuzzySim (Barbosa, 2015). Paste the following code (without the #) in the R console (and then press enter) to install a recent version of this package:
# install.packages("fuzzySim")
Now you’ll need some polygon rangemaps to compare. You can use my sample
rangemap set for experimenting. Download
it to your R working directory – find out which it is by typing
getwd() – and unzip it. You should now
have some shapefiles in a folder called
“imagine_rangemaps” in your R working directory. The
following code will get you a matrix containing the areas of
pair-wise intersection (in the lower triangle) and
union (in the upper triangle) of the rangemaps in this folder
(the diagonal contains the area of each individual rangemap):
require(fuzzySim)
my_rangemaps <- list.files(path = "imagine_rangemaps", pattern = ".shp", full.names = TRUE)
my_rangemaps
rangemap_matrix <- pairwiseRangemaps(my_rangemaps, unit = "km")
rangemap_matrix
Instead of file names, you can provide a named list of SpatVector polygon objects containing the rangemaps to be compared. This can be useful especially if you previously want to process these polygons, e.g. to exclude extinct or introduced parts of the range (https://nc.iucnredlist.org/redlist/resources/files/1539614211-Mapping_attribute_codes_v1.16_2018.pdf).
Computation can be very intensive and slow if you have many and/or
large rangemaps, due to the time needed for spatial operations between
maps. If your computer has more than one core that you can use, you can
increase Ncpu (e.g., replace
Ncpu = 1 with Ncpu = 3 in the command above;
you can find out the number of cores in your machine by typing
parallel::detectCores()) to get parallel
computing. If there are many rangemaps, you should probably
also set chunks = "decreasing" for the
matrix to be calculated in parts and the memory cleaned between one part
and the next.
Once you have your rangemap_matrix, you can use it to
calculate pairwise similarity between the rangemaps,
using a variety of indices. Jaccard is the one used by default:
rangemap_jac <- rangemapSim(rangemap_matrix)
rangemap_jac
Check out the help files of these functions
(help(pairwiseRangemaps); help(rangemapSim))
for additional options and information. And that’s it! You can contact me with any
suggestions or concerns, but first remember to check for updates to the
package or to this tutorial at http://fuzzysim.r-forge.r-project.org. This tutorial was
built with RStudio + rmarkdown + knitr.
Thanks!
Barbosa A.M. (2015) fuzzySim:
applying fuzzy logic to binary similarity indices in ecology.
Methods in Ecology and Evolution, 6: 853-858
Barbosa A.M. & Estrada A. (2016) Calcular corotipos sin dividir el territorio en OGUs: una adaptación de los índices de similitud para su utilización directa sobre áreas de distribución. In: Gómez Zotano J., Arias García J., Olmedo Cobo J.A. & Serrano Montes J.L. (eds.), Avances en Biogeografía. Áreas de Distribución: Entre Puentes y Barreras, pp. 157-163. Editorial Universidad de Granada & Tundra Ediciones, Granada (Spain)