Skip to content
cccskills
FreePublished on GitHub

bio-ecological-genomics-community-ecology

Analyzes community composition using constrained ordination (CCA, RDA, db-RDA), variance partitioning (varpart), indicator species analysis (indicspecies multipatt), and distance-based environmental gradient methods with vegan. Links species composition to environmental explanatory variables. Use when testing how environmental gradients structure species communities, identifying habitat indicator taxa, or partitioning explained variation among predictors. Not for basic unconstrained ordination and PERMANOVA (see microbiome/diversity-analysis).

The English summary is being prepared. Showing the original description.

Run score Not tested

See how to install

Files included (4)

  • SKILL.md9.1 KB
  • examples/constrained_ordination.R4.6 KB
  • examples/indicator_species.R2.9 KB
  • usage-guide.md4.1 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Version Compatibility

Reference examples tested with: ggplot2 3.5+, vegan 2.6+

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.

Community Ecology

"Test how environmental variables structure my species communities" → Link species composition to environmental gradients using constrained ordination (CCA, RDA, db-RDA), partition explained variation among predictor groups with varpart, and identify habitat indicator taxa with multipatt.

  • R: vegan::cca(), vegan::rda(), vegan::dbrda() for constrained ordination
  • R: indicspecies::multipatt() for indicator species analysis

Analyzes species-environment relationships using constrained ordination, variance partitioning, and indicator species analysis.

Canonical Correspondence Analysis (CCA)

CCA models unimodal species responses along environmental gradients. Appropriate when species have optima along gradients (bell-shaped response curves):

library(vegan)

# species_matrix: sites x species abundance matrix
# env_data: sites x environmental variables data frame
cca_result <- cca(species_matrix ~ temperature + precipitation + soil_pH + elevation,
                  data = env_data)

# Global permutation test (999 permutations by default)
anova(cca_result, permutations = 999)

# Per-axis significance
anova(cca_result, by = 'axis', permutations = 999)

# Per-term (marginal) significance
anova(cca_result, by = 'margin', permutations = 999)

# Proportion of variance explained
# Total inertia = constrained + unconstrained
summary(cca_result)$tot.chi
summary(cca_result)$constr.chi
prop_explained <- summary(cca_result)$constr.chi / summary(cca_result)$tot.chi

# Triplot: sites, species, and environmental vectors
plot(cca_result, display = c('sites', 'species', 'bp'), scaling = 2)

Redundancy Analysis (RDA)

RDA models linear species responses. Preferred when species respond linearly to gradients (short gradients, <= 3 SD):

# Hellinger transformation recommended for abundance data with RDA
# Reduces the weight of rare species and double-zero problem
species_hell <- decostand(species_matrix, method = 'hellinger')

rda_result <- rda(species_hell ~ temperature + precipitation + soil_pH + elevation,
                  data = env_data)

# Adjusted R-squared (corrected for number of predictors)
RsquareAdj(rda_result)

# Permutation test
anova(rda_result, permutations = 999)
anova(rda_result, by = 'margin', permutations = 999)

Forward Selection with ordiR2step

Selects the most parsimonious set of environmental predictors:

# Null model (intercept only)
rda_null <- rda(species_hell ~ 1, data = env_data)

# Full model (all predictors)
rda_full <- rda(species_hell ~ ., data = env_data)

# Forward selection using adjusted R-squared criterion
# Stops when adding variables no longer improves adjusted R^2
# or when p > 0.05 (permutation test)
rda_sel <- ordiR2step(rda_null, scope = formula(rda_full),
                      direction = 'forward', permutations = 999)

# Check VIF for collinearity in selected model
# VIF > 10: indicates problematic multicollinearity; remove or combine variables
vif.cca(rda_sel)

Distance-Based RDA (db-RDA)

Extends RDA to any distance metric using principal coordinates:

# Bray-Curtis distance for abundance data
bray_dist <- vegdist(species_matrix, method = 'bray')

# capscale (legacy) or dbrda (modern)
dbrda_result <- dbrda(bray_dist ~ temperature + precipitation + soil_pH,
                      data = env_data)

# Negative eigenvalues handled automatically (add correction if needed)
dbrda_result <- dbrda(bray_dist ~ temperature + precipitation + soil_pH,
                      data = env_data, add = 'lingoes')

anova(dbrda_result, permutations = 999)
anova(dbrda_result, by = 'margin', permutations = 999)

Variance Partitioning

Goal: Quantify the unique and shared contributions of environmental vs spatial predictors to community composition.

Approach: Run varpart with the species matrix and predictor groups to decompose variation into unique and shared fractions, then test each unique fraction's significance with partial RDA conditioned on the other group.

Quantifies the unique and shared contributions of 2-4 sets of explanatory variables:

# Partition variance between spatial and environmental predictors
# spatial_data: PCNM/MEM spatial eigenvectors or coordinates
# env_data: environmental variables
vp <- varpart(species_hell, env_data, spatial_data)

# Fractions: [a] = unique environment, [b] = shared, [c] = unique spatial, [d] = residual
vp

# Venn diagram of explained variation
plot(vp, digits = 2, bg = c('skyblue', 'tomato'))

# Test significance of unique fractions (testable fractions only)
# [a] unique environment
anova(rda(species_hell ~ . + Condition(as.matrix(spatial_data)), data = env_data),
      permutations = 999)

# [c] unique spatial
anova(rda(species_hell ~ . + Condition(as.matrix(env_data)), data = as.data.frame(spatial_data)),
      permutations = 999)

Three-Way Partition

# Environment, space, and time
vp3 <- varpart(species_hell, env_data, spatial_data, temporal_data)
plot(vp3, digits = 2, bg = c('skyblue', 'tomato', 'gold'))

Indicator Species Analysis

