Hill number 0
|
Hill number 1
|
Hill number 2
|
|
|---|---|---|---|
| Dependent on presence and absence of taxonomic features, not abundance | Dependent on how evenly taxonomic features are distributed in a sample | The inverse of the probability of two randomly picked individuals belonging to the same taxonomic feature | |
|
Neutral Diversity
Weighs each taxon equally, no assumptions about phylogeny |
Richness (observed) | Shannon Entropy | Simpson’s Index |
|
Phylogenetic Diversity
Indices are scaled based on phylogenetic closeness with a phylogenetic tree |
Faith’s Phylogenetic Diversity | Phylogenetic Entropy | Rao’s Quadratic Diversity |
| The equation for general diversity can be defined as follows: \({}^qD = (\sum_{i=1}^{R}p^q_i)^{\frac{1}{(1-q)}}\), with q = Hill number, R = number of features, p = relative feature abundance. | |||
12 Alpha diversity
12.1 Background
Alpha diversity, or within-sample diversity, is a central concept in microbiome research. In ecological literature, several distinct but related alpha diversity indices, often referring to richness and evenness - the number of taxonomic features and how they are distributed, respectively - are commonly used (Whittaker 1960; Willis 2019). The term diversity can be used to collectively refer to all these indices.
12.1.1 Applications
Alpha diversity is predominantly used to quantify complexity in the microbiome. In the general adult population, lower alpha diversity and lower bacterial load have been associated with worse overall physical and mental health (Vandeputte et al. 2017; Valles-Colomer et al. 2019). However, this principle may not generalize to other populations, most notably in early life and in patient cohorts (Ma et al. 2019).
12.1.2 Approaches
The majority of alpha diversity metrics are closely related, though this is not evident from their names. Bastiaanssen et al. (2023) lay out this relationship across two factors (see table below): first, alpha diversity metrics can be defined as special cases of a unifying equation of diversity, where the Hill number determines the specific index captured. Lower Hill numbers favor richness, the number of distinct taxonomic features, whereas higher numbers favor evenness, how the taxonomic features are distributed over the sample (Hill 1973). Second, some alpha diversity metrics are weighted based on phylogeny, like Faith’s PD (1992). The table includes Shannon entropy (Shannon 1948), Simpson’s index (Simpson 1949), phylogenetic entropy (Allen et al. 2009) and Rao’s quadratic diversity (Rao 1982).
Cassol et al. (2025) offer practical guidelines for selecting alpha diversity indices. They classify alpha diversity into four main categories and recommend calculating at least one metric from each category, if possible, to sufficiently capture within-sample diversity. Since indices within the same category tend to be correlated, they suggest using the simplest available metric. Below are the default choices for each category:
- Richness: The number of observed unique features
- Dominance: Berger-Parker (Berger and Parker 1970)
- Information: Shannon (Shannon 1948)
- Phylogenetics: Faith
Several estimators have been developed to address the confounding effect of limited sampling size on observed richness, most notably ACE (Chao and Lee 1992) and Chao1 (Chao 1984). Notably, these approaches may yield misleading results for modern 16S data, which commonly features denoising and removal of singletons (Deng et al. 2024).
12.2 Examples
12.2.1 Calculate diversity
Alpha diversity can be estimated with the addAlpha() function, which includes built-in methods for calculating some indices, while others are computed via integration with the vegan package (Oksanen et al. 2020). The method calculates the given indices, and adds them to the colData slot of the SummarizedExperiment object with the given name.
# First, let's load some example data.
library(mia)
data("GlobalPatterns", package = "mia")
tse <- GlobalPatterns
# The 'index' parameter allows computing multiple diversity indices
# simultaneously. Without specification, four standard indices are calculated:
# dbp_dominance, faith_diversity, observed_richness, and shannon_diversity.
tse <- addAlpha(
tse,
assay.type = "counts"
)
# Check some of the first values in colData
tse$observed_richness |> head()
## [1] 6964 7679 5729 2667 2574 3214
tse$shannon_diversity |> head()
## [1] 6.577 6.777 6.498 3.828 3.288 4.289Certain indices have additional options. For example, observed richness has the detection parameter that controls the detection threshold (by default 0). Features above this threshold are considered detected. See the full list of options from help(addAlpha).
Because tse is a TreeSummarizedExperiment object, its phylogenetic tree is used by default. However, the optional argument tree must be provided if tse does not contain a rowTree.
12.2.2 Visualize diversity
As alpha diversity metrics typically summarize high-dimensional samples into single values, many visualization approaches are available. Once calculated, these metrics can be analyzed directly from the colData, for example, by plotting them using plotBoxplot() from the miaViz package. Here, we use the observed_richness as a measure of richness. Let’s visualize the results against the sample type in Figure 12.1.
library(miaViz)
plotBoxplot(
tse,
col.var = "observed_richness",
x = "SampleType"
) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(x = "Sample type", y = "Observed richness")
12.2.2.1 Comparing alpha diversity indices
We can compare alpha diversities for example by calculating the correlation between them. Figure 12.2 shows a visual comparison between Shannon and Faith indices as a scatter plot.
library(scater)
plotColData(tse, x = "shannon_diversity", y = "faith_diversity") +
labs(x = "Shannon index", y = "Faith (phylogenetic) index") +
geom_smooth(method = "lm")
cor.test(tse[["shannon_diversity"]], tse[["faith_diversity"]])
##
## Pearson's product-moment correlation
##
## data: tse[["shannon_diversity"]] and tse[["faith_diversity"]]
## t = 2.2, df = 24, p-value = 0.04
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.02719 0.68822
## sample estimates:
## cor
## 0.4102Let us visualize results from multiple alpha diversity measures against a given sample grouping available in colData (here, sample type). These have been readily stored in the colData slot, and they are thus directly available for plotting (Figure 12.3).
Show the plotting code
library(patchwork)
# Create the plots
p1 <- plotBoxplot(
tse,
col.var = "observed_richness", x = "SampleType", fill.by = "SampleType"
) +
labs(y = "Observed richness", fill = "Sample type")
p2 <- plotBoxplot(
tse,
col.var = "dbp_dominance", x = "SampleType", fill.by = "SampleType"
) +
labs(y = "Berger-Parker dominance", fill = "Sample type")
p3 <- plotBoxplot(
tse,
col.var = "shannon_diversity", x = "SampleType", fill.by = "SampleType"
) +
labs(y = "Shannon diversity", fill = "Sample type")
p4 <- plotBoxplot(
tse,
col.var = "faith_diversity", x = "SampleType", fill.by = "SampleType"
) +
labs(y = "Faith's PD", fill = "Sample type")
# Combine the plots and remove the sample type labels from the x-axis
wrap_plots(p1, p2, p3, p4, ncol = 1) +
plot_layout(guides = "collect") &
theme(
axis.text.x = element_blank(),
axis.title.x = element_blank(),
axis.ticks.x = element_blank()
)
All these different metrics provide information from different aspects of alpha diversity, notably on richness, dominance, information, and phylogenetic diversity described in Cassol et al. (2025). It is recommended to interpret these aspects separately and together.
From our example, we can observe that soil and freshwater (creek) have the highest number of different taxonomic features present while tongue microbiome has the lowest richness, suggesting greater biodiversity in soil and freshwater samples.
Based on the dominance values, species abundances in the soil samples appeared to be relatively evenly distributed. In contrast, the freshwater microbiome — particularly in the freshwater creek samples — was dominated by a single species, despite showing high observed richness.
These observations are supported by the Shannon index, which accounts for both richness and dominance. Soil samples showed the highest Shannon diversity, reflecting their high number of observed species and relatively even species distribution.
Soil and freshwater creek environments host a wide range of phylogenetically diverse organisms, indicating that the observed taxonomic features are not closely related but rather distinct from one another in terms of their evolutionary history.
In summary, soil samples exhibit the highest biodiversity, while human-derived samples show less variation in terms of species composition and evolutionary diversity.
12.2.3 Rarefaction
To control for uneven sampling depths, we can do rarefaction (Sanders 1968; Hurlbert 1971) (see Section 10.5). Rarefaction for alpha diversity metrics can be applied by specifying the optional arguments sample and niter in addAlpha(). niter controls the number of rarefaction iterations (choose a sufficiently large value for stable estimates). sample sets the rarefaction depth, i.e., the number of reads sampled per iteration from each sample (default: the smallest library size).
Next, we compare the results with and without rarefaction (Figure 12.4).
library(miaViz)
p1 <- plotBoxplot(tse, col.var = "observed_richness", fill.by = "SampleType") +
labs(y = "Observed richness", fill = "Sample type")
p2 <- plotBoxplot(tse, col.var = "richness_w_rarefaction", fill.by = "SampleType") +
labs(y = "Observed richness (rarefied)", fill = "Sample type")
p1 + p2 + plot_layout(guides = "collect")
These results illustrate that uneven sequencing depth affects the diversity estimates. The rarefied values are lower, as every sample is subsampled to the same, smaller depth, and the ranking of the sample types changes. Skin and estuary sediment samples, which have relatively few reads, rank higher after rarefaction, whereas the deeply sequenced freshwater samples rank lower. Soil remains the richest sample type in both analyses. This indicates that part of the apparent differences in the non-rarefied analysis was driven by sampling effort rather than biology.
12.2.4 Statistical testing
We can then analyze the statistical significance. We use the non-parametric Wilcoxon or Mann-Whitney test (Wilcoxon 1945; Mann and Whitney 1947), as it is more flexible than the commonly used Student’s t-test, since it does not assume normality.
pairwise.wilcox.test(
tse[["observed_richness"]], tse[["SampleType"]],
p.adjust.method = "fdr"
)
##
## Pairwise comparisons using Wilcoxon rank sum exact test
##
## data: tse[["observed_richness"]] and tse[["SampleType"]]
##
## Feces Freshwater Freshwater (creek) Mock Ocean
## Freshwater 0.3 - - - -
## Freshwater (creek) 0.3 0.4 - - -
## Mock 0.3 0.9 0.3 - -
## Ocean 0.8 1.0 0.3 1.0 -
## Sediment (estuary) 0.3 0.9 0.3 0.6 0.6
## Skin 0.3 0.9 0.3 1.0 1.0
## Soil 0.3 0.4 0.9 0.3 0.3
## Tongue 1.0 0.6 0.4 0.6 0.6
## Sediment (estuary) Skin Soil
## Freshwater - - -
## Freshwater (creek) - - -
## Mock - - -
## Ocean - - -
## Sediment (estuary) - - -
## Skin 0.6 - -
## Soil 0.3 0.3 -
## Tongue 0.4 0.6 0.4
##
## P value adjustment method: fdrWith only two to four samples per sample type, none of the pairwise differences is significant after FDR correction.
12.2.4.1 Visualizing significance in group-wise comparisons
Next, let’s compare the Shannon index between sample groups and visualize the statistical significance. plotBoxplot() can annotate pairwise group comparisons directly. By default, it uses Wilcoxon tests and adjusts p-values with the FDR method (Benjamini and Hochberg 1995). The resulting plot is shown in Figure 12.5.
# Subsets the data by selecting only samples from feces, skin, or tongue.
tse_sub <- tse[, tse[["SampleType"]] %in% c("Feces", "Skin", "Tongue")]
plotBoxplot(
tse_sub,
col.var = "shannon_diversity",
x = "SampleType",
add.significance = TRUE,
label = "p.adj"
) +
labs(x = "Sample type", y = "Shannon diversity")
12.3 Further reading
An article on ggpubr package provides further examples for estimating and highlighting significances.
12.4 Exercises
We use the Tengeler2020 dataset.
Solve the exercises in order, as each exercise continues from the previous one. Try to solve each exercise yourself before opening the solution.




