Diversity Indices

Diversity indices summarize one assemblage at a time. In DiversityAndDissimilarity.jl, use entropy when you want entropy units and diversity or effective_diversity when you want diversity-scale values.

julia> using DiversityAndDissimilarity

julia> assemblage = Dict(:oak => 12, :ash => 5, :elm => 3);

julia> diversity(Richness(), assemblage)
3

julia> entropy(Shannon(), assemblage)
1.3527241956246545

julia> diversity(Shannon(), assemblage)
2.5539392274300625

Available Methods

FamilyTypes and helpersMain optionsTypical use
RichnessRichness, richnessfrequenciesObserved positive-abundance taxa/categories.
Shannon entropyShannon, shannon_entropy, shannon_diversitybase, estimator, supportEntropy and effective diversity; low-count corrections.
Generalized entropyRenyi, Tsallis, renyi_entropy, tsallis_entropyorder q, baseDiversity profiles and Hill-number relationships.
Simpson familySimpson, GiniSimpson, InverseSimpsonfrequenciesDominance, Gini-Simpson diversity, and inverse Simpson diversity.
Hill numbersHill, hill_number, effective_diversityorder qEffective number of species/categories.
Richness estimatorsChao1, ACE, chao1, aceACE thresholdUnseen-richness estimation from abundance frequency counts.
CoverageSampleCoverage, sample_coveragefrequenciesGood-Turing style sample completeness.
EvennessPielouEvenness, pielou_evennessbaseShannon evenness relative to observed richness.
Fisher log-seriesFisherAlpha, fisher_alphafrequenciesFisher's alpha diversity parameter.
Linguistic diversityGreenbergDiversityIndex, LinguisticDiversityIndex, linguistic_diversity_indexfrequenciesGini-Simpson interpreted as probability of different mother tongues.

Inputs

All methods accept the same data shapes: dictionaries, numeric vectors, observation vectors, community matrices, and Tables.jl-compatible tables. See Data Input Formats for the complete reference.

julia> richness(["oak", "ash", "oak", "elm"])   # observation vector
3

julia> richness([1, 2, 1, 3]; frequencies=false)   # numeric obs. vector
3

julia> community = [1 1 2 0 5; 3 0 1 1 0];

julia> all(shannon_entropy(community) .≈ [1.6577427265048888, 1.3709505944546687])
true

Entropy And Effective Diversity

Shannon, Renyi, and Tsallis default to base=2, so entropy is reported in bits unless you choose another base.

\[H_b = -\sum_i p_i \log_b p_i\]

\[H_q = \frac{1}{1-q}\log_b\left(\sum_i p_i^q\right)\]

\[T_q = \frac{\sum_i p_i^q - 1}{(1-q)\log b}\]

The order q = 1 case for Renyi and Tsallis is evaluated as Shannon entropy. Effective diversity converts entropy-family quantities to Hill-number scale:

\[{}^qD = \left(\sum_i p_i^q\right)^{1/(1-q)}, \qquad {}^1D = b^H.\]

julia> entropy(Renyi(2), assemblage)
1.168122758808327

julia> effective_diversity(Renyi(2), assemblage)
2.247191011235955

julia> diversity(Hill(2), assemblage)
2.247191011235955

Shannon Estimators And Low-Count Options

Shannon accepts estimator objects:

julia> entropy(Shannon(; estimator=Plugin()), assemblage)
1.3527241956246545

julia> entropy(Shannon(; estimator=MillerMadow()), assemblage)
1.4248589476691027

julia> entropy(Shannon(; estimator=AddGamma(1)), assemblage; support=5)
1.7792365361682794

Use Plugin for the empirical estimate. Use MillerMadow for a simple observed-support bias correction. Use HausserStrimmer, Basharin, or AddGamma when a finite support is known. Use ChaoShen when support is unknown and unseen categories are plausible.

The support keyword can be an integer support size or a collection of known category labels:

julia> known_species = [:oak, :ash, :elm, :pine, :birch];

julia> entropy(Shannon(; estimator=AddGamma(0.5)), assemblage; support=known_species)
1.6295944962456386

For uncertainty, use analytic helpers where available or resampling:

entropy_variance(Shannon(; estimator=Basharin()), assemblage; support=5)
entropy_confint(Shannon(; estimator=ChaoShen()), assemblage)
bootstrap(Shannon(; estimator=AddGamma(1)), assemblage; support=5)
jackknife(Shannon(; estimator=MillerMadow()), assemblage)

