科研 Skill

生态多样性群落分析

ecological-diversity-analysis

Computes community-ecology diversity metrics and ordination: Shannon/Simpson indices, rarefaction, NMDS/PCoA, PERMANOVA. Use when analyzing species-by-site community composition data.

发布者 Codar安全审核通过v0.1.0更新于 2026-11-18

SKILL.md

Ecological Diversity and Community Analysis

Purpose

Covers the standard quantitative-ecology workflow for analyzing a species-by-site (or species-by-sample) community matrix: computing alpha-diversity indices, comparing diversity across sites with rarefaction, ordinating community composition to visualize similarity between samples, and testing whether groups of samples differ statistically (PERMANOVA/ANOSIM). This is the standard toolkit behind community ecology, conservation biology, and environmental monitoring studies (e.g., comparing biodiversity across habitats, before/after a disturbance, or along an environmental gradient) — a gap in a skill set that otherwise only covers species-occurrence download and distribution modeling (see gbif-biodiversity), not the follow-on community-level statistics.

Use when a dataset already has site x species abundance or presence/absence counts and the next step is quantifying and comparing biodiversity patterns, not downloading new occurrence records.

When to Use

  • Have a sites x species abundance/count matrix and need diversity indices, rarefaction curves, or richness estimates.
  • Need to test whether community composition differs between treatments, habitats, or time points (PERMANOVA, ANOSIM).
  • Need to visualize similarity/dissimilarity between samples via ordination (NMDS, PCoA) rather than raw high-dimensional species tables.
  • Comparing biodiversity across unevenly sampled sites (different numbers of individuals or samples) — this requires rarefaction, not a direct richness comparison.

Prerequisites

  • A tidy site x species matrix (rows = sites/samples, columns = species, values = abundance or presence/absence).
  • Python: scikit-bio, pandas, numpy, scipy; for ordination and PERMANOVA, scikit-bio's diversity, stats.distance modules, or Python port equivalents of R's vegan. R: the vegan package is the field-standard reference implementation (install.packages("vegan")) and is recommended when exact parity with published ecology methods matters.

Workflow

1. Compute alpha diversity (within-sample)

from skbio.diversity import alpha_diversity
import pandas as pd

counts = site_species_df.values  # rows = sites, cols = species
sample_ids = site_species_df.index

