Species diversity in R
A diversity number is a compression. A species list with a hundred rows becomes one value, and the value is easy to plot, easy to compare across sites, and easy to put in a model. What gets lost in the compression is not random: every index throws away a different part of the assemblage, and the part it throws away is the part your reviewer will ask about.
This page collects every diversity tutorial on this site, in an order that makes sense to read. All of them work in R, most of them in base R, and the code is on the page rather than behind a package call.
What the indices actually measure
Richness counts species and ignores how common each one is. Shannon and Simpson mix richness and evenness together, in proportions you did not choose and cannot see in the output, which is why two assemblages with no species in common can return the same Shannon value. Hill numbers put that whole family on a single axis indexed by the order q: at q of zero you get richness, and as q rises the number pays less and less attention to rare species. Picking an index is picking how much weight rare species carry. That is an ecological decision about your question, not a statistical one about your data.
Then sampling effort gets involved
The number you compute describes your sample, not your site. More individuals and more plots both raise the species count whatever the truth is, so a richness comparison between an intensively sampled reserve and a quick survey next door is mostly a comparison of field time. Rarefaction and coverage standardisation are the two ways out, and they answer different questions: equal sample size and equal completeness can rank the same two assemblages in opposite directions.
Behind that sits the unseen tail. Species missed entirely are not a rounding error, and the estimators that reach for them (Chao1, ACE, the jackknives) are lower bounds, not corrections. Richness is the least estimable member of the Hill family precisely because it gives full weight to the species you are least likely to have caught.
Beta diversity is not one arithmetic
Once there is more than one site, the question becomes how much composition changes between them, and there are at least three unrelated ways to answer it: partition a dissimilarity into turnover and nestedness, divide gamma by alpha to get a multiplicative beta, or read beta as the variance of a site-by-species table. They are not variants of one quantity. They disagree, and each one carries a trap: additive beta on some indices is bounded by alpha, a naive arithmetic alpha can produce an impossible beta below one, and a site-level beta score rewards species-poor sites while the permutation test agrees with it.
Underneath all of them is the dissimilarity index, which is a decision you make before any of the arithmetic starts.
The tutorials
One sample, one number
Start here if you have a site-by-species table and need a defensible number out of it.
- Diversity indices in R - richness, Shannon and Simpson from a community matrix, with the code you will reuse in every later post.
- When not to use Shannon - what one number hides, and the cases where evenness or richness on their own say more.
- Estimating diversity with Hill numbers - the whole index family on one axis, and why the plug-in estimate is biased low.
Effort, and the species you did not see
The step most papers skip, and the one that decides whether the comparison means anything.
- Rarefaction and accumulation curves - separating diversity from field time, and the two curves that are not the same curve.
- Estimating species richness beyond your sample - Chao1, ACE and jackknife estimators, and why they stay lower bounds.
- Coverage-based rarefaction - standardising by completeness rather than size, and how far extrapolation can honestly go.
- Checking a diversity estimate - coverage deficit, singleton sensitivity, and what the interval can promise.
Diversity in other currencies
Species are not interchangeable. These count them by what they do and where they come from.
- Functional diversity - diversity from mixed traits, with Gower distance and Rao’s quadratic entropy.
- Phylogenetic diversity with picante - Faith’s PD, mean pairwise distance, and the effect sizes that make them comparable.
- Species abundance distributions - the shape behind the index, fitted and compared.
- Species-area relationships - the power law, the logarithmic model, and reading the exponent.
Beta diversity: the space between sites
- Beta diversity partitioning - splitting a dissimilarity into replacement and loss in the Baselga framework.
- Multiplicative beta diversity - gamma over alpha with Hill numbers, and the exact identity linking it to Sorensen.
- Beta diversity as variance - a beta score per site and per species, and two measured traps in reading them.
- Nestedness and NODF - nested structure, and the null model that decides the verdict.
- Distance decay of similarity - how shared species fall off with distance, and the permutation the test needs.
- Zeta diversity - the multi-site question pairwise dissimilarity cannot ask.
- Additive diversity partitioning - gamma as alpha plus beta, tested against a null.
- Checking a beta diversity analysis - effort, metric and site set, each shown flipping the verdict.
Where this connects
- Choosing a dissimilarity index sits underneath every beta diversity number on this page.
- Phylogenetic beta diversity and phylogenetic community structure take the same questions onto a tree.
- Species richness by data augmentation estimates the undetected tail with a community occupancy model instead of an asymptotic estimator.
- Bootstrap confidence intervals is where the interval around a Shannon value comes from, since there is no formula for it.
- Ordination in R is the next step once one number per site stops being enough.