Simpson, Linguistic Diversity, Richness, And Coverage

The Simpson family uses concentration

\[D = \sum_i p_i^2.\]

Simpson returns D, GiniSimpson returns 1 - D, and InverseSimpson returns 1 / D.

GreenbergDiversityIndex and LinguisticDiversityIndex are the same formula as Gini-Simpson but interpreted as the probability that two randomly selected people have different mother tongues.

Richness and coverage estimators use abundance-frequency counts:

julia> sparse = [5, 1, 1, 0, 0];

julia> richness(sparse)
3

julia> chao1(sparse)
4.0

julia> sample_coverage(sparse)
0.7142857142857143

Availability Checklist

Legend: [x] is available directly; [~] is available indirectly or with a different convention; [ ] is not documented as available in the checked source. Last checked: 2026-05-13.

Index or featureDiversityAndDissimilarity.jlDiversity.jlveganiNEXTscikit-bioEcoPyMicrobiome.jlSciPySpadeRentropartNotes
Observed richness / number of taxa[x][x][x][x][x][x][ ][ ][x][x]Richness() / richness; vegan specnumber; scikit-bio sobs / observed_features; EcoPy spRich.
Chao / ACE richness estimators[x][ ][x][x][x][ ][ ][ ][x][~]Chao1() / chao1 and ACE() / ace; vegan estimateR / specpool; iNEXT ChaoRichness; scikit-bio chao1 and ace.
Rarefied richness / rarefaction curves[ ][ ][x][x][~][x][ ][ ][~][ ]Outside this package's core scope; vegan and iNEXT are stronger rarefaction tools.
Shannon entropy, H[x][~][x][~][x][x][x][ ][x][x]Defaults to base=2 here; vegan defaults to natural logs.
Shannon effective diversity[x][x][~][x][x][x][ ][ ][x][x]effective_diversity(Shannon()); vegan derives it with exp(diversity(..., "shannon")).
Shannon entropy estimation[x][ ][ ][x][ ][ ][ ][ ][x][x]Plugin, MillerMadow, HausserStrimmer, Basharin, AddGamma, and ChaoShen are available here.
Sample coverage[x][ ][~][x][x][ ][ ][ ][x][x]SampleCoverage() / sample_coverage; related coverage estimates appear in iNEXT, scikit-bio, SpadeR, and entropart.
Simpson concentration, sum(p_i^2)[x][~][~][~][~][x][ ][ ][x][x]This package's Simpson() returns concentration; vegan index="simpson" returns 1-D.
Gini-Simpson, 1 - sum(p_i^2)[x][~][x][~][x][x][x][ ][x][~]GiniSimpson(); vegan diversity(..., "simpson").
Greenberg / linguistic diversity index[x][~][~][~][~][~][~][ ][~][~]Same formula as Gini-Simpson with linguistic-demography interpretation.
Inverse Simpson[x][x][x][x][x][x][ ][ ][x][x]InverseSimpson(); vegan index="invsimpson"; scikit-bio inv_simpson.
Hill number, general order q[x][x][~][x][x][~][ ][ ][x][x]Hill(q) and hill_number; Diversity.jl is stronger for partitioned Hill/Jost diversity.
Renyi entropy / diversity profile[x][~][x][ ][x][ ][ ][ ][~][x]Renyi(q; base=2) / renyi_entropy; vegan renyi; scikit-bio renyi.
Tsallis entropy[x][~][x][ ][x][ ][ ][ ][ ][x]Tsallis(q; base=2) / tsallis_entropy; vegan tsallis; scikit-bio tsallis.
Fisher alpha[x][ ][x][ ][x][ ][ ][ ][ ][ ]FisherAlpha() / fisher_alpha; vegan fisher.alpha; scikit-bio fisher_alpha.
Evenness / equitability[x][ ][~][ ][x][x][ ][ ][ ][ ]PielouEvenness() / pielou_evenness; scikit-bio and EcoPy provide additional evenness metrics.
Dominance / Berger-Parker style metrics[ ][ ][~][ ][x][x][ ][ ][ ][ ]Simpson concentration is available here, but broader dominance families are not.
UniFrac / Faith phylogenetic diversity[ ][x][~][ ][x][ ][ ][ ][ ][x]Out of scope here; Diversity.jl and scikit-bio are stronger phylogenetic options.
Rao quadratic entropy[ ][ ][ ][ ][ ][ ][ ][ ][ ][~]Specialist phylogenetic/functional diversity packages are better suited.
Alpha/beta/gamma diversity partitioning[ ][x][x][~][~][x][ ][ ][~][x]Not a core goal of this package.
Functional diversity[ ][~][~][ ][~][ ][ ][ ][ ][x]Specialist packages such as BAT, hillR, hilldiv, and entropart are stronger.

