gptomics/bioskills/biodiversity-metrics

Claude Code and agent skill by gptomics/bioskills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Quantifies biodiversity from species abundance/incidence tables using Hill numbers (iNEXT) with coverage-based rarefaction-extrapolation (Chao & Jost 2012), asymptotic richness via Chao1/ACE/jackknife as a lower bound, Baselga turnover/nestedness partition with the Podani alternative as sensitivity check, mandatory Hellinger transformation before ordination (Legendre & Gallagher 2001), Faith PD and SES_MPD/SES_MNTD with explicit null-model choice, and Maire 2015 functional-diversity dimensionality optimization. Use when comparing diversity across sites with unequal sampling effort, picking the right richness estimator for singleton-heavy amplicon data, partitioning beta diversity into turnover vs nestedness, reporting Hill-number effective species counts rather than raw entropies, computing SES_MPD with explicit null-model justification, or deciding whether to apply standard metrics to compositional amplicon data. Not for clinical 16S microbiome diversity (see microbiome/diversity-analysis).

Install

npx vskill@latest install gptomics/bioskills/biodiversity-metrics

SKILL.md

Version Compatibility

Reference examples tested with: iNEXT 3.0+, iNEXT.3D 1.0+, vegan 2.6+, betapart 1.6+, picante 1.8+, ggplot2 3.5+

Before using code patterns, verify installed versions match. If versions differ:

  • R: packageVersion('<pkg>') then ?function_name to verify parameters

If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.

Biodiversity Metrics

"Calculate species diversity for my ecological samples" -> Compute Hill-number diversity (numbers-equivalent of richness, Shannon, Simpson) with coverage-based rarefaction/extrapolation, choose the richness estimator appropriate to the singleton/doubleton signature of the data, and partition beta diversity into turnover and nestedness components with a documented partition framework.

  • R: iNEXT::iNEXT() for coverage-based rarefaction/extrapolation
  • R: betapart::beta.multi() for Baselga turnover/nestedness partition
  • R: picante::ses.mpd() for phylogenetic-community SES with explicit null model

The Single Most Important Modern Insight -- Standardize by COVERAGE not by sample size

Chao & Jost 2012 Ecology 93(12):2533-2547 established that comparing diversity across assemblages by rarefying to a common sample size systematically biases comparisons whenever assemblages differ in underlying diversity: a 100-read rarefaction of a 50-species community is essentially saturated (coverage approximately 99%) while the same 100 reads from a 500-species community covers only approximately 40% of the underlying diversity. The two rarefied diversities are not measuring the same thing. Coverage-based rarefaction with iNEXT is the postdoc-grade default; sample-size rarefaction is now considered a methodological anti-pattern for cross-site comparison.

A second insight pairs with this: raw Shannon and Simpson indices are entropies, NOT diversities. Jost 2006 Oikos 113(2):363-375 showed that only their numbers-equivalents (exp(H), 1/D) are comparable as effective species counts and have the intuitive "doubling property" (merging two equally diverse equally abundant assemblages doubles the diversity). Reporting raw Shannon = 3.2 vs 3.0 hides whether the difference is large or trivial; reporting 1D = 24.5 vs 20.1 species-equivalents makes the 22% gap visible.

Algorithmic Taxonomy

MethodEstimandStrengthFails when
Hill numbers q=0,1,2 (iNEXT)Effective species count at order qUnifies richness, Shannon, Simpson; doubling propertyNone; report all three q values
Chao1 = S + f1^2/(2*f2)Lower bound on asymptotic richnessNon-parametric; works at low coverageSingletons dominated by PCR error (amplicon data); f2 near zero
Chao1bc = S + f1(f1-1)/(2(f2+1))Bias-corrected Chao1Stable when f2 = 0Same singleton-bias issue
ACEAsymptotic richness using all rare classes (f1...f10)Uses more rare-class information than Chao1Choice of "rare" cutoff (default 10) is arbitrary
Jackknife1 = S + f1*(n-1)/nAsymptotic richness via resamplingRobust when f2 = 0Sensitive to singleton count alone
Coverage-based rarefaction (iNEXT)Diversity at standardized completenessCorrect comparison across sites with unequal effortExtrapolation beyond 2x reference size is unreliable
Sample-size rarefactionDiversity at common nLegacy familiarSystematically biased when communities differ in true diversity
Faith's PDSum of branch lengths on spanning treeCaptures evolutionary distinctnessSensitive to richness; report alongside SES_PD
Rao's QPairwise functional/phylogenetic distance * abundanceUnifies taxonomic and functional/phylogenetic diversityTrait dimensionality artifacts (see Maire 2015)
FRic / FEve / FDivFunctional richness/evenness/divergenceMultidimensional trait coverageFRic inflates with collinear traits; optimize axis count
Baselga beta partitionSorensen = turnover (Simpson) + nestednessDecomposes beta into ecological processesNot unique; Podani partition gives different components
Podani / Carvalho partitionAlternative turnover + richness-differenceConceptually distinct from BaselgaSame data, different conclusion possible; report both
Hellinger transform + PCA/RDASolves double-zero problemStandard for community ordinationNone; required preprocessing

