hinna0818/ukbanalytica_v2/ukbsci-mediation
Claude Code and agent skill by hinna0818/ukbanalytica_v2
- community
Checking that the SKILL.md file is still in the repository.
Causal mediation analysis for UK Biobank Research Analysis Platform (RAP) cohorts using UKBAnalytica. Wraps regmedint (Valeri & VanderWeele 4-way decomposition: CDE, PNDE, TNIE, TNDE, PNIE, TE, PM) via run_mediation; supports multi-mediator screening (run_multi_mediator), visualization (plot_mediation, plot_mediation_forest) for linear, logistic, and Cox outcome models with continuous or binary mediators. Use this skill when the user asks for mediation analysis, indirect effects, natural direct / indirect effects, controlled direct effects, proportion mediated, or mediator screening across multiple candidates. Triggers: mediation analysis, indirect effect, natural direct effect, TNIE, PNDE, proportion mediated, 中介分析, /ukbsci-mediation. Hard rule: local agents must not read or inspect real UKB RAP participant-level data; generate scripts for RAP execution and interpret aggregate outputs only.
Install
npx vskill@latest install hinna0818/ukbanalytica_v2/ukbsci-mediationSKILL.md
ukbsci-mediation — Causal mediation on UKB cohorts
0. RAP guardrails
Strict local-agent boundary: this skill is for script generation, workflow planning, package guidance, and interpretation of aggregate outputs. The agent must not read, inspect, summarize, or process real UK Biobank RAP participant-level data, including de-identified row-level tables, raw RAP fields, exact dates, per-row predictions, row-level SHAP matrices, screenshots, tracebacks, or logs containing row-level values. Generate scripts for the user to run inside RAP; only aggregate results or rendered figures may be shared back with the agent. See ../references/agent-privacy-boundary.md.
Inputs: cohort data.table with exposure, mediator(s), outcome, covariates. Outputs: aggregate effect tables + figures that may be shared with the local agent. Bootstrap CI sampling stays in RAP memory; the resulting estimates and CIs are aggregate.
1. When to load
- The user has an exposure → mediator → outcome triple and wants to
decompose total effect into direct + indirect components.
- Screening multiple candidate mediators for the strongest indirect effect.
- Reporting CDE / PNDE / TNIE / TNDE / PNIE / TE / proportion-mediated.
2. When NOT to load
- Simple confounder adjustment (no mediator) →
ukbsci-regression. - Effect-modification / subgroup tests →
ukbsci-subgroup-sensitivity. - IPTW / treatment-effect estimation →
ukbsci-propensity.
3. Prerequisites
If regmedint is missing, run_mediation() errors out with a clear message.
4. Pipeline
Phase 1 — Specify the triple + model types
Decision matrix:
| Mediator | Outcome | mediator_type × outcome_type | |
|---|---|---|---|
| Continuous biomarker | Time-to-event | ("continuous", "cox") | |
| Binary indicator | Binary outcome | ("binary", "logistic") | |
| Continuous biomarker | Continuous outcome | ("continuous", "linear") |
Phase 2 — Single mediator: run_mediation()
Phase 3 — Multi-mediator screening
Phase 4 — Visualize
5. Key assumptions encoded
regmedint (and therefore this skill) assumes:
- No unmeasured exposure-outcome confounders given
covariates. - No unmeasured mediator-outcome confounders given exposure + covariates.
- No unmeasured exposure-mediator confounders given covariates.
- No mediator-outcome confounder affected by exposure (cross-world
assumption for natural effects).
- Correct functional form of mediator and outcome models.
Setting interaction = TRUE allows for an E × M interaction in the outcome model (recommended; the default).
6. Common pitfalls
- `regmedint` not installed. Triggers a stop with explicit message —
install before continuing.
- Survival outcomes require
outcome_type = "cox"andendpoint.
Passing only outcome is for linear / logistic.
- Binary mediator + Cox outcome. Supported but doubles model
complexity; expect convergence warnings on small subgroups.
- Bootstrap is slow.
boot = TRUE, boot_n = 1000can take many
minutes on 200k+ cohorts. Start with boot = FALSE (delta-method CIs) and only bootstrap a confirmatory run.
- No multiple-comparisons correction in `run_multi_mediator()`.
When screening ≥ 5 mediators, apply Benjamini-Hochberg externally before highlighting "significant" indirect effects.
- Sensitivity analysis is not implemented. Use a method appropriate to
the fitted mediation model and report its assumptions explicitly.
- Exponentiated estimates apply naturally to logistic / Cox outcomes
(OR / HR scale). For linear outcomes, leave exponentiate = FALSE.
7. Key functions
| Function | Returns | |
|---|---|---|
run_mediation(...) | S3 mediation_result (effects, mediator_model, outcome_model, regmedint_obj, params) | |
run_multi_mediator(...) | data.frame: per-mediator effects | |
plot_mediation(mediation_result, type = c("effects","path","decomposition")) | ggplot | |
plot_mediation_forest(multi_mediation_result, effect_type) | ggplot | |
| S3 methods | print, summary, coef, confint (on mediation_result) |
8. Related skills
| Skill | When | |
|---|---|---|
ukbsci-cohort | Build cohort first. | |
ukbsci-regression | Compare total vs. mediator-adjusted estimates. | |
ukbsci-imputation | Pool mediation effects across imputations (use pool_custom_estimates). | |
ukbsci-plot | Polished forest figure for the manuscript. |
9. References
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
- SKILL.md in the repositoryCheckinginst/skills/UKBAnalytica_skills/ukbsci-mediation/SKILL.md
Popularity
- Repository stars
- 35
- 7-day trend score
- 18
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 29 Aug 2026, 2 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
[](https://verified-skill.com/skills/hinna0818/ukbanalytica_v2/ukbsci-mediation)