Title: | Functional Rarity Indices Computation |
---|---|
Description: | Computes functional rarity indices as proposed by Violle et al. (2017) <doi:10.1016/j.tree.2017.02.002>. Various indices can be computed using both regional and local information. Functional Rarity combines both the functional aspect of rarity as well as the extent aspect of rarity. 'funrar' is presented in Grenié et al. (2017) <doi:10.1111/ddi.12629>. |
Authors: | Matthias Grenié [aut, cre] , Pierre Denelle [aut] , Caroline Tucker [aut] , François Munoz [ths] , Cyrille Violle [ths] |
Maintainer: | Matthias Grenié <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.5.0 |
Built: | 2024-11-08 04:28:35 UTC |
Source: | https://github.com/rekyt/funrar |
Internal function to compute combinations of distance matrices from a
data.frame of traits, using compute_dist_matrix()
.
combination_trait_dist(traits_table, ...)
combination_trait_dist(traits_table, ...)
traits_table |
a data.frame of traits with species in row and traits in columns, row names should be species names, |
... |
additional arguments supplied to |
A list of functional distance matrices, one for each provided trait plus an additional matrix for all traits taken altogether
Wrapper for cluster::daisy()
function in cluster
package,
to compute distance matrix of trait between each pair of species present in
given traits_table
, each row represents a species and each column
a trait. To be able to compute other metrics traits_table
must have
species name as row names.
compute_dist_matrix( traits_table, metric = "gower", center = FALSE, scale = FALSE )
compute_dist_matrix( traits_table, metric = "gower", center = FALSE, scale = FALSE )
traits_table |
a data.frame of traits with species in row and traits in columns, row names should be species names, |
metric |
character vector in list |
center |
logical that defines if traits should be centered (only in the
case of |
scale |
logical that defines if traits should be scaled (only in the
case of |
The functional distance matrix can be computed using any type of distance metric. When traits are both quantitative and qualitative Gower's (Gower, 1971; Podani, 1999) distance can be used. Otherwise, any other distance metric (Euclidean, Manhattan, Minkowski) can be used - as long as the rows and the columns are named following the species. When using mixed data consider also Gower's distance extension by Pavoine et al. (2009). IMPORTANT NOTE: in order to get functional rarity indices between 0 and 1, the distance metric has to be scaled between 0 and 1.
A functional distance matrix, column and row names follow
species name from traits_table
row names.
Gower, J.C. (1971) A general coefficient of similarity and some of its properties. Biometrics, 857–871. Podani, J. (1999) Extending Gower’s general coefficient of similarity to ordinal characters. Taxon, 331–340. Pavoine, S., Vallet, J., Dufour, A.-B., Gachet, S., & Daniel, H. (2009) On the challenge of treating various types of variables: application for improving the measurement of functional diversity. Oikos, 118, 391–402.
cluster::daisy()
which this function wraps, base stats::dist()
or ade4::dist.ktab()
for Pavoine et al. (2009) extension of Gower's
distance.
set.seed(1) # For reproducibility trait = data.frame( sp = paste("sp", 1:5), trait_1 = runif(5), trait_2 = as.factor(c("A", "A", "A", "B", "B"))) rownames(trait) = trait$sp dist_mat = compute_dist_matrix(trait[, -1])
set.seed(1) # For reproducibility trait = data.frame( sp = paste("sp", 1:5), trait_1 = runif(5), trait_2 = as.factor(c("A", "A", "A", "B", "B"))) rownames(trait) = trait$sp dist_mat = compute_dist_matrix(trait[, -1])
Computes functional distinctiveness from a site-species matrix (containing presence-absence or relative abundances) of species with provided functional distance matrix. The sites-species matrix should have sites in rows and species in columns, similar to vegan package defaults.
distinctiveness(pres_matrix, dist_matrix, relative = FALSE)
distinctiveness(pres_matrix, dist_matrix, relative = FALSE)
pres_matrix |
a site-species matrix (presence-absence or relative abundances), with sites in rows and species in columns |
dist_matrix |
a species functional distance matrix |
relative |
a logical indicating if distinctiveness should be scaled relatively to the community (scaled by max functional distance among the species of the targeted community) |
The Functional Distinctiveness of a species is the average functional distance from a species to all the other in the given community. It is computed as such:
with the functional distinctiveness of species
,
the total number of species in the community and
the
functional distance between species
and species
.
IMPORTANT NOTE: in order to get functional rarity indices between 0
and 1, the distance metric has to be scaled between 0 and 1.
a similar matrix from provided pres_matrix
with Distinctiveness
values in lieu of presences or relative abundances, species absent from
communities will have an NA
value (see Note
section)
Absent species should be coded by 0
or NA
in input matrices.
When a species is alone in its community the functional distinctiveness
cannot be computed (denominator = 0 in formula), and its value is assigned
as NaN
.
For speed and memory efficiency sparse matrices can be used as input of
the function using as(pres_matrix, "dgCMatrix")
from the
Matrix
package.
(see vignette("sparse_matrices", package = "funrar")
)
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) # Compute relative abundances mat = make_relative(mat) # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] # Distance matrix dist_mat = compute_dist_matrix(tra) di = distinctiveness(pres_matrix = mat, dist_matrix = dist_mat) di[1:5, 1:5] # Compute distinctiveness for all species in the regional pool # i.e., with all the species in all the communities # Here considering each species present evenly in the regional pool reg_pool = matrix(1, ncol = ncol(mat)) colnames(reg_pool) = colnames(mat) row.names(reg_pool) = c("Regional_pool") reg_di = distinctiveness(reg_pool, dist_mat)
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) # Compute relative abundances mat = make_relative(mat) # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] # Distance matrix dist_mat = compute_dist_matrix(tra) di = distinctiveness(pres_matrix = mat, dist_matrix = dist_mat) di[1:5, 1:5] # Compute distinctiveness for all species in the regional pool # i.e., with all the species in all the communities # Here considering each species present evenly in the regional pool reg_pool = matrix(1, ncol = ncol(mat)) colnames(reg_pool) = colnames(mat) row.names(reg_pool) = c("Regional_pool") reg_di = distinctiveness(reg_pool, dist_mat)
Computes functional distinctiveness from a site-species matrix (containing presence-absence or relative abundances) of species with provided functional distance matrix considering only species within a given range in the functional space. Basically species are cutoff when their dissimilarity is above the input threshold. The sites-species matrix should have sites in rows and species in columns, similar to vegan package defaults.
distinctiveness_alt(pres_matrix, dist_matrix, given_range)
distinctiveness_alt(pres_matrix, dist_matrix, given_range)
pres_matrix |
a site-species matrix (presence-absence or relative abundances), with sites in rows and species in columns |
dist_matrix |
a species functional distance matrix |
given_range |
a numeric indicating the dissimilarity range at which the the other species are considered maximally dissimilar |
The Functional Distinctiveness of a species is the average functional distance from a species to all the other in the given community. It is computed as such:
with the functional distinctiveness of species
,
the total number of species in the community and
the
functional distance between species
and species
.
is the chosen maximal range considered. The function
is an indicator function that returns 1 when
and 0 when
.
IMPORTANT NOTE: in order to get functional rarity indices between 0
and 1, the distance metric has to be scaled between 0 and 1.
a similar matrix from provided pres_matrix
with Distinctiveness
values in lieu of presences or relative abundances, species absent from
communities will have an NA
value (see Note
section)
Absent species should be coded by 0
or NA
in input matrices.
When a species is alone in its community the functional distinctiveness
cannot be computed (denominator = 0 in formula), and its value is assigned
as NaN
.
For speed and memory efficiency sparse matrices can be used as input of
the function using as(pres_matrix, "dgCMatrix")
from the
Matrix
package.
(see vignette("sparse_matrices", package = "funrar")
)
Given a stacked data.frame and a distance matrix compute the functional
distinctiveness for a single community. Functional distinctiveness relates to
the functional "originality" of a species in a community. The closer to 1 the
more the species is functionally distinct from the rest of the community. See
distinctiveness()
function or the functional rarity
indices vignette included in the package
(type vignette("rarity_indices", package = "funrar")
), for more details
on the metric. IMPORTANT NOTE: in order to get functional rarity indices
between 0 and 1, the distance metric has to be scaled between 0 and 1.
distinctiveness_com( com_df, sp_col, abund = NULL, dist_matrix, relative = FALSE )
distinctiveness_com( com_df, sp_col, abund = NULL, dist_matrix, relative = FALSE )
com_df |
a stacked (= tidy) data.frame from a single community with each row representing a species in a community |
sp_col |
a character vector, the name of the species column in |
abund |
a character vector, the name of the column containing relative abundances values |
dist_matrix |
a functional distance matrix as given by
|
relative |
a logical indicating if distinctiveness should be scaled relatively to the community (scaled by max functional distance among the species of the targeted community) |
the same data.frame with the additional Di column giving functional distinctiveness values for each species
This function is meant for internal uses mostly, thus it does not include any
tests on inputs and may fail unexpectedly. Please use
distinctiveness_stack()
to avoid input errors.
scarcity_com()
,
vignette("rarity_indices", package = "funrar")
and
distinctiveness()
Details section for detail on the index
From a trait data.frame and a site-species matrix compute Distinctiveness (average pairwise functional distance) for each species in each community on each provided trait and on all traits taken altogether.
distinctiveness_dimensions(pres_matrix, traits_table, ...)
distinctiveness_dimensions(pres_matrix, traits_table, ...)
pres_matrix |
a site-species matrix, with species in rows and sites in columns, containing presence-absence, relative abundances or abundances values |
traits_table |
a data.frame of traits with species in row and traits in columns, row names should be species names, |
... |
additional arguments supplied to |
a list of site-species matrix with functional distinctiveness values per species per site, with elements Di_X for distinctiveness computed on trait X and Di_all for distinctiveness computed on all traits.
uniqueness_dimensions()
, distinctiveness()
,
distinctiveness_stack()
and compute_dist_matrix()
for additional
arguments
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) rel_mat = make_relative(mat) # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] di_dim = distinctiveness_dimensions(rel_mat, tra)
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) rel_mat = make_relative(mat) # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] di_dim = distinctiveness_dimensions(rel_mat, tra)
Given a distance (or dissimilarity) matrix or dist()
objects compute
regional/global level distinctiveness as if all species were present in the
same community.
distinctiveness_global(dist_obj, di_name = "global_di")
distinctiveness_global(dist_obj, di_name = "global_di")
dist_obj |
a functional distance matrix as given by
|
di_name |
a character vector giving the name of the distinctiveness
column in the final data.frame (default: |
a data.frame with two columns: by default species
that contains the
species names and global_di
that contains the distinctiveness values.
The first column that contains species names can renamed based on dist_obj
dimnames
, while the second column is renamed through the di_name
argument.'
vignette("rarity_indices", package = "funrar")
and
distinctiveness()
Details section for detail on the index
Computes functional distinctiveness from a site-species matrix (containing presence-absence or relative abundances) of species with provided functional distance matrix considering only species within a given range in the functional space. The sites-species matrix should have sites in rows and species in columns, similar to vegan package defaults.
distinctiveness_range(pres_matrix, dist_matrix, given_range, relative = FALSE)
distinctiveness_range(pres_matrix, dist_matrix, given_range, relative = FALSE)
pres_matrix |
a site-species matrix (presence-absence or relative abundances), with sites in rows and species in columns |
dist_matrix |
a species functional distance matrix |
given_range |
a numeric indicating the dissimilarity range at which the the influence of other species is not considered anymore |
relative |
a logical indicating if distinctiveness should be scaled relatively to the community (scaled by max functional distance among the species of the targeted community) |
The Functional Distinctiveness of a species is the average functional distance from a species to all the other in the given community. It is computed as such:
with the functional distinctiveness of species
,
the total number of species in the community and
the
functional distance between species
and species
.
is the chosen maximal range considered. When presence-absence are used
and the term
is replaced by 1.
IMPORTANT NOTE: in order to get functional rarity indices between 0
and 1, the distance metric has to be scaled between 0 and 1.
a similar matrix from provided pres_matrix
with Distinctiveness
values in lieu of presences or relative abundances, species absent from
communities will have an NA
value (see Note
section)
Absent species should be coded by 0
or NA
in input matrices.
When a species is alone in its community the functional distinctiveness
cannot be computed (denominator = 0 in formula), and its value is assigned
as NaN
.
For speed and memory efficiency sparse matrices can be used as input of
the function using as(pres_matrix, "dgCMatrix")
from the
Matrix
package.
(see vignette("sparse_matrices", package = "funrar")
)
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) # Compute relative abundances mat = make_relative(mat) # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] # Distance matrix dist_mat = compute_dist_matrix(tra) di = distinctiveness_range(pres_matrix = mat, dist_matrix = dist_mat, 0.2) di[1:5, 1:5]
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) # Compute relative abundances mat = make_relative(mat) # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] # Distance matrix dist_mat = compute_dist_matrix(tra) di = distinctiveness_range(pres_matrix = mat, dist_matrix = dist_mat, 0.2) di[1:5, 1:5]
Compute Functional Distinctiveness for several communities, from a stacked
(or tidy) data.frame of communities, with one column for species identity,
one for community identity and an optional one for relative abundances. Also
needs a species functional distances matrix. Functional distinctiveness
relates to the functional "originality" of a species in a community. The
closer to 1 the more the species is functionally distinct from the rest of
the community. See distinctiveness()
function or the
functional rarity indices vignette included in the package
(type vignette("rarity_indices", package = "funrar")
), for more details
on the metric. IMPORTANT NOTE: in order to get functional rarity indices
between 0 and 1, the distance metric has to be scaled between 0 and 1.
You can either use _stack()
or _tidy()
functions as they are aliases of
one another.
distinctiveness_stack( com_df, sp_col, com, abund = NULL, dist_matrix, relative = FALSE ) distinctiveness_tidy( com_df, sp_col, com, abund = NULL, dist_matrix, relative = FALSE )
distinctiveness_stack( com_df, sp_col, com, abund = NULL, dist_matrix, relative = FALSE ) distinctiveness_tidy( com_df, sp_col, com, abund = NULL, dist_matrix, relative = FALSE )
com_df |
a stacked (= tidy) data.frame from a single community with each row representing a species in a community |
sp_col |
a character vector, the name of the species column in |
com |
a character vector, the column name for communities names |
abund |
a character vector, the name of the column containing relative abundances values |
dist_matrix |
a functional distance matrix as given by
|
relative |
a logical indicating if distinctiveness should be scaled relatively to the community (scaled by max functional distance among the species of the targeted community) |
the same data.frame with the additional Di column giving functional distinctiveness values for each species
scarcity_stack()
,
uniqueness_stack()
,
restrictedness_stack()
;
distinctiveness()
Details section for detail on the index
data("aravo", package = "ade4") # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] # Distance matrix dist_mat = compute_dist_matrix(tra) # Site-species matrix converted into data.frame mat = as.matrix(aravo$spe) mat = make_relative(mat) dat = matrix_to_stack(mat, "value", "site", "species") dat$site = as.character(dat$site) dat$species = as.character(dat$species) di_df = distinctiveness_stack(dat, "species", "site", "value", dist_mat) head(di_df)
data("aravo", package = "ade4") # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] # Distance matrix dist_mat = compute_dist_matrix(tra) # Site-species matrix converted into data.frame mat = as.matrix(aravo$spe) mat = make_relative(mat) dat = matrix_to_stack(mat, "value", "site", "species") dat$site = as.character(dat$site) dat$species = as.character(dat$species) di_df = distinctiveness_stack(dat, "species", "site", "value", dist_mat) head(di_df)
From a site-species matrix and functional distance matrix compute all indices included in the package: functional uniqueness (regional, functional), functional distinctiveness (local, functional), geographical restrictedness (regional, extent), scarcity (local, abundance). Note: scarcity can only be computed if relative abundances are provided in the site-species matrix.
funrar(pres_matrix, dist_matrix, rel_abund = FALSE)
funrar(pres_matrix, dist_matrix, rel_abund = FALSE)
pres_matrix |
a site-species matrix (presence-absence or relative abundances), with sites in rows and species in columns |
dist_matrix |
a species functional distance matrix |
rel_abund |
logical ( |
A list of 3 objects (or 4 if rel_abund = TRUE
):
a vector containing uniqueness values per species,
a site-species matrix with functional distinctiveness values per species per site,
a vector containing geographical restrictedness values per species,
and if rel_abund = TRUE
,
a site-species matrix with scarcity values per species per site.
uniqueness()
, distinctiveness()
, restrictedness()
,
scarcity()
From a stacked (= tidy) data.frame and functional distance matrix compute all indices included in the package: functional uniqueness (regional, functional), functional distinctiveness (local, functional), geographical restrictedness (regional, extent), scarcity (local, abundance). Note: scarcity can only be computed if relative abundances are provided in the data.frame.
funrar_stack(com_df, sp_col, com, abund = NULL, dist_matrix)
funrar_stack(com_df, sp_col, com, abund = NULL, dist_matrix)
com_df |
a stacked (= tidy) data.frame from a single community with each row representing a species in a community |
sp_col |
a character vector, the name of the species column in |
com |
a character vector, the column name for communities names |
abund |
a character vector, the name of the column containing relative abundances values |
dist_matrix |
a functional distance matrix as given by
|
A list of 3 objects (or 4 if abund
is not NULL
):
a vector containing uniqueness values per species,
a site-species matrix with functional distinctiveness values per species per site,
a vector containing geographical restrictedness values per species,
and if abund
is not NULL
,
a site-species matrix with scarcity values per species per site.
uniqueness_stack()
, distinctiveness_stack()
,
restrictedness_stack()
, scarcity_stack()
From an abundance/presence-absence matrix or data.frame tells if it contains relative abundances or absolute abundances. Checks if all abundances are between 1 and 0 but never checks sum of abundances per community.
is_relative(given_obj, abund = NULL)
is_relative(given_obj, abund = NULL)
given_obj |
abundance or presence-absence matrix, with sites in rows and species in columns, or tidy community data frame |
abund |
name of the column of the provided object that contains the abundances |
TRUE
if the input has relative abundances FALSE
otherwise
make_relative()
to transform matrix into a relative abundance
matrix.
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) head(mat)[, 1:5] # Has absolute abundances rel_mat = make_relative(mat) head(rel_mat) # Relative abundances # Forced to use ':::' becasue function is not exported funrar:::is_relative(mat) # FALSE funrar:::is_relative(rel_mat) # TRUE
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) head(mat)[, 1:5] # Has absolute abundances rel_mat = make_relative(mat) head(rel_mat) # Relative abundances # Forced to use ':::' becasue function is not exported funrar:::is_relative(mat) # FALSE funrar:::is_relative(rel_mat) # TRUE
From an abundance matrix (numbers of individuals of a given species at a site) returns a relative abundance matrix (proportion of individuals of a given species at a given site). This function works also with sparse matrices.
make_relative(abund_matrix)
make_relative(abund_matrix)
abund_matrix |
abundance matrix, with sites in rows and species in columns. |
Similar shaped matrix as the input but with relative abundances instead
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) head(mat)[, 1:5] # Has absolute abundances rel_mat = make_relative(mat) head(rel_mat) # Relative abundances
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) head(mat)[, 1:5] # Has absolute abundances rel_mat = make_relative(mat) head(rel_mat) # Relative abundances
From a matrix with values to a stacked (= tidy) data.frame, exclude NA from
given data.frame. If supplied object is not a matrix, try to coerce object
to matrix first. matrix_to_tidy()
is an alias of this function.
matrix_to_stack( my_mat, value_col = "value", row_to_col = names(dimnames(my_mat))[1], col_to_col = names(dimnames(my_mat))[2] )
matrix_to_stack( my_mat, value_col = "value", row_to_col = names(dimnames(my_mat))[1], col_to_col = names(dimnames(my_mat))[2] )
my_mat |
matrix you want to transform in stacked (= tidy) data.frame |
value_col |
(optional) character vector to use for value column (default: 'value') |
row_to_col |
(optional) character vector used for name of column in data.frame corresponding to rows in matrix (default: corresponding dimension name) |
col_to_col |
(optional) character vector used for name of column in data.frame corresponding to columns in matrix (default: corresponding dimension name) |
a stacked (= tidy) data.frame with, a column for row names, one for column names and a third one for the values.
stack_to_matrix()
for the reverse operation
data("aravo", package = "ade4") # Site-species matrix converted into data.frame mat = as.matrix(aravo$spe) dat = matrix_to_stack(mat, "value", "site", "species") str(dat)
data("aravo", package = "ade4") # Site-species matrix converted into data.frame mat = as.matrix(aravo$spe) dat = matrix_to_stack(mat, "value", "site", "species") str(dat)
Computes geographical restrictedness from a site-species matrix.
Geographical restrictedness is an index related to the extent of a species
in a given dataset, it is close to 1 when the species is present in only a
single site of the dataset (restricted) and close to 0 when the species is
present at all sites. It estimates the geographical extent of a species in a
dataset. See Details
section to have details on the formula used for
the computation. The sites-species matrix should have sites
in rows and species in columns, similar to vegan package
defaults.
restrictedness(pres_matrix, relative = FALSE)
restrictedness(pres_matrix, relative = FALSE)
pres_matrix |
a site-species matrix, with species in rows and sites in columns, containing presence-absence, relative abundances or abundances values |
relative |
a logical (default = FALSE), indicating if restrictedness should be computed relative to restrictedness from a species occupying a single site |
Geographical Restrictedness aims to measure the regional extent of a species in funrar it is computed the simplest way possible: a ratio of the number of sites where a species is present over the total number of sites in the dataset. We take this ratio off 1 to have a index between 0 and 1 that represents how restricted a species is:
where is the geographical restrictedness value,
the total
number of sites where species
occur and
the total number
of sites in the dataset.
When
relative = TRUE
, restrictedness is computed relatively to the
restrictedness of a species present in a single site:
Other approaches can be used to measure the geographical extent (convex hulls, occupancy models, etc.) but for the sake of simplicity only the counting method is implemented in funrar.
A stacked data.frame containing species' names and their
restrictedness value in the Ri column, similar to what
uniqueness()
returns.
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) ri = restrictedness(mat) head(ri)
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) ri = restrictedness(mat) head(ri)
Compute the geographical restrictedness for each species present in the
stacked data.frame. Geographical restrictedness is an index related to the
extent of a species in a given dataset, it is close to 1 when the species is
present in only a single site of the dataset (restricted) and close to 0 when
the species is present at all sites. It estimates the geographical extent of
a species in a dataset. See restrictedness()
for details
on restrictedness computation. You can either use _stack()
or _tidy()
functions as they are aliases of one another.
restrictedness_stack(com_df, sp_col, com, relative = FALSE) restrictedness_tidy(com_df, sp_col, com, relative = FALSE)
restrictedness_stack(com_df, sp_col, com, relative = FALSE) restrictedness_tidy(com_df, sp_col, com, relative = FALSE)
com_df |
a stacked (= tidy) data.frame of communities |
sp_col |
a character vector indicating the name of the species column |
com |
a character vector indicating the name of the community column |
relative |
a logical (default = FALSE), indicating if restrictedness should be computed relative to restrictedness from a species occupying a single site |
A stacked data.frame containing species' names and their
restrictedness value in the Ri column, similar to what
uniqueness_stack()
returns.
restrictedness()
, uniqueness_stack()
data("aravo", package = "ade4") # Site-species matrix converted into data.frame mat = as.matrix(aravo$spe) dat = matrix_to_stack(mat, "value", "site", "species") dat$site = as.character(dat$site) dat$species = as.character(dat$species) ri_df = restrictedness_stack(dat, "species", "site") head(ri_df)
data("aravo", package = "ade4") # Site-species matrix converted into data.frame mat = as.matrix(aravo$spe) dat = matrix_to_stack(mat, "value", "site", "species") dat$site = as.character(dat$site) dat$species = as.character(dat$species) ri_df = restrictedness_stack(dat, "species", "site") head(ri_df)
Computes scarcity from a relative abundance matrix of species. Scarcity is
close to 1 when a species is rare in a community and close to 0 when it is
abundant. It requires a site-species matrix with relative abundances. See
Details
section for the formula. The sites-species matrix should have
sites in rows and species in columns, similar to vegan
package defaults.
scarcity(pres_matrix)
scarcity(pres_matrix)
pres_matrix |
a site-species matrix, with species in rows and sites in columns, containing relative abundances values |
The scarcity of species is computed as follow:
with the scarcity of species
,
the total
number of species in the community and
the relative abundance
of species
in the community. Scarcity is thus a measure of the
local rarity in terms of abundances. If
is close to 1
the species has a very low abundances while if it's close to 0, it is
quite abundant in the community.
a similar matrix to pres_matrix
with scarcity values in lieu
of relative abundances.
vignette("rarity_indices", package = "funrar")
for details on the
scarcity metric; distinctiveness()
, restrictedness()
, uniqueness()
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) mat = make_relative(mat) si = scarcity(pres_matrix = mat) si[1:5, 1:5]
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) mat = make_relative(mat) si = scarcity(pres_matrix = mat) si[1:5, 1:5]
Given a stacked data.frame compute species scarcity. Scarcity measures how
abundant is a species locally. Scarcity is close to 1 when a species is rare
in a community and close to 0 when it is abundant. See scarcity()
function
or the functional rarity indices vignette included in the package (type
vignette("rarity_indices", package = "funrar")
) for details about the
index.
scarcity_com(com_df, sp_col, abund)
scarcity_com(com_df, sp_col, abund)
com_df |
a stacked (= tidy) data.frame from a single community with each row representing a species in a community |
sp_col |
a character vector, the name of the species column in |
abund |
a character vector, the name of the column containing relative abundances values |
the same data.frame with the additional Si column giving scarcity values for each species
This function is meant for internal uses mostly, thus it does not include any
tests on inputs and may fail unexpectedly. Please use scarcity_stack()
to
avoid input errors.
scarcity()
and vignette("rarity_indices", package = "funrar")
for details on the scarcity metric; distinctiveness_com()
to compute
distinctiveness on a single community
data("aravo", package = "ade4") # Site-species matrix converted into data.frame mat = as.matrix(aravo$spe) mat = make_relative(mat) dat = matrix_to_stack(mat, "value", "site", "species") dat$site = as.character(dat$site) dat$species = as.character(dat$species) si_df = scarcity_com(subset(dat, site == "AR07"), "species", "value") head(si_df)
data("aravo", package = "ade4") # Site-species matrix converted into data.frame mat = as.matrix(aravo$spe) mat = make_relative(mat) dat = matrix_to_stack(mat, "value", "site", "species") dat$site = as.character(dat$site) dat$species = as.character(dat$species) si_df = scarcity_com(subset(dat, site == "AR07"), "species", "value") head(si_df)
Compute scarcity values for several communities. Scarcity computation
requires relative abundances. Scarcity is close to 1 when a species is rare
in a community and close to 0 when it is abundant. See scarcity()
function
or the functional rarity indices vignette included in the package (type
vignette("rarity_indices", package = "funrar")
) for details about the
index. You can either use _stack()
or _tidy()
functions as they are
aliases of one another.
scarcity_stack(com_df, sp_col, com, abund) scarcity_tidy(com_df, sp_col, com, abund)
scarcity_stack(com_df, sp_col, com, abund) scarcity_tidy(com_df, sp_col, com, abund)
com_df |
a stacked (= tidy) data.frame from a single community with each row representing a species in a community |
sp_col |
a character vector, the name of the species column in |
com |
a character vector indicating the column name of communities ID in
|
abund |
a character vector, the name of the column containing relative abundances values |
The same table as com_df
with an added column
for Scarcity values.
scarcity()
and vignette("rarity_indices", package = "funrar")
for details on the scarcity metric; distinctiveness_stack()
,
restrictedness_stack()
, uniqueness_stack()
data("aravo", package = "ade4") # Site-species matrix converted into data.frame mat = as.matrix(aravo$spe) mat = make_relative(mat) dat = matrix_to_stack(mat, "value", "site", "species") dat$site = as.character(dat$site) dat$species = as.character(dat$species) si_df = scarcity_stack(dat, "species", "site", "value") head(si_df)
data("aravo", package = "ade4") # Site-species matrix converted into data.frame mat = as.matrix(aravo$spe) mat = make_relative(mat) dat = matrix_to_stack(mat, "value", "site", "species") dat$site = as.character(dat$site) dat$species = as.character(dat$species) si_df = scarcity_stack(dat, "species", "site", "value") head(si_df)
Passes from a stacked (= tidy) data.frame to a matrix. tidy_to_matrix()
is
an alias of this function.
stack_to_matrix( my_df, col_to_row, col_to_col, col_value = NULL, sparse = FALSE )
stack_to_matrix( my_df, col_to_row, col_to_col, col_value = NULL, sparse = FALSE )
my_df |
data.frame you want to transform in matrix |
col_to_row |
character vector of the name of the data.frame column you want to put into matrix rows |
col_to_col |
character vector of the name of the data.frame column you want to be as columns in matrix |
col_value |
(optional, default = |
sparse |
(optional, default = |
a matrix with given col_to_row
column in rows and col_to_col
column in columns. If some cells are not present in the data.frame (e.g. some
species not present at some sites), the matrix will have a NA
value.
matrix_to_stack()
for the reverse operation
example = data.frame("sites" = c(rep("1", 3), rep("2", 2)), "species" = c("A", "B", "C", "B", "D"), "abundance" = c(0.33, 0.33, 0.33, 0.4, 0.6)) mat = stack_to_matrix(example, "sites", "species", "abundance") mat
example = data.frame("sites" = c(rep("1", 3), rep("2", 2)), "species" = c("A", "B", "C", "B", "D"), "abundance" = c(0.33, 0.33, 0.33, 0.4, 0.6)) mat = stack_to_matrix(example, "sites", "species", "abundance") mat
Computes the functional uniqueness from a site-species matrix with the
provided functional distance matrix. Functional Uniqueness represents how
"isolated" is a species in the global species pool, it is the functional
distance to the nearest neighbor of the species of interest (see Details
section for the formula). The sites-species matrix should have sites
in rows and species in columns, similar to vegan package
defaults.
uniqueness(pres_matrix, dist_matrix)
uniqueness(pres_matrix, dist_matrix)
pres_matrix |
a site-species matrix (presence-absence or relative abundances), with sites in rows and species in columns |
dist_matrix |
a species functional distance matrix |
Functional Uniqueness is computed as follow:
with the functional uniqueness of species
, and
the functional distance between species
and species
A data.frame with functional uniqueness values per species, with one column with provided species column name and the Ui column with functional uniqueness values.
distinctiveness()
, restrictedness()
, scarcity()
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) colnames(mat) = as.character(colnames(mat)) # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] # Distance matrix dist_mat = compute_dist_matrix(tra) ui = uniqueness(mat, dist_mat) head(ui) # Computing uniqueness for each community com_ui = apply(mat, 1, function(x, dist_m) { smaller_com = x[x > 0 & !is.na(x)] uniqueness(t(as.matrix(smaller_com)), dist_m) }, dist_m = dist_mat)
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) colnames(mat) = as.character(colnames(mat)) # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] # Distance matrix dist_mat = compute_dist_matrix(tra) ui = uniqueness(mat, dist_mat) head(ui) # Computing uniqueness for each community com_ui = apply(mat, 1, function(x, dist_m) { smaller_com = x[x > 0 & !is.na(x)] uniqueness(t(as.matrix(smaller_com)), dist_m) }, dist_m = dist_mat)
From a trait table and a site-species matrix compute Uniqueness (nearest functional distance) for each species and each trait, plus computes it for all the traits.
uniqueness_dimensions(pres_matrix, traits_table, ...)
uniqueness_dimensions(pres_matrix, traits_table, ...)
pres_matrix |
a site-species matrix, with species in rows and sites in columns, containing presence-absence, relative abundances or abundances values |
traits_table |
a data.frame of traits with species in row and traits in columns, row names should be species names, |
... |
additional arguments supplied to |
a data.frame containing species' names and their uniqueness values for each traits (Ui_X column for trait X), as well as a column for the uniqueness value for all traits (Ui_all column)
distinctiveness_dimensions()
, uniqueness()
, uniqueness_stack()
and compute_dist_matrix()
for additional arguments
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) rel_mat = make_relative(mat) # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] ui_dim = uniqueness_dimensions(rel_mat, tra)
data("aravo", package = "ade4") # Site-species matrix mat = as.matrix(aravo$spe) rel_mat = make_relative(mat) # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] ui_dim = uniqueness_dimensions(rel_mat, tra)
Computes functional uniqueness values over a given regional pool. Functional
uniqueness gives the functional distance to the nearest-neighbor of a given
species in the provided distance matrix. See uniqueness()
function for
details on computation. You can either use _stack()
or _tidy()
functions
as they are aliases of one another.
uniqueness_stack(com_df, sp_col, dist_matrix) uniqueness_tidy(com_df, sp_col, dist_matrix)
uniqueness_stack(com_df, sp_col, dist_matrix) uniqueness_tidy(com_df, sp_col, dist_matrix)
com_df |
a data frame of the species in the regional pool. |
sp_col |
a character vector indicating the name of the species column
in the |
dist_matrix |
a functional distance matrix |
A data.frame with uniqueness value per species, with one column with provided species column name and the Ui column with the uniqueness values.
uniqueness()
and vignette("rarity_indices", package = "funrar")
for
details on the uniqueness metric; distinctiveness_stack()
,
restrictedness_stack()
, scarcity_stack()
data("aravo", package = "ade4") # Site-species matrix converted into data.frame mat = as.matrix(aravo$spe) dat = matrix_to_stack(mat, "value", "site", "species") dat$site = as.character(dat$site) dat$species = as.character(dat$species) # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] # Distance matrix dist_mat = compute_dist_matrix(tra) ui_df = uniqueness_stack(dat, "species", dist_mat) head(ui_df)
data("aravo", package = "ade4") # Site-species matrix converted into data.frame mat = as.matrix(aravo$spe) dat = matrix_to_stack(mat, "value", "site", "species") dat$site = as.character(dat$site) dat$species = as.character(dat$species) # Example of trait table tra = aravo$traits[, c("Height", "SLA", "N_mass")] # Distance matrix dist_mat = compute_dist_matrix(tra) ui_df = uniqueness_stack(dat, "species", dist_mat) head(ui_df)