
Calculate alpha diversity indices
Source:R/mStat_calculate_alpha_diversity.R
mStat_calculate_alpha_diversity.RdThis function calculates several alpha diversity indices (Shannon, Simpson, Observed Species, Chao1, ACE, Pielou, and Faith's PD) using the vegan and picante packages. The function takes a feature table (x) as input and returns a list containing the requested alpha diversity indices.
Arguments
- x
Feature table (e.g., OTU/ASV table) with taxa in rows and samples in columns.
- alpha.name
character vector containing the names of alpha diversity indices to calculate. Possible values are: "shannon", "simpson", "observed_species", "chao1", "ace", "pielou", and "faith_pd".
- tree
Phylogenetic tree object of class "phylo". Required for Faith's phylogenetic diversity ("faith_pd") calculation.
Examples
if (FALSE) { # \dontrun{
# Create example feature table
otu.tab <- matrix(data = rpois(100, 5), nrow = 10, ncol = 10)
rownames(otu.tab) <- paste0("Taxon_", 1:10)
colnames(otu.tab) <- paste0("Sample_", 1:10)
# Calculate non-phylogenetic alpha diversity indices
alpha.obj <- mStat_calculate_alpha_diversity(
x = otu.tab,
alpha.name = c("shannon", "simpson", "observed_species", "chao1", "ace", "pielou")
)
# Calculate Faith's PD when picante is available
if (requireNamespace("picante", quietly = TRUE)) {
tree <- ape::rtree(n = nrow(otu.tab), tip.label = rownames(otu.tab))
faith_pd <- mStat_calculate_alpha_diversity(
x = otu.tab,
alpha.name = "faith_pd",
tree = tree
)
}
} # }