---
id: gh-meta-analysis-skill
name: "meta-analysis-skill"
url: https://skills.yangsir.net/skill/gh-meta-analysis-skill
author: Lokenqaq111
domain: healthcare
tags: ["meta-analysis", "r", "healthcare", "evidence-synthesis", "network-meta-analysis"]
install_count: 8
rating: 4.00 (20 reviews)
github: https://github.com/Lokenqaq111/meta-analysis-skill
---

# meta-analysis-skill

> 在 R 中运行成对与网络荟萃分析，支持连续、二分类、患病率、通用效应量和 NMA 数据。适合康复与运动科学研究者将已提取的数值 CSV 用于验证、合成、绘图、诊断，并生成可复现 Markdown 报告；不负责文献检索、PDF 数值提取或自动 GRADE/CINeMA 评分。

**Stats**: 8 installs · 4.0/5 (20 reviews)

## Before / After 对比

### 从手写 R 脚本到可复现荟萃分析流程

**Before**:

研究者需要手动编写 R 脚本：整理 CSV、选择模型、运行 meta/network meta 包、绘制森林图与漏斗图、检查诊断并拼装报告，重复劳动多且容易遗漏验证步骤。

**After**:

调用仓库内经过测试的脚本自动完成数据校验、连续/二分类/患病率/网络荟萃分析、图表诊断和 Markdown 报告，保留日志与 rerun.sh，流程可复现。

| Metric | Before | After | Change |
|---|---|---|---|
| 完成一次标准分析耗时 | 30分钟 | 5分钟 | -83% |

## Readme

---
name: meta-analysis-r
description: Run tested R scripts for pairwise continuous, binary, generic, prevalence, or network meta-analysis after numeric data have already been extracted into CSV. Use for validation, synthesis, plots, diagnostics, and a reproducible Markdown report. Do not use for literature-only searches, protocol writing, extracting numbers from PDFs/abstracts, or automatic GRADE/CINeMA/PRISMA scoring.
metadata:
  short-description: Tested R engines for pairwise, prevalence, and network meta-analysis.
---

# R Meta-analysis V2

Use repository scripts as the analysis engine. Do not rewrite a complete `analysis.R` from a prompt.

## Hard rules

1. Never invent numeric data. An empty required cell stops validation.
2. Do not extract or estimate means, SDs, events, or sample sizes from a PDF or abstract. If the user explicitly requests a documented Cochrane 6.5.2 conversion from reported SE/CI/IQR data, record the source values, formula, and caveat in notes before analysis.
3. Never install R packages silently. Report missing packages and the exact install command, then wait for authorization.
4. Validate before analysis. Do not bypass a failed validator.
5. Refuse meta-analysis with one independent study; suggest narrative synthesis.
6. Preserve `analysis.log`, input data, parameters, `rerun.sh`, plots, summaries, notes, and `report.md` under the selected output directory.
7. Do not apply a universal MCID. Use only a population-appropriate source supplied by the user.
8. RoB, GRADE, and JBI content is a manual placeholder. Do not calculate an automatic certainty score.

## Environment gate

Run from the skill repository root:

```bash
scripts/check_env.sh
```

Read `ENV_REPORT.md`. If R or required packages are unavailable, implement/validate what is possible, mark package-dependent work `BLOCKED`, and do not claim that the analysis pipeline was runtime-verified.

## Select a mode

| Mode | Measure | Template | Use |
|---|---|---|---|
| `continuous` | `SMD` or `MD` | `templates/continuous_empty.csv` | Two-arm aggregate continuous outcomes |
| `binary` | `RR` or `OR` | `templates/binary_empty.csv` | Comparative event counts with intervention/control arms |
| `generic` | Declared effect measure | `templates/generic_empty.csv` | Pre-calculated `TE` and `seTE` |
| `prevalence` | `PLOGIT` | `templates/prevalence_empty.csv` | Single-group prevalence (`events` / `total`) |
| `network` | `RR`, `OR`, `SMD`, or `MD` | `templates/network_empty.csv` | Connected multi-treatment arm-level network |

Prevalence is an independent mode. Never put single-group prevalence data into the comparative binary template.

