Title: | Diversity Metrics Calculations for Rasterized Data |
---|---|
Description: | Alpha and beta diversity for taxonomic (TD), functional (FD), and phylogenetic (PD) dimensions based on rasters. Spatial and temporal beta diversity can be partitioned into replacement and richness difference components. It also calculates standardized effect size for FD and PD alpha diversity and the average individual traits across multilayer rasters. The layers of the raster represent species, while the cells represent communities. Methods details can be found at Cardoso et al. 2022 <https://CRAN.R-project.org/package=BAT> and Heming et al. 2023 <https://CRAN.R-project.org/package=SESraster>. |
Authors: | Flávio M. M. Mota [aut, cre, cph]
|
Maintainer: | Flávio M. M. Mota <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.4 |
Built: | 2025-01-26 03:14:40 UTC |
Source: | https://github.com/flaviomoc/divraster |
Area calculation
area.calc(r1, unit = "km", r2 = NULL, r3 = NULL, filename = "")
area.calc(r1, unit = "km", r2 = NULL, r3 = NULL, filename = "")
r1 |
A SpatRaster or a list of multiple SpatRasters. |
unit |
Character. Default is "km", but "m" and "ha" are also available. |
r2 |
A SpatRaster with the same resolution and extent as "r1". |
r3 |
A SpatRaster with the same resolution and extent as "r1". |
filename |
Character. Save results if a name is provided. |
A vector or a data.frame with area values in the chosen unit.
library(terra) bin1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) my.list <- list(bin1 = bin1[[1:2]]) area.calc(my.list)
library(terra) bin1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) my.list <- list(bin1 = bin1[[1:2]]) area.calc(my.list)
Function to calculate distance and direction of change between centroids
dd.calc(raster1, raster2)
dd.calc(raster1, raster2)
raster1 |
A binary spatraster. |
raster2 |
A binary spatraster. |
A data frame with distance and direction.
library(terra) r1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) r2 <- terra::rast(system.file("extdata", "fut.tif", package = "divraster")) dd.calc(r1, r2)
library(terra) r1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) r2 <- terra::rast(system.file("extdata", "fut.tif", package = "divraster")) dd.calc(r1, r2)
Difference between raster objects
differ.rast(r1, r2, perc = TRUE, filename = "")
differ.rast(r1, r2, perc = TRUE, filename = "")
r1 |
A SpatRaster object. |
r2 |
A SpatRaster object. |
perc |
Boolean. Default is TRUE to calculate the percentage of change between r1 and r2. FALSE gives the absolute number instead. |
filename |
Character. Save results if a name is provided. |
A SpatRaster object with the difference between r1 and r2.
library(terra) rich1 <- terra::rast(system.file("extdata", "rich_ref.tif", package = "divraster")) rich2 <- terra::rast(system.file("extdata", "rich_fut.tif", package = "divraster")) differ.rast(rich1, rich2)
library(terra) rich1 <- terra::rast(system.file("extdata", "rich_ref.tif", package = "divraster")) rich2 <- terra::rast(system.file("extdata", "rich_fut.tif", package = "divraster")) differ.rast(rich1, rich2)
Check if objects are valid
inputs_chk(bin1, bin2, tree)
inputs_chk(bin1, bin2, tree)
bin1 |
A SpatRaster with presence-absence data (0 or 1) for a set of species. |
bin2 |
A SpatRaster with presence-absence data (0 or 1) for a set of species. Species names in 'bin2' and 'bin1' must match! |
tree |
It can be a 'data.frame' with species traits or a 'phylo' with a rooted phylogenetic tree. Species names in 'tree', 'bin1', and 'bin2' must match! |
Either a success message or an error.
Load data adapted from Mota et al. (2022), Tobias et al. (2022), and Jetz et al. (2014)
load.data()
load.data()
A list with binary maps of species for the reference and future climate scenarios, species traits, and a rooted phylogenetic tree for the species. The species names across these objects must match!
Mota, F. M. M. et al. 2022. Climate change is expected to restructure forest frugivorous bird communities in a biodiversity hot-point within the Atlantic Forest. - Diversity and Distributions 28: 2886–2897.
Tobias, J. A. et al. 2022. AVONET: morphological, ecological and geographical data for all birds. - Ecology Letters 25: 581–597.
Jetz, W. et al. 2014. Global Distribution and Conservation of Evolutionary Distinctness in Birds. - Current Biology 24: 919–930.
data <- load.data() data
data <- load.data() data
Area calculation
## S3 method for class 'list' range(x, unit = "km", r2 = NULL, r3 = NULL, filename = "")
## S3 method for class 'list' range(x, unit = "km", r2 = NULL, r3 = NULL, filename = "")
x |
A list containing multiple SpatRaster with presence-absence data (0 or 1) for a set of species. |
unit |
Character. Default is "km", but "m" and "ha" are also available. |
r2 |
A SpatRaster with the same extent as "x". |
r3 |
A SpatRaster with the same extent as "x". |
filename |
Character. Save results if a name is provided. |
A data.frame with area values in the chosen unit.
Area calculation
## S3 method for class 'rast' range(x, unit = "km", ...)
## S3 method for class 'rast' range(x, unit = "km", ...)
x |
A SpatRaster with presence-absence data (0 or 1) for a given species. |
unit |
Character. Default is "km", "m" and "ha" also available. |
... |
Additional arguments to be passed passed down from a calling function. |
A vector with an area in the chosen unit.
Calculates alpha diversity for taxonomic (TD),
functional (FD), and phylogenetic (PD) dimensions.
Adapted from alpha
spat.alpha(bin, tree, cores = 1, filename = "", ...)
spat.alpha(bin, tree, cores = 1, filename = "", ...)
bin |
A SpatRaster with presence-absence data (0 or 1) for a set of species. |
tree |
It can be a 'data.frame' with species traits or a 'phylo' with a rooted phylogenetic tree. Species names in 'tree' and 'bin' must match! |
cores |
A positive integer. If cores > 1, a 'parallel' package cluster with that many cores is created and used. |
filename |
Character. Save results if a name is provided. |
... |
Additional arguments to be passed passed down from a calling function. |
Alpha calculations use a tree-based approach for TD, FD, and PD (Cardoso et al. 2014). In the FD calculation, a species traits matrix is transformed into a distance matrix and clustered to create a regional dendrogram (i.e. a dendrogram with all species in the raster stack), from which the total branch length is calculated. When computing FD for each community (i.e. raster cell), the regional dendrogram is subsetted to create a local dendrogram that includes only the species present in the local community. The branch lengths connecting these species are then summed to represent the functional relationships of the locally present species (Petchey and Gaston, 2002, 2006). Similarly, in PD, the cumulative branch lengths connecting species within a community indicate their shared phylogenetic relationships (Faith, 1992). Alpha TD can also be visualized using a tree diagram, where each species is directly connected to the root by an edge of unit length, reflecting the number of different taxa in the community (i.e. species richness) since all taxa are at the same level (Cardoso et al. 2014).
A SpatRaster with alpha result.
Cardoso, P. et al. 2014. Partitioning taxon, phylogenetic and functional beta diversity into replacement and richness difference components. - Journal of Biogeography 41: 749–761.
Faith, D. P. 1992. Conservation evaluation and phylogenetic diversity. - Biological Conservation 61: 1–10.
Petchey, O. L. and Gaston, K. J. 2002. Functional diversity (FD), species richness and community composition. - Ecology Letters 5: 402–411.
Rodrigues, A. S. L. and Gaston, K. J. 2002. Maximising phylogenetic diversity in the selection of networks of conservation areas. - Biological Conservation 105: 103–111.
library(terra) bin1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) traits <- read.csv(system.file("extdata", "traits.csv", package = "divraster"), row.names = 1) tree <- ape::read.tree(system.file("extdata", "tree.tre", package = "divraster")) spat.alpha(bin1) spat.alpha(bin1, traits) spat.alpha(bin1, tree)
library(terra) bin1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) traits <- read.csv(system.file("extdata", "traits.csv", package = "divraster"), row.names = 1) tree <- ape::read.tree(system.file("extdata", "tree.tre", package = "divraster")) spat.alpha(bin1) spat.alpha(bin1, traits) spat.alpha(bin1, tree)
Alpha calculation for vector
spat.alpha.vec(x, tree, resu, ...)
spat.alpha.vec(x, tree, resu, ...)
x |
A numeric vector with presence-absence data (0 or 1) for a set of species. |
tree |
It can be a data frame with species traits or a phylogenetic tree. |
resu |
Numeric. A vector to store results. |
... |
Additional arguments to be passed passed down from a calling function. |
A vector with alpha result.
Alternative method to calculate alpha taxonomic diversity
spat.alpha2(bin, cores = 1, filename = "")
spat.alpha2(bin, cores = 1, filename = "")
bin |
A SpatRaster with presence-absence data (0 or 1) for a set of species. |
cores |
A positive integer. If cores > 1, a 'parallel' package cluster with that many cores is created and used. |
filename |
Character. Save results if a name is provided. |
A SpatRaster object with richness.
library(terra) bin1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) spat.alpha2(bin1)
library(terra) bin1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) spat.alpha2(bin1)
Calculates spatial beta diversity for
taxonomic (TD), functional (FD), and phylogenetic (PD)
dimensions. Adapted from beta
.
spat.beta( x, tree, filename = "", global = FALSE, fm = NULL, d = mean(terra::res(terra::rast(x))) * 2, type = "circle", na.policy = "omit", ... )
spat.beta( x, tree, filename = "", global = FALSE, fm = NULL, d = mean(terra::res(terra::rast(x))) * 2, type = "circle", na.policy = "omit", ... )
x |
A SpatRaster with presence-absence data (0 or 1) for a set of species. |
tree |
It can be a 'data.frame' with species traits or a 'phylo' with a rooted phylogenetic tree. Species names in 'tree' and 'x' must match! |
filename |
Character. Save results if a name is provided. |
global |
Logical. Mean of pairwise comparisons between focal cell and its neighbors (default) or mean of all pairwise comparisons. |
fm |
Numeric. Focal matrix ("moving window"). |
d |
Window radius to compute beta diversity. |
type |
Character. Window format. Default = "circle". |
na.policy |
Character. Default = "omit". See ?terra::focal3D for details. |
... |
Additional arguments to be passed passed down from a calling function. |
The TD beta diversity partitioning framework we used was developed by Podani and Schmera (2011) and Carvalho et al. (2012) and expanded to PD and FD by Cardoso et al. (2014).
A SpatRaster with beta results (total, replacement, richness difference, and ratio).
Cardoso, P. et al. 2014. Partitioning taxon, phylogenetic and functional beta diversity into replacement and richness difference components. - Journal of Biogeography 41: 749–761.
Carvalho, J. C. et al. 2012. Determining the relative roles of species replacement and species richness differences in generating beta-diversity patterns. - Global Ecology and Biogeography 21: 760–771.
Podani, J. and Schmera, D. 2011. A new conceptual and methodological framework for exploring and explaining pattern in presence - absence data. - Oikos 120: 1625–1638.
Hidasi-Neto, J. et al. 2019. Climate change will drive mammal species loss and biotic homogenization in the Cerrado Biodiversity Hotspot. - Perspectives in Ecology and Conservation 17: 57–63.
library(terra) bin1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) traits <- read.csv(system.file("extdata", "traits.csv", package = "divraster"), row.names = 1) rownames(traits) <- names(bin1) tree <- ape::read.tree(system.file("extdata", "tree.tre", package = "divraster")) spat.beta(bin1) spat.beta(bin1, traits) spat.beta(bin1, tree)
library(terra) bin1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) traits <- read.csv(system.file("extdata", "traits.csv", package = "divraster"), row.names = 1) rownames(traits) <- names(bin1) tree <- ape::read.tree(system.file("extdata", "tree.tre", package = "divraster")) spat.beta(bin1) spat.beta(bin1, traits) spat.beta(bin1, tree)
Spatial beta diversity for vector
spat.beta.vec(x, tree, global = FALSE, spp, nspp, ...)
spat.beta.vec(x, tree, global = FALSE, spp, nspp, ...)
x |
A numeric vector with presence-absence data (0 or 1) for a set of species. |
tree |
It can be a data frame with species traits or a phylogenetic tree. |
global |
Logical. Mean of pairwise comparisons between focal cell and its neighbors (default) or mean of all pairwise comparisons. |
spp |
Character. Species names. |
nspp |
Numeric. Number of species. |
... |
Additional arguments to be passed passed down from a calling function. |
A vector with beta results (total, replacement, richness difference, and ratio).
Calculates the standardized effect size for
functional and phylogenetic alpha diversity.
See bootspat_str
and
bootspat_naive
spat.rand( x, tree, aleats, random = c("site", "species", "both", "spat"), cores = 1, filename = "", ... )
spat.rand( x, tree, aleats, random = c("site", "species", "both", "spat"), cores = 1, filename = "", ... )
x |
SpatRaster. A SpatRaster containing presence-absence data (0 or 1) for a set of species. |
tree |
It can be a 'data.frame' with species traits or a 'phylo' with a rooted phylogenetic tree. Species names in 'tree' and 'x' must match! |
aleats |
positive integer. A positive integer indicating how many times the calculation should be repeated. |
random |
character. A character indicating the type of randomization. The currently available randomization methods are "spat", "site", "species" or "both" (site and species). |
cores |
positive integer. If cores > 1, a 'parallel' package cluster with that many cores is created and used. |
filename |
character. Output filename. |
... |
additional arguments to be passed passed down from a calling function. |
SpatRaster with Mean, SD, Observed, and SES.
x <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) traits <- read.csv(system.file("extdata", "traits.csv", package = "divraster"), row.names = 1) tree <- ape::read.tree(system.file("extdata", "tree.tre", package = "divraster")) spat.rand(x, tree, 3, "site") spat.rand(x, traits, 3, "site")
x <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) traits <- read.csv(system.file("extdata", "traits.csv", package = "divraster"), row.names = 1) tree <- ape::read.tree(system.file("extdata", "tree.tre", package = "divraster")) spat.rand(x, tree, 3, "site") spat.rand(x, traits, 3, "site")
Compute average for each trait.
spat.trait(x, trait, cores = 1, filename = "", ...)
spat.trait(x, trait, cores = 1, filename = "", ...)
x |
A SpatRaster with presence-absence data (0 or 1) for a set of species. |
trait |
A 'data.frame' with species traits. Rownames must have species names that match with 'x'! |
cores |
A positive integer. If cores > 1, a 'parallel' package cluster with that many cores is created and used. |
filename |
Character. Save results if a name is provided. |
... |
Additional arguments to be passed passed down from a calling function. |
SpatRaster with average traits.
library(terra) bin1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) traits <- read.csv(system.file("extdata", "traits.csv", package = "divraster"), row.names = 1) spat.trait(bin1, traits)
library(terra) bin1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) traits <- read.csv(system.file("extdata", "traits.csv", package = "divraster"), row.names = 1) spat.trait(bin1, traits)
Average trait calculation for vector
spat.trait.vec(x, col_trait, ...)
spat.trait.vec(x, col_trait, ...)
x |
A numeric vector with presence-absence data (0 or 1) for a set of species. |
col_trait |
A numeric vector with trait numbers. |
... |
Additional arguments to be passed passed down from a calling function. |
Vector of average trait.
Species suitability change between climate scenarios
suit.change(r1, r2, filename = "")
suit.change(r1, r2, filename = "")
r1 |
A SpatRaster with presence-absence data (0 or 1) for a set of species. |
r2 |
A SpatRaster with presence-absence data (0 or 1) for a set of species. |
filename |
Character. Save results if a name is provided. |
A SpatRaster with suitability change (gain, loss, unchanged, and unsuitable).
library(terra) r1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) r2 <- terra::rast(system.file("extdata", "fut.tif", package = "divraster")) suit.change(r1, r2)
library(terra) r1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) r2 <- terra::rast(system.file("extdata", "fut.tif", package = "divraster")) suit.change(r1, r2)
Calculates temporal beta diversity for
taxonomic (TD), functional (FD), and phylogenetic (PD)
dimensions. Adapted from beta
temp.beta(bin1, bin2, tree, filename = "", cores = 1, ...)
temp.beta(bin1, bin2, tree, filename = "", cores = 1, ...)
bin1 |
A SpatRaster with presence-absence data (0 or 1) for a set of species. |
bin2 |
A SpatRaster with presence-absence data (0 or 1) for a set of species. Species names in 'bin2' and 'bin1' must match! |
tree |
It can be a 'data.frame' with species traits or a 'phylo' with a rooted phylogenetic tree. Species names in 'tree', 'bin1', and 'bin2' must match! |
filename |
Character. Save results if a name is provided. |
cores |
A positive integer. If cores > 1, a 'parallel' package cluster with that many cores is created and used. |
... |
Additional arguments to be passed passed down from a calling function. |
The TD beta diversity partitioning framework we used was developed by Podani and Schmera (2011) and Carvalho et al. (2012) and expanded to PD and FD by Cardoso et al. (2014).
A SpatRaster with beta results (total, replacement, richness difference, and ratio).
Cardoso, P. et al. 2014. Partitioning taxon, phylogenetic and functional beta diversity into replacement and richness difference components. - Journal of Biogeography 41: 749–761.
Carvalho, J. C. et al. 2012. Determining the relative roles of species replacement and species richness differences in generating beta-diversity patterns. - Global Ecology and Biogeography 21: 760–771.
Podani, J. and Schmera, D. 2011. A new conceptual and methodological framework for exploring and explaining pattern in presence - absence data. - Oikos 120: 1625–1638.
Hidasi-Neto, J. et al. 2019. Climate change will drive mammal species loss and biotic homogenization in the Cerrado Biodiversity Hotspot. - Perspectives in Ecology and Conservation 17: 57–63.
library(terra) bin1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) bin2 <- terra::rast(system.file("extdata", "fut.tif", package = "divraster")) traits <- read.csv(system.file("extdata", "traits.csv", package = "divraster"), row.names = 1) tree <- ape::read.tree(system.file("extdata", "tree.tre", package = "divraster")) temp.beta(bin1, bin2) temp.beta(bin1, bin2, traits) temp.beta(bin1, bin2, tree)
library(terra) bin1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster")) bin2 <- terra::rast(system.file("extdata", "fut.tif", package = "divraster")) traits <- read.csv(system.file("extdata", "traits.csv", package = "divraster"), row.names = 1) tree <- ape::read.tree(system.file("extdata", "tree.tre", package = "divraster")) temp.beta(bin1, bin2) temp.beta(bin1, bin2, traits) temp.beta(bin1, bin2, tree)
Temporal beta diversity calculation for vector
temp.beta.vec(x, nspp, spp, tree, resu, ...)
temp.beta.vec(x, nspp, spp, tree, resu, ...)
x |
A numeric vector with presence-absence data (0 or 1) for a set of species. |
nspp |
Numeric. Number of species. |
spp |
Character. Species name. |
tree |
It can be a data frame with species traits or a phylogenetic tree. |
resu |
Numeric. A vector to store results. |
... |
Additional arguments to be passed passed down from a calling function. |
A vector with beta results (total, replacement, richness difference, and ratio).