Identifies species significantly associated with site groups using the IndVal index:

library(indicspecies)

# site_groups: factor or vector of group assignments per site
# multipatt tests association of each species with group combinations
# func='IndVal.g': group-equalized indicator value (handles unbalanced groups)
# duleg=TRUE: only tests individual groups, not combinations
mp <- multipatt(species_matrix, site_groups, func = 'IndVal.g',
                duleg = TRUE, control = how(nperm = 999))

summary(mp)

# Extract significant indicators
# p.value < 0.05: standard significance threshold
sig_indicators <- mp$sign[mp$sign$p.value < 0.05, ]
sig_indicators <- sig_indicators[order(sig_indicators$p.value), ]
sig_indicators

Point-Biserial Correlation

# Alternative: r.g function for point-biserial correlation coefficients
# More interpretable effect sizes than IndVal
pb <- multipatt(species_matrix, site_groups, func = 'r.g',
                duleg = TRUE, control = how(nperm = 999))
summary(pb)

CCA vs RDA Decision

CriterionUse CCAUse RDA
Gradient length> 3 SD (DCA axis 1)<= 3 SD (DCA axis 1)
Species responseUnimodal (bell curves)Linear
Data transformationRaw abundances OKHellinger recommended
Chi-square distanceAppropriateNot appropriate

Check gradient length with DCA:

dca <- decorana(species_matrix)
# Axis 1 length > 3 SD: unimodal methods (CCA)
# Axis 1 length <= 3 SD: linear methods (RDA)
dca

Publication-Quality Triplot

Goal: Create a journal-ready CCA triplot showing sites, species, and environmental vectors in a single ordination figure.

Approach: Extract site, species, and biplot scores from the CCA result, combine into data frames, and overlay points, text labels, and arrow segments in ggplot2.

library(ggplot2)

# Extract scores for ggplot
site_scores <- scores(cca_result, display = 'sites', scaling = 2)
species_scores <- scores(cca_result, display = 'species', scaling = 2)
env_scores <- scores(cca_result, display = 'bp', scaling = 2)

site_df <- as.data.frame(site_scores)
site_df$group <- env_data$habitat_type

sp_df <- as.data.frame(species_scores)
env_df <- as.data.frame(env_scores)
env_df$label <- rownames(env_df)

ggplot() +
    geom_point(data = site_df, aes(x = CCA1, y = CCA2, color = group), size = 3) +
    geom_text(data = sp_df, aes(x = CCA1, y = CCA2, label = rownames(sp_df)),
              size = 2, color = 'grey50', alpha = 0.7) +
    geom_segment(data = env_df, aes(x = 0, y = 0, xend = CCA1, yend = CCA2),
                 arrow = arrow(length = unit(0.2, 'cm')), color = 'red') +
    geom_text(data = env_df, aes(x = CCA1 * 1.1, y = CCA2 * 1.1, label = label),
              color = 'red', size = 3.5) +
    theme_bw() +
    labs(title = 'CCA Triplot')

Related Skills

  • biodiversity-metrics - Alpha and beta diversity metrics
  • edna-metabarcoding - Generate community data from eDNA
  • landscape-genomics - Genotype-environment associations
  • microbiome/diversity-analysis - Unconstrained ordination alternative
  • data-visualization/ggplot2-fundamentals - Custom ordination plots

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Workflow for read alignment, sorting, indexing, mapping statistics, and downstream-ready alignment artifacts.

The English summary is being prepared. Showing the original description.

BioTender-max/awesome-bio-agent-skills206Updated Jul 2, 2026

Validate protein designs using AlphaFold2 structure prediction. Use this skill when: (1) Validating designed sequences fold correctly, (2) Predicting binder-target complex structures, (3) Calculating confidence metrics (pLDDT, pTM, ipTM), (4) Self-consistency validation of designs, (5) Multi-chain complex prediction with AlphaFold-Multimer. For faster single-chain prediction, use esm. For QC thresholds, use protein-qc.

The English summary is being prepared. Showing the original description.

BioTender-max/awesome-bio-agent-skills206Updated Jul 2, 2026

AlphaFold2 / AlphaFold-Multimer structure prediction for validation and confidence scoring. Use this skill when: (1) Validating designed sequences fold correctly, (2) Predicting binder-target complex structures, (3) Calculating confidence metrics (pLDDT, pTM, ipTM), (4) Self-consistency validation of designs, (5) Multi-chain complex prediction with AlphaFold-Multimer. For faster single-chain prediction, use esm2-sequence-scoring. For QC thresholds, use protein-design-qc.

The English summary is being prepared. Showing the original description.

BioTender-max/awesome-bio-agent-skills206Updated Jul 2, 2026

Workflow for event-level and isoform-level splicing analysis with sashimi-ready outputs and splice QC.

The English summary is being prepared. Showing the original description.

BioTender-max/awesome-bio-agent-skills206Updated Jul 2, 2026

ATAC-seq processing with assay QC, MACS3 peak calling, consensus peak matrices, differential accessibility, and motif or footprint follow-up.

The English summary is being prepared. Showing the original description.

BioTender-max/awesome-bio-agent-skills206Updated Jul 2, 2026

End-to-end binder design using BindCraft hallucination. Use this skill when: (1) Designing protein binders with built-in AF2 validation, (2) Running production-quality binder campaigns, (3) Using different design protocols (fast, default, slow), (4) Need joint backbone and sequence optimization, (5) Want high experimental success rate. For backbone-only generation, use rfdiffusion. For QC thresholds, use protein-qc. For tool selection guidance, use binder-design.

The English summary is being prepared. Showing the original description.

BioTender-max/awesome-bio-agent-skills206Updated Jul 2, 2026

See all skills by BioTender-max

Report a problem with this skill