knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(funrar)
In addition to single index functions funrar
proposes several functions to
help you compute functional rarity indices. The aim of this vignette is to
provide detailed examples of how to use each of them.
In this vignette we will use the dataset aravo
(you can learn more about it
through help("aravo", package = "ade4")
) from the ade4
package as for the
"Getting Started" vignette:
data("aravo", package = "ade4") # Extract the traits of all species of `aravo` traits = aravo$traits head(traits)
distinctiveness_global()
While functional distinctiveness has been envisioned initially at local scale,
that's what the distinctiveness()
function computes, it can be useful to
compute it at regional scales. This functions provides exactly that based on a
provided functional dissimilarity matrix.
Using the aravo
dataset we can compute the global distinctiveness of all species
across the dataset in the following way:
# Compute a Euclidean distance matrix (because all traits are quantitative) dist_matrix = compute_dist_matrix(traits, metric = "euclidean") # Compute global distinctiveness global_di = distinctiveness_global(dist_matrix) head(global_di)
The global distinctiveness is available in column global_di
.
You can rename this column using the second argument of
distinctiveness_global()
:
aravo_di = distinctiveness_global(dist_matrix, di_name = "aravo_di") head(aravo_di)
NB: distinctiveness_global()
assumes that all species in the provided
trait dataset are present at global/regional scale. It also assumes only a
presence-absence matrix.
Distinctiveness is generally computed through a dissimilarity matrix that itself comes from aggregating differences across multiple traits. Sometimes it can be useful to compare it to distinctiveness computed on each trait separately. This way, it is possible that some species appear distinct on certain traits and not others. The two functions below let you do exactly that for distinctiveness and uniqueness.
distinctiveness_dimensions()
The function distinctiveness_dimensions()
computes species local
distinctiveness values from a site-species matrix and a trait data.frame.
It will return a data frame with distinctiveness computed from all traits taken
together and each trait taken separately.
Let's do this with the traits from the aravo
dataset. The first argument of distinctiveness_dimensions()
is supposed to be site-species matrix while the second should be a traits table:
di_dim = distinctiveness_dimensions(as.matrix(aravo$spe), traits, metric = "euclidean") str(di_dim, max.level = 1)
We see that it returns a list of 9 local distinctiveness matrices: one for each
trait and one for all traits taken together (named di_all
).
uniqueness_dimensions()
The function uniqueness_dimensions()
computes species regional uniqueness
values from a site-species matrix and a trait data.frame. It will return a data
frame with uniqueness computed from all traits taken together and each trait
taken separately.
Let's do this with the traits from the aravo
dataset. The first argument of uniqueness_dimensions()
is supposed to be site-species matrix while the second should be a traits table:
ui_dim = uniqueness_dimensions(as.matrix(aravo$spe), traits, metric = "euclidean") str(ui_dim, max.level = 1)
We see that it returns a data frame with 10 columns: one for species names,
one for each trait separately, and one for all traits taken together
(named Ui_all
).
make_relative()
This function, probably largest source of citations of funrar
, transforms a
matrix of absolute abundances to relative abundances. It takes an abundance
matrix and returns the same matrix with relative abundances.
We can check that with aravo
site-species matrix:
aravo_site_sp = as.matrix(aravo$spe) # There are clearly abundances and not only presence-absence in this table aravo_site_sp[1:5, 1:5] # Compute total abundance per site site_abundance = rowSums(aravo_site_sp) head(site_abundance) # Compute a relative abundance matrix relative_site_sp = make_relative(aravo_site_sp) relative_site_sp[1:5, 1:5] rel_site_abundance = rowSums(relative_site_sp) head(rel_site_abundance)
We see, through rel_site_abundance
, that make_relative()
transformed the
abundances in each site so that they all sum to one. It divides the abundance of
each species by the total abundance of the site.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.