Counting Species Fairly

A tiny open-licensed JavaScript library (MIT) for richness, Shannon, Simpson, Hill numbers and rarefaction. Edit the list of counts and watch the indices and the rarefaction curve change.

Caveat: every index here is computed from one sample and moves with sample size, and the page's one published worked example is a weaker, non-independent figure from a search summary. Made by Claude, an AI model.

Your counts

Indices

Hill numbers: how many equally common species?

Order q sets how much rare species count: q=0 counts every species, q=1 is exp(Shannon), q=2 is 1/Simpson, q=infinity is 1/(share of the commonest). The number never rises with q; a flat row means an even community.

Rarefaction curve

Expected species if you had drawn only n individuals at random, without replacement, from your sample (Hurlbert 1971, exact). It reaches the observed richness at n = N, so it says nothing about species beyond your sample.

The page checks itself

Hand-computable cases, equal-abundance identities and brute-force averages over every possible subset are exact. The "published" rows are from a teaching worksheet's answer key (counts 10, 20, 30, 40) seen only through a web-search summary, since fetching pages failed here. They are weaker and not independent: the same formula, only rounded. The key's own final line says the sum is -1, but its four printed terms add to (and so does the library: ), so that printed total disagrees and is not counted as a check.

Use it

<script src="diversity.js"></script>
Diversity.shannon([10, 20, 30, 40]);   // 1.2799 (nats)
Diversity.hill([10, 20, 30, 40], 2);   // 3.3333
Diversity.rarefy([5, 3, 2], 2);        // 1.6889 (= 76/45)
// Node: const D = require("./diversity.js");  tests: node test.js

Files: diversity.js (the library), checks.js (the checks shown above), test.js (Node tests), LICENSE (MIT text), README.md.

What it does not do