Env trend and driver attribution

From XuShuwenn/RedAct · View interactive version

Env trend and driver attribution is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Detect long-term trends in an environmental time series and attribute dominant drivers by grouping predictors into categories and decomposing explained variance.

How to use this skill

Skill file

Environmental Trend and Driver Attribution

This skill provides a reproducible workflow to (1) test for a long-term trend in an environmental time series and (2) identify the dominant driver category among grouped predictors (e.g., Heat, Flow, Wind, Human) using factor scores and R² decomposition.

Use this when you need to:

Core Workflow

Phase 1 — Trend Analysis (robust and reproducible)

  1. Load the response time series (e.g., WaterTemperature) and time key (e.g., Year).
  2. Sort by time; drop rows with missing response values.
  3. Prefer a non-parametric Mann–Kendall test with Sen’s slope (robust to outliers and non-normality). If the package is unavailable, fall back to linear regression (report that it is parametric if asked).
  4. Write trend_result.csv with exactly two columns: slope and p-value.

Phase 2 — Driver Attribution by Category

  1. Load and merge predictor tables on the time key (e.g., Year). Keep only rows with complete values for selected predictors and the response.
  2. Define a variable-to-category map (e.g., Heat, Flow, Wind, Human). Only use variables present in the merged data.
  3. Standardize predictors (zero mean, unit variance).
  4. Extract latent factors:
  1. Compute factor scores for each observation.
  2. Fit a linear model: response ~ factor scores. Record full R².
  3. For each factor i, compute R² without factor i. Factor contribution = max(0, full R² − R²_without_i).
  4. Map each factor to a category by summing absolute loadings of variables within each category for that factor; assign the category with the highest sum.
  5. Aggregate factor contributions per category and choose the dominant category (highest aggregated contribution).
  6. Convert the dominant category’s contribution to a percentage (contribution × 100), round to two decimals, and write dominant_factor.csv with two columns: variable (the category name) and contribution (percentage).

Verification

Before finalizing results, perform these checks:

Common Pitfalls (and how to avoid them)

Success Criteria

Optional Script Usage

This repository includes a helper script that implements the workflow with sensible fallbacks.

Example usage:

Run:

--water /root/data/water_temperature.csv \

--climate /root/data/climate.csv \

--land /root/data/land_cover.csv \

--hydro /root/data/hydrology.csv \

--time-col Year \

--response WaterTemperature \

--output-dir /root/output

To provide a custom category map, pass a JSON file mapping variable names to categories:

The script writes:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.