Reference

DiversityAndDissimilarity.PluginType

Plugin estimator for Shannon entropy.

This is the maximum-likelihood estimator (MLE) obtained by substituting the empirical probabilities into Shannon's definition.

DiversityAndDissimilarity.MillerMadowType

Miller-Madow estimator for Shannon entropy.

For $S$ observed positive-abundance species and sample size $n$, the correction added to Shannon entropy is

\[\frac{S - 1}{2n\log b},\]

where $b$ is the logarithm base.

DiversityAndDissimilarity.HausserStrimmerType

Hausser-Strimmer shrinkage estimator for Shannon entropy.

This shrinks empirical probabilities towards the uniform distribution over the known or observed support, then applies the plugin entropy estimator.

DiversityAndDissimilarity.BasharinType

Basharin bias-reduced estimator for Shannon entropy.

For known support size $S$ and sample size $n$, the correction added to the plugin estimator is

\[\frac{S - 1}{n\log b},\]

where $b$ is the logarithm base.

DiversityAndDissimilarity.AddGammaType
AddGamma(gamma)

Add-gamma estimator for Shannon entropy.

With support size $S$ and counts $n_i$, probabilities are estimated as

\[\hat p_i = \frac{n_i + \gamma}{n + \gamma S}.\]

DiversityAndDissimilarity.ChaoShenType

Chao-Shen estimator for Shannon entropy with possible unseen species.

This uses a Good-Turing coverage estimate and a Horvitz-Thompson adjustment. It is intended for samples where the true support may be larger than the observed support.

DiversityAndDissimilarity.RenyiType
Renyi(q; base=2)

Renyi entropy of order q.

The default logarithm base is 2, so entropy is measured in bits unless another base is provided. At q = 1, Renyi entropy is evaluated as Shannon entropy.

\[H_q = \frac{1}{1-q}\log_b\left(\sum_i p_i^q\right)\]

DiversityAndDissimilarity.TsallisType
Tsallis(q; base=2)

Tsallis entropy of order q, scaled to the requested logarithm base.

The default logarithm base is 2. At q = 1, Tsallis entropy is evaluated as Shannon entropy with the same base.

\[T_q = \frac{\sum_i p_i^q - 1}{(1-q)\log b}\]

Non-standard base scaling

The $\log b$ denominator scales the result so that $T_1$ equals Shannon entropy in the same base. This differs from the standard Tsallis definition $(1 - \sum_i p_i^q)/(q-1)$, which does not include a logarithm base factor. Values will differ from packages that use the standard definition by a factor of $\log b$.

DiversityAndDissimilarity.GreenbergDiversityIndexType

Greenberg's linguistic diversity index.

This is the probability that two randomly selected individuals have different mother tongues. It is mathematically the same quantity as Gini-Simpson diversity:

\[1 - \sum_i p_i^2\]

The index uses only relative mother-tongue frequencies. It does not account for second-language use, language vitality, or linguistic distance between languages.

DiversityAndDissimilarity.HillType
Hill(q)

Hill diversity of order q. Orders 0, 1, and 2 correspond to richness, Shannon effective diversity, and inverse Simpson diversity.

\[{}^qD = \left(\sum_i p_i^q\right)^{1/(1-q)}\]

DiversityAndDissimilarity.Chao1Type

Chao1 asymptotic richness estimator.

For observed richness $S_{obs}$, singleton count $f_1$, and doubleton count $f_2$, this package uses the bias-corrected abundance form

\[\hat S_{Chao1} = S_{obs} + \frac{f_1(f_1 - 1)}{2(f_2 + 1)}.\]

DiversityAndDissimilarity.ACEType
ACE(; threshold=10)

Abundance-based Coverage Estimator (ACE) for richness.

Species with counts up to threshold are treated as rare. The default threshold=10 follows the usual ACE convention.

DiversityAndDissimilarity.FisherAlphaType

Fisher's alpha diversity parameter.

Fisher's alpha solves

\[S = \alpha \log\left(1 + \frac{n}{\alpha}\right),\]

where $S$ is observed richness and $n$ is total abundance.

DiversityAndDissimilarity.entropyFunction
entropy(index, data; frequencies=true, support=nothing)