shannon = alpha_diversity("shannon", counts, ids=sample_ids)
simpson = alpha_diversity("simpson", counts, ids=sample_ids)
richness = alpha_diversity("observed_otus", counts, ids=sample_ids)
  • Richness (number of species observed) is highly sensitive to sampling effort — never compare raw richness across sites with different total abundance/sample sizes without rarefying first.
  • Shannon (H') weights by both richness and evenness; Simpson (1 - D) is more weighted toward dominant species and less sensitive to rare species than Shannon — report which index is used and why, since they can rank sites differently.
  • Pielou's evenness = H' / log(richness), useful to separate "many species but one dominant" from "many species, evenly abundant" communities with similar Shannon values.

2. Rarefaction for fair comparison across sampling effort

from skbio.diversity.alpha import sobs
import numpy as np

def rarefy(counts_row, depth, n_iter=100, seed=0):
    rng = np.random.default_rng(seed)
    results = []
    total = counts_row.sum()
    species_idx = np.repeat(np.arange(len(counts_row)), counts_row)
    for _ in range(n_iter):
        sample = rng.choice(species_idx, size=depth, replace=False)
        results.append(len(np.unique(sample)))
    return np.mean(results), np.std(results)
  • Rarefy all sites to the same depth (the smallest total count across sites, or a chosen common depth) before comparing richness; report both the rarefied mean and its variability across iterations.
  • For presence/absence or detection data with repeat visits, consider accumulation curves / Chao estimators (skbio.diversity.alpha.chao1) instead, which estimate asymptotic richness rather than observed-at-a-given-depth richness.
  • In R, vegan::rarefy() and vegan::specaccum() are the standard, well-tested implementations — prefer them over a custom reimplementation when R is available, since subtle bugs in resampling-without-replacement logic are easy to introduce.

3. Ordination (beta diversity visualization)

from skbio.diversity import beta_diversity
from skbio.stats.ordination import pcoa

bc_dm = beta_diversity("braycurtis", counts, ids=sample_ids)
ordination = pcoa(bc_dm)
coords = ordination.samples[["PC1", "PC2"]]
  • Bray-Curtis dissimilarity is the standard choice for abundance data; Jaccard for presence/absence data.
  • PCoA (principal coordinates analysis) gives an eigenvalue-based ordination directly from a distance matrix; NMDS (non-metric multidimensional scaling, vegan::metaMDS in R, or sklearn.manifold.MDS with metric=False as an approximation in Python) better preserves rank-order dissimilarity for noisy ecological data and reports a stress value — stress above ~0.2 indicates the chosen number of dimensions does not represent the data well and should be increased or the result interpreted cautiously.
  • Always report the dissimilarity metric used and, for NMDS, the final stress value alongside the ordination plot.

4. Test group differences (PERMANOVA / ANOSIM)

from skbio.stats.distance import permanova

result = permanova(bc_dm, grouping=site_metadata["treatment"],
                    permutations=999)
  • PERMANOVA (permutational multivariate ANOVA) tests whether group centroids differ in multivariate space; it is sensitive to differences in within-group dispersion (heterogeneity), not just location — run betadisper/PERMDISP (via vegan::betadisper in R) first to check whether a significant PERMANOVA result reflects a true compositional difference or merely unequal variance between groups.
  • Use enough permutations (999 is a common default; more for small p-values near a significance threshold) and report the exact p-value and permutation count, not just "p < 0.05."
  • ANOSIM is an older alternative with similar logic but is more sensitive to unequal sample sizes between groups; PERMANOVA is generally preferred in current ecological practice.

5. Report conventions

  • State the index/metric choices (which alpha-diversity index, which dissimilarity metric) and why, since different metrics can lead to different conclusions about the same data.
  • Report rarefaction depth and number of resampling iterations.
  • For ordination plots, report the method, distance metric, percent variance explained (PCoA) or stress (NMDS), and sample size per group.

Limitations

  • Assumes a clean site x species count/abundance matrix already exists; taxonomic identification, data cleaning, and occurrence download are out of scope (pair with gbif-biodiversity for sourcing raw occurrence records, or a project's own survey data pipeline).
  • vegan in R remains the most complete, field-validated reference implementation for these methods; the Python (scikit-bio) equivalents cover the core methods shown here but have a smaller feature surface (e.g., fewer built-in diversity indices and ordination methods) — for a methods section that must match established ecological literature exactly, cross-check against vegan.
  • Does not cover phylogenetic diversity metrics (e.g., Faith's PD, UniFrac) which require a phylogenetic tree as additional input, or functional-trait diversity, which requires a trait matrix.
  • PERMANOVA/NMDS results depend on the chosen dissimilarity metric and data transformation (e.g., Hellinger or log transforms for abundance data with many zeros); these choices should be justified, not defaulted blindly.

Quality Checklist

  • Alpha-diversity comparisons across sites use rarefied values (or an asymptotic estimator), not raw counts, when sampling effort differs.
  • Dissimilarity metric (Bray-Curtis, Jaccard, etc.) stated and appropriate for the data type (abundance vs. presence/absence).
  • NMDS stress value (if used) reported and checked against conventional thresholds (<0.2 acceptable, <0.1 good).
  • PERMANOVA accompanied by a dispersion check (betadisper/ PERMDISP) before interpreting group differences as compositional.
  • Permutation count and exact p-values reported.

示例提示词

我有样方物种计数矩阵,帮我算多样性指数并做NMDS排序和PERMANOVA检验。

所属插件

地球与环境科学面向地学、大气、海洋与生态研究:ERA5/CDS 气象数据、气候趋势、遥感与 GIS、水文、地震、空气质量、生物多样性与海洋绘图。

安装该插件会一并获得同领域的 18 个 Skill / MCP。

同插件的其他科研 Skill

常见问题

生态多样性群落分析能做什么?

Computes community-ecology diversity metrics and ordination: Shannon/Simpson indices, rarefaction, NMDS/PCoA, PERMANOVA. Use when analyzing species-by-site community composition data。

如何安装生态多样性群落分析?

在科搭 Codar 左侧点击「插件」,在「组件」页签搜索「生态多样性群落分析」并安装;在 Claude Code 或 Codex 中可以发送本页的安装提示词,或下载 Skill 包后解压到 ~/.claude/skills 或 ~/.codex/skills。

生态多样性群落分析需要哪些权限?

该科研 Skill没有声明额外权限;执行具体操作时仍由 Agent 按自身规则请求确认。

生态多样性群落分析经过官方审核吗?

是。SpeedSkills 收录的每个版本都会记录内容摘要与权限声明,当前版本已通过安全审核。