functional_richness: Calculates functional richness

functional_richnessR Documentation

Calculates functional richness

Description

Calculates functional richness from a species-trait matrix and possibly an abundance vector.

Usage

functional_richness(
  x,
  w,
  a = rep(1, nrow(x)),
  relative = F,
  ndim = NULL,
  gower = T
)

Arguments

x

numeric matrix. Species-trait matrix.

w

an optional numeric vector. Trait weights for use in gower dissimilarity computation (if 'gower' = T).

a

optional numeric vector. Species-abundances.

relative

a logical. Calculate functional richness as a proportion of maximum value.

ndim

an optional integer. If supplied the trait space will be ordinated using principal coordinate analysis (PCoA) to a lower dimensional space equal to the value of this parameter. This can speed up the computational time significantly, and is almost mandatory if the number of traits is > 10.

gower

a logical. If true the trait dissimilarity metric will be gower dissimilarity, otherwise euclidean distance will be used.

Value

a number.

Details

When using 'relative=T', the maximum volume is computed as the product of the functional trait axis ranges, and standardization is carried out by dividing the convex hull volume by this hypercube volume.

OBS: The computation of the convex hull, is extremely slow for large numbers of species and traits. In that case, consider ordinating the traits to a lower dimensionality using the 'ndim' parameter.

References

\insertRef

Villeger2008asgerbachelor

Examples

## Not run: 
# An example using the data also supplied in the package. 
# Note that the first part of the example, 
# just shows how to create species-abundance and species-trait tables from the data, 
# as well as subsetting species in the intersection of both data sources.
library(hash)
FIA_dict <- hash(PLANTS_meta$plants_code, PLANTS_meta$fia_code)
PLANTS_dict <- invert(FIA_dict)

tSP <- FIA %>%
  filter(INVYR>2000) %>%
  group_by(ID,SPCD) %>%
  summarise(
    dens = mean(individuals/samples, na.rm = T),
    .groups = "drop"
  ) %>%
  filter(SPCD %in% values(FIA_dict,PLANTS_tG$traits$plants.code)) %>%
  pivot_wider(ID,SPCD,values_from=dens,names_prefix = "SP",values_fill = 0)

PLANTS_tG <- PLANTS_traits %>%
  filter(plants_code %in% values(PLANTS_dict, str_remove(names(tSP)[-1],"^SP"))) %>%
  gower_traits(T)

PCoA_traits <- ape::pcoa(FD::gowdis(PLANTS_tG$traits[,-1],PLANTS_tG$weights))

nPC <- PCoA_traits$values[,3:4] %>% 
  apply(1,diff) %>% 
  sign %>% 
  diff %>% 
  {
    which(.!=0)[1]
  } %>% 
  names %>% 
  as.numeric()

ordTraits <- PCoA_traits$vectors[,1:nPC]

par(mfrow = c(1,1))
functional_richness(ordTraits,tSP[,-1]) %>% 
  hist(main = "Distribution of functional richnesses\nat a 50x50 km scale in the FIA dataset",
       xlab = "Functional richness")

## End(Not run)

asgersvenning/bachelor documentation built on May 2, 2023, 7:06 a.m.