Species diversity in R

Diversity analysis in R, from alpha indices to beta diversity: which number answers which ecological question, what sampling effort does to it, and where it breaks.

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.

Effort, and the species you did not see

The step most papers skip, and the one that decides whether the comparison means anything.

Diversity in other currencies

Species are not interchangeable. These count them by what they do and where they come from.

Beta diversity: the space between sites

Where this connects

Newsletter

Get new tutorials by email

New R and QGIS tutorials for ecologists, straight to your inbox. No spam; unsubscribe anytime.

By subscribing you agree to receive these emails and confirm your address once. See the privacy policy.