mixle.analysis.coverage module¶
Sampling completeness, species richness, and diversity from frequency counts.
“How much of the population have I actually seen?” The same estimand recurs across fields: unseen probability mass in language models, undiscovered species in ecology, unobserved rare classes in machine learning. The answer comes from the frequencies of frequencies – especially how many items were seen exactly once (singletons) or twice (doubletons), which carry the signal about what is still missing.
turing_coverage()/good_turing()– sample coverage and the Good–Turing discounting that reallocates probability mass to unseen items (Good 1953; Gale & Sampson’s Simple Good–Turing).
chao1()/chao2()– nonparametric lower-bound richness estimators from abundance (Chao1) or replicated incidence (Chao2) data, with standard errors and log-normal CIs.
ace()/ice()– abundance/incidence coverage-based richness estimators (rare-species corrected).
hill_numbers()– the unified diversity profile (q=0richness,q=1exp-Shannon,q=2inverse Simpson).
rarefaction_curve()– expected richness as a function of sample size (Hurlbert interpolation), the basis for coverage-standardised comparison.
Counts are non-negative integer abundances per species; incidence inputs are a (species, sites)
0/1 matrix.
- turing_coverage(counts)[source]
Turing’s sample-coverage estimate and the complementary unseen probability mass.
C = 1 - f1 / nwheref1is the number of singletons andnthe total count: the estimated probability that the next observation is a previously seen species.1 - C = f1/nis the Good–Turing estimate of the total probability of all unseen species.
- good_turing(counts)[source]
Simple Good–Turing smoothed probabilities (Gale & Sampson 1995).
Reallocates probability from seen to unseen items using the frequencies of frequencies. Empirical Turing estimates
r* = (r+1) N_{r+1}/N_rare used for smallrand a smoothed log-linear fitS(r)takes over once the two diverge (the Gale switch), giving stable discounts in the sparse tail.- Parameters:
counts (ndarray) – per-species abundances (zeros ignored).
- Returns:
{'p0', 'proba', 'r_star', 'r'}–p0is the total probability assigned to unseen species;probaare the smoothed probabilities of the input species (aligned to the positive entries ofcounts, summing to1 - p0);r_star/rare the discounted and raw frequencies for the distinct abundance classes.- Return type:
- chao1(counts, *, ci_level=0.95)[source]
Chao1 nonparametric richness estimator from abundance data (bias-corrected).
S_chao1 = S_obs + f1 (f1 - 1) / (2 (f2 + 1))(Chao 1984, bias-corrected form), a lower bound on total richness driven by the singleton (f1) and doubleton (f2) counts. Returns a standard error and a log-normal confidence interval for the number of undetected species (Chao 1987), so the interval respectsS_chao1 >= S_obs.
- chao2(incidence, *, ci_level=0.95)[source]
Chao2 richness estimator from replicated incidence (presence/absence) data.
- Parameters:
- Returns:
{'estimate', 'observed', 'q1', 'q2', 'se', 'ci_low', 'ci_high', 'sites'}whereq1/q2are the numbers of species found in exactly one / two sites.- Return type:
- ace(counts, *, rare_threshold=10)[source]
ACE: Abundance-based Coverage Estimator of richness (Chao & Lee 1992).
Splits species into abundant (
> rare_threshold) and rare, estimates sample coverage from the rare group’s singletons, and corrects for the coefficient of variation of the rare abundances.
- ice(incidence, *, rare_threshold=10)[source]
ICE: Incidence-based Coverage Estimator of richness (the Chao–Lee estimator for incidence data).
- hill_numbers(counts, q=(0.0, 1.0, 2.0))[source]
Hill numbers (effective number of species) of order
q.The unified diversity profile:
q=0is observed richness,q=1is the exponential of Shannon entropy,q=2is the inverse Simpson concentration. Largerqweights common species more, so the profileD(q)summarises evenness as well as richness.
- rarefaction_curve(counts, sizes=None)[source]
Individual-based rarefaction: expected richness when subsampling
mindividuals (Hurlbert).E[S(m)] = sum_i (1 - C(n - x_i, m) / C(n, m))– the expected number of species seen in a random subsample ofmof thenindividuals. Used to compare richness between samples at a common sample size (or coverage).