Decision Tree by Scenario

ScenarioRecommended approachWhy
Cross-site diversity comparison with unequal sampling effortCoverage-based rarefaction in iNEXT to common C (typically 0.95)Sample-size rarefaction is biased when assemblages differ in true diversity
Reporting diversity for publicationHill numbers q=0,1,2 (numbers-equivalents)Comparable, additive, doubling property; raw entropies are not
Amplicon/eDNA data with many singletonsSkip Chao1 OR use after careful denoising; report Good's coverage alongsideSingletons in amplicon data are dominated by PCR error, not undersampling
Singleton-heavy real data (f1 >> f2)Chao1 with wide CI; cross-check with ACEChao1 variance grows as f1^4; ACE uses more rare-class information
f2 = 0 (no doubletons)Chao1bc or jackknife1Original Chao1 is undefined; bias-corrected form is the standard
Diversity at much larger sample size than observedStop extrapolation at 2x reference size (the doubling rule)iNEXT will silently extrapolate further; variance grows superlinearly beyond
Beta diversity for two assemblagesSorensen or Jaccard with Baselga partition; document choiceBray-Curtis is not a true metric and breaks some downstream methods
Beta diversity reported as turnover/nestednessRun BOTH Baselga AND Podani partitions and report bothThe partition is not mathematically unique; one alone hides ambiguity
Before PCA/RDA on community dataHellinger transformation firstSolves double-zero problem; raw Euclidean PCA on counts is malpractice
Phylogenetic community structure (NRI/NTI)SES_MPD with explicit null.model justificationDefault null may not match question; document choice
Functional diversity (FRic)Optimize PCoA axis count via Maire 2015 mAD; report chosen kFRic biased by trait-axis count; defaults (k=2-3) are too few
Amplicon/compositional dataEither presence/absence metrics (Chao2, Sorensen) OR explicit CLR-based diversity per Gloor 2017 Front Microbiol 8:2224Hill-numbers assume absolute abundances; amplicon counts are compositional

Hill Numbers and Why Raw Entropies Are Not Diversities

Goal: Report diversity values that are interpretable as effective species counts and additive under standard partitions.

Approach: Compute Hill numbers qD at q = 0, 1, 2 (Jost 2006 Oikos 113:363-375; iNEXT software paper Hsieh, Ma, Chao 2016 Methods Ecol Evol 7:1451-1456). q controls sensitivity to rare vs common species in a continuous parametric family: q=0 weights all species equally (richness); q=1 is the geometric-mean weighting (Shannon-equivalent exp(H)); q=2 weights down rare species rapidly (Simpson-equivalent 1/D). qD has the doubling property — merging two equally diverse equally abundant assemblages exactly doubles qD. Raw Shannon and Simpson values do NOT.

r
library(iNEXT)
library(vegan)
abundance_data <- list(
site_A = c(100, 45, 23, 12, 8, 5, 3, 2, 1, 1),
site_B = c(80, 60, 40, 30, 20, 15, 10, 8, 5, 3, 2, 1),
site_C = c(200, 10, 5, 2, 1, 1, 1)
)
# Hill numbers q=0,1,2 with coverage-based rarefaction/extrapolation
# nboot=200 is the publication-quality floor; default nboot=50 is too few for CIs
result <- iNEXT(abundance_data, q = c(0, 1, 2), datatype = 'abundance', nboot = 200)
# Report effective species counts at standardized coverage (postdoc-grade default)
# coverage=0.95: 95% of individuals in the underlying community belong to detected species
est <- estimateD(abundance_data, datatype = 'abundance', base = 'coverage', level = 0.95)
est
# For vegan equivalence: numbers-equivalent of Shannon
shannon_eff <- exp(diversity(community_matrix, index = 'shannon'))
# Inverse Simpson is already in numbers-equivalent units
invsimp <- diversity(community_matrix, index = 'invsimpson')

