Lesson 9 of 13 · 11 min
Alpha Diversity: Richness and Shannon
Alpha diversity measures how varied the community is inside a single sample, in contrast to beta diversity, which compares communities between samples. For amplicon and metagenomic data it answers two questions at once: how many distinct taxa (features, OTUs, or ASVs) are present, and how evenly the reads are spread across them. Each index below is a different way of collapsing those two ideas into one number per sample.
Richness, Shannon, Simpson
Observed richness is the raw count of features detected in a sample and ignores abundance entirely, so one read and ten thousand reads of a taxon count the same. The Shannon index adds evenness: it is highest when many features occur at similar abundances and drops when a few taxa dominate. The Simpson index reported by these tools is the probability that two reads drawn at random belong to different taxa, so it is driven by the most abundant members and is relatively insensitive to rare ones.
qiime diversity alpha \
--i-table table.qza \
--p-metric observed_features \
--o-alpha-diversity observed_features.qza
qiime diversity alpha \
--i-table table.qza \
--p-metric shannon \
--o-alpha-diversity shannon.qza
qiime diversity alpha \
--i-table table.qza \
--p-metric simpson \
--o-alpha-diversity simpson.qzaSaved SampleData[AlphaDiversity] to: observed_features.qza
Saved SampleData[AlphaDiversity] to: shannon.qza
Saved SampleData[AlphaDiversity] to: simpson.qza
Depth and rarefaction
Richness and Shannon both climb as you sequence deeper, because extra reads keep uncovering rare taxa, so a sample with 50,000 reads looks more diverse than the same community sampled at 5,000. A rarefaction curve plots a diversity metric against subsampled read depth and shows whether it has plateaued, meaning you have sequenced deeply enough to capture most of the richness. To compare samples fairly you either rarefy every sample to a common depth or model depth explicitly; alpha-rarefaction draws the curves and helps you pick that depth.
qiime diversity alpha-rarefaction \
--i-table table.qza \
--p-max-depth 20000 \
--p-metrics observed_features \
--p-metrics shannon \
--m-metadata-file metadata.tsv \
--o-visualization alpha-rarefaction.qzvlibrary(vegan)
# counts: a samples-by-features matrix of read counts
# meta: a data frame with a 'group' column, rows aligned to counts
richness <- specnumber(counts)
shannon <- diversity(counts, index = "shannon")
simpson <- diversity(counts, index = "simpson")
# rarefy richness to the shallowest sample before comparing
raremax <- min(rowSums(counts))
rarefied_richness <- rarefy(counts, raremax)
rarecurve(counts, step = 500, sample = raremax)
# Shannon is comparatively depth-robust, so we test it across groups;
# rarefy first (as above) if you compare richness instead
kruskal.test(shannon ~ meta$group) Kruskal-Wallis rank sum test
data: shannon by meta$group
Kruskal-Wallis chi-squared = 11.42, df = 2, p-value = 0.003307
Reading the result: a significantly higher Shannon or richness in one group means more taxa and/or a more even spread. In the gut, higher alpha diversity is often associated with stability and resilience, while a sharp drop follows antibiotics or accompanies conditions like IBD, but treat this as correlation, not cause. Caveats: alpha values depend on your OTU or ASV clustering and reference database, rarefaction discards reads and adds sampling noise, and 16S copy-number bias inflates some taxa, so never compare indices computed with different pipelines or at different depths.
Try it yourself: Using shannon.qza and your metadata, run qiime diversity alpha-group-significance with --i-alpha-diversity shannon.qza and --m-metadata-file metadata.tsv to reproduce the Kruskal-Wallis test inside QIIME 2. Then rarefy the same feature table to two depths, for example 5,000 and 15,000 reads, and check whether the significant group difference in observed richness holds at both. If it disappears, what does that tell you about sequencing depth as a confounder?