## Read references only when needed

- Before preparing or validating any CSV, read [references/data-dictionary.md](references/data-dictionary.md).
- For model, direction, HK, prediction-interval, and diagnostic defaults, read [references/methods-defaults.md](references/methods-defaults.md).
- For prevalence, read [references/prevalence.md](references/prevalence.md) and [references/jbi-prevalence-rob.md](references/jbi-prevalence-rob.md).
- For NMA, read [references/nma-limits.md](references/nma-limits.md); connectivity does not establish transitivity.
- When a funnel plot or asymmetry test is relevant, read [references/egger-and-bias.md](references/egger-and-bias.md).
- Before interpreting `report.md`, read [references/report-spec.md](references/report-spec.md).

## Validate

The main runner validates automatically. A validation-only call is also available:

```bash
Rscript scripts/validate.R \
  --input path/to/input.csv \
  --mode continuous \
  --measure SMD
```

When a study contributes multiple outcomes, timepoints, or pairwise rows, select one using `--outcome` / `--timepoint` or stop and ask for a prespecified dependency decision. Pairwise shared controls stop by default.

## Run

```bash
Rscript scripts/run_analysis.R \
  --input path/to/input.csv \
  --mode continuous \
  --measure SMD \
  --outdir output/topic \
  --topic topic
```

Optional arguments include:

- `--model random|common`
- `--target-higher-is-better true|false`
- `--outcome <name>` and `--timepoint <name>`
- `--population <description>` and `--mcid-source <citation>`
- NMA: `--reference <treatment>` and `--ranking P-score|SUCRA`

Default output is `./output/<topic>/`. Use a Desktop path only when the user explicitly asks for it.

## Check outputs

Confirm that the output directory contains:

- `run_parameters.txt` and executable `rerun.sh`;
- `analysis.log`;
- `data/input.csv`, `data/validation.txt`, `data/summary.txt`, `data/notes.txt` when notes exist, and `data/sessionInfo.txt`;
- gated files under `plots/` and `data/`;
- `report.md` in the required section order.

Surface analysis failures verbatim. Do not edit outputs to conceal skipped or failed diagnostics.

## Test the skill

```bash
tests/run_all.sh
```

A nonzero exit means V2 is not complete. `BLOCKED` is acceptable only when `ENV_REPORT.md` identifies environment branch B/C; every non-blocked test must pass.

--- README.md ---

# meta-analysis-r V2

A Claude Code / Cursor skill backed by parameterized R scripts for aggregate-data meta-analysis. V2 validates an already extracted CSV, runs a repository-owned engine, saves reproducible parameters and logs, and writes plots plus a structured Markdown report.

Supported modes:

- pairwise continuous: MD or Hedges' g SMD;
- pairwise binary: RR or OR;
- generic pre-calculated effects;
- independent single-proportion prevalence mode;
- technical frequentist network meta-analysis.

This project does not search literature, extract numeric data from PDFs, generate PRISMA flow diagrams, or automatically score GRADE, CINeMA, JBI, or risk of bias.

## Requirements

- R 4.0 or later;
- R packages `meta`, `metafor`, and `netmeta`;
- Claude Code or Cursor when used as an agent skill.

Check the actual runtime before analysis:

```bash
scripts/check_env.sh
```

If packages are missing, review `ENV_REPORT.md` and obtain approval before running:

```r
install.packages(c("meta", "metafor", "netmeta"))
```

The skill never installs packages silently.

## Install

### Claude Code

```bash
git clone https://github.com/Lokenqaq111/meta-analysis-skill.git \
  ~/.claude/skills/meta-analysis-r
```

### Cursor — user scope

```bash
git clone https://github.com/Lokenqaq111/meta-analysis-skill.git \
  ~/.cursor/skills/meta-analysis-r
```

### Cursor — project scope

From the project root:

```bash
git clone https://github.com/Lokenqaq111/meta-analysis-skill.git \
  .cursor/skills/meta-analysis-r
```

## Quick start

Copy an empty template and fill every required field:

```bash
cp templates/continuous_empty.csv my_input.csv
```