Asymptotic Richness — Chao1 is a Lower Bound, NOT a Point Estimate

Goal: Estimate the lower bound on true richness when sampling is incomplete and report it correctly.

Approach: Compute Chao1 from the singleton/doubleton ratio (Chao 1984), check that singletons are real biology rather than PCR/sequencing error, and report as a LOWER BOUND with Good's coverage to indicate sampling adequacy. Switch to ACE or jackknife1 when f2 is near zero or singletons are unreliable.

The original Chao1 derivation (Chao 1984) under a Gamma-Poisson mixture model produces a NON-PARAMETRIC LOWER BOUND on richness, not a point estimate. The bound is tight only under specific homogeneity assumptions. Reporting "Chao1 estimated richness = 320" without "at least" is widespread in published literature but statistically wrong.

r
library(iNEXT)
# AsyEst returns Chao1 (q=0), Chao-Shannon (q=1), Chao-Simpson (q=2) with CIs
asymp <- iNEXT(abundance_data, q = c(0, 1, 2), datatype = 'abundance')$AsyEst
# CRITICAL: also report Good's coverage to indicate whether the bound is informative
# Coverage < 0.85 means heavily under-sampled; Chao1 CI will be huge and bound is uninformative
coverage <- estimateD(abundance_data, datatype = 'abundance',
base = 'coverage', level = 0.95)
# Inspect estimateD output's Coverage column at the OBSERVED sample size
# Singleton check: if f1 >> f2 and singletons are likely PCR artifacts (amplicon data),
# do NOT report Chao1 — it will measure "how much PCR error" not "how much undiscovered diversity"
f1_check <- sapply(abundance_data, function(x) sum(x == 1))
f2_check <- sapply(abundance_data, function(x) sum(x == 2))
cat('Singletons f1:', f1_check, '\n')
cat('Doubletons f2:', f2_check, '\n')
cat('f1^2/(2*f2) Chao1 bound term:', f1_check^2 / (2 * pmax(f2_check, 0.5)), '\n')

Coverage-Based Rarefaction with the Doubling Rule

Goal: Compare diversity across sites at a common sampling completeness, with extrapolation bounded by statistical reliability.

Approach: Use iNEXT's coverage-based rarefaction-extrapolation interpolating to the minimum coverage across sites; bound extrapolation at 2x the reference sample size (Chao et al. 2014 Ecol Monogr 84:45-67 derive variance bounds that grow superlinearly beyond 2x).

r
# Type 3 (diversity vs coverage) is the cross-site comparison plot
# nboot=200 minimum for publication-quality CIs (default 50 is too few)
ggiNEXT(result, type = 3) + theme_bw() +
labs(title = 'Coverage-Based Hill-Number Diversity')
# The doubling rule: endpoint should be at most 2 * max(observed sample size)
# iNEXT default endpoint = 2 * max(sample size); do NOT override above this
# Beyond 2x, the variance estimate grows superlinearly and CIs become unreliable
# To extract numerical results at standardized coverage:
est_95 <- estimateD(abundance_data, datatype = 'abundance',
base = 'coverage', level = 0.95)

The Double-Zero Problem and Hellinger Transformation

Goal: Compute community dissimilarity in a way that does not treat shared absences as evidence of similarity.

Approach: Apply the Hellinger transformation (Legendre & Gallagher 2001 Oecologia 129:271-280) before computing Euclidean distance, PCA, or RDA. This is the single most important preprocessing decision for community ordination.

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
505
Repository forks
90
7-day trend score
31

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 18 Apr 2026, 7 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/gptomics/bioskills/biodiversity-metrics/badge)](https://verified-skill.com/skills/gptomics/bioskills/biodiversity-metrics)

Something wrong with this skill or its page? Tell us.