Package 'divraster'

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] , Neander Marcel Heming [aut] , Gabriela Alves-Ferreira [aut]
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

Help Index


Area calculation

Description

Area calculation

Usage

area.calc(r1, unit = "km", r2 = NULL, r3 = NULL, filename = "")

Arguments

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.

Value

A vector or a data.frame with area values in the chosen unit.

Examples

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

Description

Function to calculate distance and direction of change between centroids

Usage

dd.calc(raster1, raster2)

Arguments

raster1

A binary spatraster.

raster2

A binary spatraster.

Value

A data frame with distance and direction.

Examples

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

Description

Difference between raster objects

Usage

differ.rast(r1, r2, perc = TRUE, filename = "")

Arguments

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.

Value

A SpatRaster object with the difference between r1 and r2.

Examples

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

Description

Check if objects are valid

Usage

inputs_chk(bin1, bin2, tree)

Arguments

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!

Value

Either a success message or an error.


Load data adapted from Mota et al. (2022), Tobias et al. (2022), and Jetz et al. (2014)

Description

Load data adapted from Mota et al. (2022), Tobias et al. (2022), and Jetz et al. (2014)

Usage

load.data()

Value

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!

References

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.

Examples

data <- load.data()
data

Area calculation

Description

Area calculation

Usage

## S3 method for class 'list'
range(x, unit = "km", r2 = NULL, r3 = NULL, filename = "")

Arguments

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.

Value

A data.frame with area values in the chosen unit.


Area calculation

Description

Area calculation

Usage

## S3 method for class 'rast'
range(x, unit = "km", ...)

Arguments

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.

Value

A vector with an area in the chosen unit.


Alpha calculation for raster

Description

Calculates alpha diversity for taxonomic (TD), functional (FD), and phylogenetic (PD) dimensions. Adapted from alpha

Usage

spat.alpha(bin, tree, cores = 1, filename = "", ...)

Arguments

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.

Details

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).

Value

A SpatRaster with alpha result.

References

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.

Examples

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

Description

Alpha calculation for vector

Usage

spat.alpha.vec(x, tree, resu, ...)

Arguments

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.

Value

A vector with alpha result.


Alternative method to calculate alpha taxonomic diversity

Description

Alternative method to calculate alpha taxonomic diversity

Usage

spat.alpha2(bin, cores = 1, filename = "")

Arguments

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.

Value

A SpatRaster object with richness.

Examples

library(terra)
bin1 <- terra::rast(system.file("extdata", "ref.tif",
package = "divraster"))
spat.alpha2(bin1)

Spatial beta diversity for raster

Description

Calculates spatial beta diversity for taxonomic (TD), functional (FD), and phylogenetic (PD) dimensions. Adapted from beta.

Usage

spat.beta(
  x,
  tree,
  filename = "",
  global = FALSE,
  fm = NULL,
  d = mean(terra::res(terra::rast(x))) * 2,
  type = "circle",
  na.policy = "omit",
  ...
)

Arguments

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.

Details

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).

Value

A SpatRaster with beta results (total, replacement, richness difference, and ratio).

References

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.

Examples

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

Description

Spatial beta diversity for vector

Usage

spat.beta.vec(x, tree, global = FALSE, spp, nspp, ...)

Arguments

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.

Value

A vector with beta results (total, replacement, richness difference, and ratio).


Standardized Effect Size (SES) for raster

Description

Calculates the standardized effect size for functional and phylogenetic alpha diversity. See bootspat_str and bootspat_naive

Usage

spat.rand(
  x,
  tree,
  aleats,
  random = c("site", "species", "both", "spat"),
  cores = 1,
  filename = "",
  ...
)

Arguments

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.

Value

SpatRaster with Mean, SD, Observed, and SES.

Examples

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")

Average trait calculation for raster

Description

Compute average for each trait.

Usage

spat.trait(x, trait, cores = 1, filename = "", ...)

Arguments

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.

Value

SpatRaster with average traits.

Examples

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

Description

Average trait calculation for vector

Usage

spat.trait.vec(x, col_trait, ...)

Arguments

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.

Value

Vector of average trait.


Species suitability change between climate scenarios

Description

Species suitability change between climate scenarios

Usage

suit.change(r1, r2, filename = "")

Arguments

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.

Value

A SpatRaster with suitability change (gain, loss, unchanged, and unsuitable).

Examples

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)

Temporal beta diversity calculation for raster

Description

Calculates temporal beta diversity for taxonomic (TD), functional (FD), and phylogenetic (PD) dimensions. Adapted from beta

Usage

temp.beta(bin1, bin2, tree, filename = "", cores = 1, ...)

Arguments

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.

Details

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).

Value

A SpatRaster with beta results (total, replacement, richness difference, and ratio).

References

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.

Examples

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

Description

Temporal beta diversity calculation for vector

Usage

temp.beta.vec(x, nspp, spp, tree, resu, ...)

Arguments

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.

Value

A vector with beta results (total, replacement, richness difference, and ratio).