Evaluate an entropy index for data.

entropy is defined for Shannon, Renyi, and Tsallis. For dictionaries, values are abundances. Numeric vectors are abundance vectors by default. Non-numeric vectors are raw observations. Pass frequencies=false to treat a numeric vector as raw observations instead.

For Shannon, support may be an integer support size or a collection of known categories. Leave support=nothing when only the observed support is known, or when using ChaoShen for possible unseen categories.

For community matrices, rows are samples and columns are taxa/categories. The result is one entropy value per row.

DiversityAndDissimilarity.diversityFunction
diversity(index, data; frequencies=true, support=nothing)

Evaluate a diversity index for data.

For dictionaries, values are abundances. Numeric vectors are abundance vectors by default. Non-numeric vectors are raw observations. Pass frequencies=false to treat a numeric vector as raw observations instead.

For entropy-family indices, diversity returns the corresponding effective diversity. Use entropy when you want entropy units such as bits. For community matrices, rows are samples and columns are taxa/categories. The result is one diversity value per row.

DiversityAndDissimilarity.effective_diversityFunction
effective_diversity(index, data; frequencies=true)

Return an index as an effective number of species when the transformation is standard. For Shannon entropy this is

\[{}^1D = b^H.\]

For community matrices, rows are samples and columns are taxa/categories. The result is one effective-diversity value per row.

DiversityAndDissimilarity.shannon_entropyFunction
shannon_entropy(data; base=2, estimator=Plugin(), frequencies=true, support=nothing)

Return Shannon entropy for data.

The default logarithm base is 2, so entropy is measured in bits. Pass support when using finite-support estimators and the support is known.

DiversityAndDissimilarity.shannon_confintFunction
shannon_confint(data; base=2, estimator=Plugin(), level=0.95, frequencies=true, support=nothing)

Return a normal-approximation confidence interval for Shannon entropy.

DiversityAndDissimilarity.shannon_diversityFunction
shannon_diversity(data; base=2, estimator=Plugin(), frequencies=true, support=nothing)

Return Shannon effective diversity for data.

\[{}^1D = b^H\]

The default logarithm base is 2, matching Shannon.

DiversityAndDissimilarity.bootstrapFunction
bootstrap(index, data; nboot=1000, level=0.95, quantity=:entropy, rng=nothing)

Bootstrap a Shannon estimator from empirical abundance counts.

quantity=:entropy bootstraps entropy values. quantity=:diversity bootstraps effective Shannon diversity values. The returned named tuple contains the estimate, bootstrap variance, standard error, percentile interval, and replicates.

DiversityAndDissimilarity.renyi_entropyFunction
renyi_entropy(data, q; base=2, frequencies=true)

Return Renyi entropy of order q for data.

The default logarithm base is 2, matching Renyi.

\[H_q = \frac{1}{1-q}\log_b\left(\sum_i p_i^q\right)\]

DiversityAndDissimilarity.tsallis_entropyFunction
tsallis_entropy(data, q; base=2, frequencies=true)

Return Tsallis entropy of order q for data.

The default logarithm base is 2, matching Tsallis.

\[T_q = \frac{\sum_i p_i^q - 1}{(1-q)\log b}\]

DiversityAndDissimilarity.tsallis_diversityFunction
tsallis_diversity(data, q; base=2, frequencies=true)

Return the effective diversity corresponding to Tsallis entropy of order q.

\[{}^qD = \left(1 + (1-q)(\log b)T_q\right)^{1/(1-q)}\]

DiversityAndDissimilarity.aceFunction
ace(data; frequencies=true, threshold=10)

Return the abundance-based coverage estimator (ACE) for richness.

DiversityAndDissimilarity.greenberg_diversity_indexFunction
greenberg_diversity_index(data; frequencies=true)

Return Greenberg's linguistic diversity index, the probability that two randomly selected individuals have different mother tongues.

This is equivalent to Gini-Simpson diversity, $1 - \sum_i p_i^2$.

DiversityAndDissimilarity.index_of_linguistic_diversityFunction
index_of_linguistic_diversity(current, baseline; frequencies=true)

Return a Terralingua-style index of linguistic diversity (ILD) as the ratio of the current linguistic diversity index to a baseline linguistic diversity index.

A value of 1 indicates no change relative to the baseline; values below 1 indicate loss of linguistic diversity; values above 1 indicate an increase. This helper compares two assemblages and is therefore not itself a single-assemblage diversity index object.