Validate without running a model:

```bash
Rscript scripts/validate.R \
  --input my_input.csv \
  --mode continuous \
  --measure SMD
```

Run the analysis:

```bash
Rscript scripts/run_analysis.R \
  --input my_input.csv \
  --mode continuous \
  --measure SMD \
  --outdir output/my-topic \
  --topic my-topic
```

The default output path is `./output/<topic>/`; `--outdir` is configurable.

## Input modes

| Mode | Template | Notes |
|---|---|---|
| `continuous` | `templates/continuous_empty.csv` | Direction is explicit; MD requires comparable units |
| `binary` | `templates/binary_empty.csv` | Comparative intervention/control events |
| `generic` | `templates/generic_empty.csv` | Pre-calculated `TE` / `seTE` |
| `prevalence` | `templates/prevalence_empty.csv` | Single-group `events` / `total`; no control columns |
| `network` | `templates/network_empty.csv` | Binary or continuous arm-level data |

Files ending in `_template.csv` contain synthetic `Example*` rows. Empty templates contain headers only.

## Reproducible output

Each successful run writes:

```text
output/<topic>/
├── analysis.log
├── report.md
├── rerun.sh
├── run_parameters.txt
├── data/
│   ├── input.csv
│   ├── validation.txt
│   ├── analysis_data.csv
│   ├── summary.txt
│   ├── notes.txt              # when warnings/skips exist
│   └── sessionInfo.txt
└── plots/
    └── ...                    # mode- and k-gated figures
```

## Defaults and limits

- Random effects with REML is the intervention default because the usual target is an average effect; it is configurable and is not a discipline-wide law.
- The current non-deprecated Hartung-Knapp API is checked at runtime.
- Diagnostics use unique study count, not CSV row count.
- Small-study tests require at least ten studies and additional effect/precision checks.
- No universal MCID is embedded. Clinical thresholds require a user-supplied, population-appropriate source.
- NMA connectivity does not establish transitivity; V2 does not claim publication-grade NMA validity.

See `references/` for the data dictionary, method rules, prevalence behavior, NMA limits, bias-test routing, report contract, and manual JBI checklist.

## Tests

```bash
tests/run_all.sh
```

With R and all packages available, the R suite runs end-to-end examples. Without R, branch-C Python/shell checks run and package-dependent tests are reported as `BLOCKED` in `TEST_LOG.md`; they are never presented as passed.

## License

MIT — see [LICENSE](LICENSE).

---

# 中文说明

`meta-analysis-r V2` 是一个面向 Claude Code / Cursor 的 Meta 分析 Skill。与 V1 每次让模型重写整份 `analysis.R` 不同，V2 直接调用仓库内参数化 R 脚本：先校验 CSV，再运行分析，并保存日志、参数、复跑脚本、图和结构化报告。

支持连续型、二分类、预计算效应量、独立患病率和技术性网络 Meta 模式。患病率使用单组 `events/total` 模板，不能与治疗组/对照组的 binary 模板混用。

硬规则：不编造或从摘要猜数值；必填空格立即停止；不静默安装 R 包；一项独立研究拒绝做 Meta；风险偏倚、GRADE 和 JBI 只留人工填写栏，不自动打分。

安装路径：

```bash
# Claude Code
git clone https://github.com/Lokenqaq111/meta-analysis-skill.git ~/.claude/skills/meta-analysis-r

# Cursor 用户级
git clone https://github.com/Lokenqaq111/meta-analysis-skill.git ~/.cursor/skills/meta-analysis-r

# Cursor 项目级
git clone https://github.com/Lokenqaq111/meta-analysis-skill.git .cursor/skills/meta-analysis-r
```

正式运行前先执行 `scripts/check_env.sh`，再用 `tests/run_all.sh` 查看当前环境实际通过、失败或受阻的测试。没有 R 时必须保留 `V2_VERIFIED=NO`，不能宣称分析管线已经实测通过。

---
*Source: https://skills.yangsir.net/skill/gh-meta-analysis-skill*
*Markdown mirror: https://skills.yangsir.net/api/skill/gh-meta-analysis-skill/markdown*