Compute Functional Richness (FRic) for each community using convex hull volume in a PCA-based functional space. Wrapper around FD::dbFD.
compute_FRic <- function(comm, traits, ndim = 3, stand = TRUE) {
if (!requireNamespace("FD", quietly = TRUE)) install.packages("FD")
library(FD)
# Align species
sp_shared <- intersect(colnames(comm), rownames(traits))
comm <- comm[, sp_shared]
traits <- traits[sp_shared, ]
# Scale traits
traits_sc <- scale(traits)
# Run dbFD
res <- FD::dbFD(traits_sc, comm,
w.abun = FALSE,
stand.x = FALSE,
calc.FRic = TRUE,
m = ndim,
print.pco = FALSE)
data.frame(site = rownames(comm),
FRic = res$FRic,
stringsAsFactors = FALSE)
}