A diversity index calculator measures how varied a set of counts is. Enter the number of items in each category, such as the individuals of each species in a sample, and you get the Shannon entropy, in nats, bits and bans, Simpson's index, the Gini–Simpson index, the inverse Simpson index, the effective number of categories and the evenness. It covers what separate tools call a Shannon entropy calculator and a Simpson's diversity index calculator. It runs in your browser.
How to use the diversity index calculator
- Enter the count of each category, separated by spaces or commas.
- Press Calculate.
- Read the entropy and the Simpson indices.
Shannon entropy
The Wikipedia article on diversity indices gives the Shannon index as H′ = −Σ pᵢ ln pᵢ, where pᵢ is the share of the i-th category and the sum runs over all R categories.[1] The article on entropy defines the same quantity with a logarithm to any base, H = −Σ p log p, with base 2 giving bits, base e nats and base 10 bans, and the convention that 0 × log 0 is 0.[2] To change the unit, multiply by the logarithm of the old base to the new base. The calculator shows all three units. A fair coin, with two equal shares, has an entropy of exactly 1 bit, and the page says so.[2] A fair die has an entropy of log₂ 6, which is 2.585 bits by our calculation.
What the number means
The page explains that the entropy reaches its maximum, ln R, when all R categories have equal shares, and that it falls toward zero as one category comes to dominate.[1] A sample with one category has an entropy of zero. For the source with four letters at 70, 26, 2 and 2 percent, the page says that the entropy is below 2 bits.[2] The calculator gives about 1.09 bits, which shows how much the unequal shares cut the uncertainty.
Simpson's index
The diversity page defines Simpson's index as λ = Σ pᵢ², the probability that two items drawn with replacement are of the same type. It is high when diversity is low, which is why the inverse, 1 ÷ λ, and the form 1 − λ, known as the Gini–Simpson index, are often used instead.[1] For equal shares among R categories, λ takes its smallest value, 1 ÷ R. For the counts 70, 26, 2 and 2, λ = 0.49 + 0.0676 + 0.0004 + 0.0004 = 0.5584, the Gini–Simpson index is 0.4416, and the inverse Simpson index is 1.79. The inverse index can be read as the effective number of equally common categories.
The unbiased version
For counts from a sample taken without replacement, the page gives the unbiased form ℓ = Σ nᵢ(nᵢ − 1) ÷ (N(N − 1)), which it calls the Hunter–Gaston index.[1] It is the probability that two different items drawn from the sample are of the same type. For the counts above it is (4,830 + 650 + 2 + 2) ÷ 9,900 = 0.554. The calculator shows it whenever you enter whole-number counts with a total above one.
Effective numbers and evenness
The page notes that these indices are related to the Hill numbers: the number of categories is the Hill number of order 0, the exponential of the Shannon index is the Hill number of order 1, and the inverse Simpson index is the Hill number of order 2.[1] Each can be read as the number of equally common categories that would give the same diversity. The calculator shows exp(H′) as the effective number. For the counts above it is about 2.1, compared with 4 categories. Shannon evenness divides the entropy by its maximum, ln S, and so lies between 0 and 1. The pages that we read do not give this ratio, so it is our own addition.
Using the indices
Ecologists use them to compare habitats. A forest plot with 10 species in equal numbers is more diverse than one with 10 species of which a single one makes up 95 percent of the trees. Other fields use the same maths: the entropy measures the information in a message, the Gini–Simpson index is used in decision trees under the name Gini impurity, and the Simpson index appears in studies of the concentration of markets. Check that your categories are defined in the same way when you compare samples.
An example with species
Two small woods each have 100 trees of four species. The first has 25 of each, and the second has 85, 5, 5 and 5. For the first wood the entropy is 1.386 nats, or 2 bits, the evenness is 1, and the inverse Simpson index is 4, the same as the number of species. For the second the entropy is only 0.588 nats, or 0.848 bits, the evenness is 0.42 and the inverse Simpson index is 1.37. Both have four species, but the first is far more diverse in the sense of how evenly the trees are spread, and the indices show it. Enter the two sets of counts to see these figures.
Common mistakes
- Comparing samples of different sizes. Small samples understate diversity.
- Reading a high Simpson index as high diversity. λ is high when diversity is low.
- Counting zero categories. They add nothing.
- Mixing logarithm bases. Bits, nats and bans differ.
What next
Use this often? Add Diversity In to your Home screen.
Frequently asked questions
What is a diversity index calculator?
A tool that measures how varied a set of counts is, using the Shannon entropy and Simpson's index.
What is the formula for Shannon entropy?
H′ = −Σ pᵢ ln pᵢ, where pᵢ is the share of each category. Using base 2 gives bits.
What is Simpson's index?
λ = Σ pᵢ², the probability that two items drawn with replacement are of the same type. It is high when diversity is low.
What is the Gini–Simpson index?
1 − λ, the probability that two items drawn are of different types. Higher means more diverse.
What is the entropy of a fair coin?
Exactly 1 bit, and a fair die has log₂ 6, about 2.585 bits.
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.