
batch-cohort
Use when one validated cohort analysis must be repeated across many exposure/outcome pairs. Generates one R/Python script per combination from a single methodology template, changing only the variables, and aggregates the results into a summary matrix.
- Installs
- 116
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/aperivue/medsci-skills --skill batch-cohort- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads batch-cohort automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Batch Cohort Analysis Skill
Generate one analysis script per exposure/outcome combination from a single validated methodology template; only the variables change between scripts.
Inputs
- Database path(s): CSV/SAS data files (KNHANES, NHANES, NHIS, or any cleaned cohort)
- Methodology template: One of:
- Path to a validated R/Python analysis script (from /replicate-study or /cross-national)
- A paper type template name:
nhis_cohort,cross_national,survey_weighted - A source paper to extract methodology from (falls back to /replicate-study Phase 1)
- Combination spec: A list of exposure/outcome pairs, provided as:
- Inline list:
exposures: [depression, obesity, smoking]; outcomes: [diabetes, hypertension, CVD] - CSV file with columns:
exposure,outcome, (optional)subgroup_vars "all"keyword: generates all pairwise combinations from the lists
- Inline list:
Optional Inputs
- Covariate set: Fixed covariate list for all analyses (default: use template's set)
- Subgroup variables: Variables to stratify by (default: sex, age group)
- Output format:
code_only(just scripts) |execute(run + collect results) |full(code + results + summary) - Cross-national mode:
cross_national: truegenerates paired scripts for both countries per combination (see Cross-National Batch Mode)
Example:
/batch-cohort
DB Korea: /path/to/knhanes/HN18.csv
DB US: /path/to/nhanes/
Template: cross_national
Exposures: [depression, obesity, smoking]
Outcomes: [diabetes, hypertension, metabolic_syndrome]
cross_national: true
Mode: execute
Workflow
Phase 1: Template Validation
- Read the methodology template (R script or paper type reference).
- Identify the slot variables — parts that change per combination:
EXPOSURE_VAR(raw variable name in the database),EXPOSURE_LABEL(label for tables/figures),EXPOSURE_CODING(derivation of the binary/categorical exposure), andOUTCOME_VAR,OUTCOME_LABEL,OUTCOME_CODINGlikewise. - Confirm the survey design: weighted analysis is mandatory for KNHANES/NHANES and is inherited from the template; NHIS and other claims databases have no sampling weights (standard regression).
- Verify the template runs successfully on at least one combination before batch generation.
- Output: template summary with identified slots → user approval.
Phase 2: Variable Specification
For each exposure and outcome in the combination spec:
- Look up the variable in the database: KNHANES — the name exists in the CSV header; NHANES —
which table contains it (codebook.csv if available); NHIS — claims code or variable name.
For ICD-10 claims algorithms read
${CLAUDE_SKILL_DIR}/../analyze-stats/references/analysis_guides/nhis_icd10_mapping.md; for survey variable coding,survey_weighted.mdin the same folder. If a mapping is uncertain, write[VERIFY: variable_name]and ask the user to confirm it against the data dictionary; never guess a variable name, column name or coding. - Define coding: binary as a threshold or category mapping (e.g.,
HE_glu >= 126 → diabetes = 1); categorical as level definitions (e.g.,smoking: current/former/never). Outcome definitions MUST include physician diagnosis, because lab-only definitions systematically overestimate exposure→outcome associations: Diabetes = FPG≥126 OR HbA1c≥6.5 OR physician-diagnosed (KNHANES: DE1_dg=1, NHANES: DIQ010="Yes"); Hypertension = SBP≥140 OR DBP≥90 OR physician-diagnosed (KNHANES: DI1_dg=1, NHANES: BPQ020="Yes"). - Set covariates: the full 8-covariate set (age, sex, education, income, smoking, alcohol, obesity, CVD) is the default unless explicitly justified — minimal models (age+sex+BMI only) leave residual confounding, which can bias effects in either direction. Remove self-adjustment: if the exposure is (or derives from) a covariate, drop that covariate (exposure = BMI → drop obesity; exposure = education/income → drop the same variable); if outcome = MetS, consider dropping obesity. Document every removal in the matrix Notes.
- Output: combination matrix (
combination_matrix.csv) with all variable specifications.
| # | Exposure | Exposure Coding | Outcome | Outcome Coding | Covariates (adjusted) | Notes |
|---|----------|-----------------|---------|----------------|----------------------|-------|
| 1 | Depression (PHQ≥10) | BP_PHQ sum ≥10 | Diabetes | HE_glu≥126|HbA1c≥6.5|DE1_dg=1 | age,sex,edu,income,smoking,alcohol,obesity,CVD | — |
| 2 | Obesity (BMI≥25) | HE_obe ≥4 | Diabetes | same | age,sex,edu,income,smoking,alcohol,depression,CVD | obesity removed from covariates |
Phase 3: Batch Code Generation
Never modify the core methodology across combinations — only swap exposure/outcome/covariates. For each combination in the matrix:
- Clone the template script.
- Replace slot variables with the combination-specific values.
- Apply the combination's adjusted covariate set from the matrix.
- Set output paths: each combination gets its own results subdirectory.
- Generate a master runner script (
run_all.Rorrun_all.sh) that executes all N scripts sequentially (or in parallel viafuture/parallel), captures errors per script without stopping the batch, and logs execution time per analysis. - Generated-code quality gate: one reproducibility slip (a missing seed, an absolute path, a
hand-typed data literal) replicates across the whole batch, so lint the generated scripts with
the
/analyze-statscode-quality gate (python3 ${CLAUDE_SKILL_DIR}/../analyze-stats/scripts/check_generated_code.py --code-dir {batch_dir} --strict) and clear every Major (MISSING_SEED,HARDCODED_DATA_LITERAL,HARDCODED_ABS_PATH,INPLACE_SOURCE_OVERWRITE) before batch execution.
Phase 4: Batch Execution (if execute or full mode)
- Event count check: before running, verify ≥10 outcome events per model parameter (count the exposure and every dummy/spline term; use min(events, non-events)), in the full sample and in each subgroup that is modelled. Flag underpowered combinations.
- Run the master script.
- Collect results from each combination's output directory.
- Log which combinations failed and why (common: convergence issues, too few events, empty
subgroups) in
failed_runs.csv, and suggest fixes.
Phase 5: Summary Matrix
Aggregate all results into a single summary. Every number comes from a combination's executed results files; never fill a cell by hand.
Main Results Matrix (summary_matrix.csv):
| Exposure | Outcome | N | Events | Model 1 OR (95% CI) | Model 2 OR (95% CI) | Model 3 OR (95% CI) | p-value | Significant |
|---|
Subgroup Summary (subgroup_matrix.csv): Same format, stratified by subgroup variables.
Heatmap (optional): Visual matrix of effect sizes × significance, exposure on Y-axis, outcome on X-axis.
- Multiple comparisons: whenever more than one combination is tested, include a Bonferroni- (or Holm-) corrected significance column in the summary matrix, with m = the number of tests in the reported family (combinations × models × subgroups), state m, and add a note on exploratory vs confirmatory framing.
- No p-hacking framing: the summary matrix is for hypothesis generation, not confirmation.
State this explicitly in README and any manuscript output. Any citation there needs a
/search-lit-confirmed DOI/PMID; otherwise mark it[UNVERIFIED - NEEDS MANUAL CHECK].
Output Files
{working_dir}/batch_{timestamp}/
├── README.md — Batch run summary (N combinations, template used, date)
├── combination_matrix.csv — All exposure/outcome specs with coding
├── template/
│ └── base_template.R — The validated template (frozen copy)
├── scripts/
│ ├── 01_depression_diabetes.R
│ ├── 02_obesity_diabetes.R
│ ├── ...
│ └── run_all.R — Master execution script
├── results/
│ ├── 01_depression_diabetes/
│ │ ├── table1.csv
│ │ ├── main_results.csv
│ │ └── subgroup_results.csv
│ └── ...
├── summary/
│ ├── summary_matrix.csv — Main results across all combinations
│ ├── subgroup_matrix.csv — Subgroup results across all combinations
│ ├── failed_runs.csv — Combinations that failed + error messages
│ └── heatmap.png — Optional effect size × significance visual
└── logs/
└── batch_execution.log — Timing + error log
Reproducibility: freeze the template version (template/) and include a SHA256 hash of the
data file in README.
Cross-National Batch Mode
When cross_national: true:
- Generate paired scripts for each combination (Korea + US), using /cross-national's dual-survey-design approach
- Summary matrix includes both countries side-by-side, with a ratio-of-ORs column (95% CI; P) computed
as in
/cross-nationalPhase 4, not a direction-agreement tick
FAQ
What does the batch-cohort skill do?
Use when one validated cohort analysis must be repeated across many exposure/outcome pairs. Generates one R/Python script per combination from a single methodology template, changing only the variables, and aggregates the results into a summary matrix.
How do I install batch-cohort?
Run npx skills add https://github.com/aperivue/medsci-skills --skill batch-cohort in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/batch-cohort/ (personal) or .claude/skills/batch-cohort/ (project).
Which AI agents can use batch-cohort?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is batch-cohort safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains batch-cohort?
It is published by aperivue in aperivue/medsci-skills. It has 116 recorded installs.
More from aperivue/medsci-skills
check-reporting
aperivue/medsci-skills
Use when auditing a manuscript item by item against a reporting guideline or risk-of-bias tool. Covers 49 reporting guidelines and risk-of-bias tools (STROBE, CONSORT, STARD, TRIPOD+AI, PRISMA, QUADAS and more), marking each item PRESENT, PARTIAL or MISSING. Not a reviewer critique (/self-review).
meta-analysis
aperivue/medsci-skills
Use when running a systematic review and meta-analysis, DTA or intervention. Covers PROSPERO protocol, search, screening, extraction, risk of bias (QUADAS-3, RoB 2, ROBINS-I), bivariate/HSROC or random-effects pooling, forest plots, heterogeneity and PRISMA reporting. Topic scouting is /ma-scout.
make-figures
aperivue/medsci-skills
Use when a paper needs publication-ready figures or a visual abstract. Makes ROC, forest, calibration, Kaplan-Meier and Bland-Altman plots, CONSORT/STARD/PRISMA flow diagrams, confusion matrices, pipeline diagrams and journal visual abstracts, checking the journal's AI-image policy first.
analyze-stats
aperivue/medsci-skills
Use when data needs statistical analysis. Runs reproducible Python/R code for Table 1, diagnostic accuracy, agreement, regression, survival, propensity score, survey-weighted and repeated-measures models, with publication tables. Sample size is /calc-sample-size; pooling studies is /meta-analysis.
verify-refs
aperivue/medsci-skills
Use when checking whether a manuscript's references are real. Audits each citation against PubMed and CrossRef, flags fabricated or mismatched entries and writes qc/referenceaudit.json. Audit-only; never edits references or refs.bib. Citation-key checks are /manage-refs.
search-lit
aperivue/medsci-skills
Use when finding papers or building a reference list. Searches PubMed, Semantic Scholar and bioRxiv/medRxiv, includes only references verified through an API, and generates BibTeX. Auditing an existing reference list is /verify-refs.
Popular other skills
hyperframes-cli
heygen-com/hyperframes
The HyperFrames CLI by job - scaffold, check, look at frames, edit the timeline, preview, render locally or in the cloud, publish, project history - plus reading its JSON and recovering from build or render failures.
triage
mattpocock/skills
Move issues and external PRs through a state machine of triage roles, categorise, verify, grill if needed, and write agent-ready briefs.
ask-matt
mattpocock/skills
Ask which skill or flow fits your situation. A router over the skills in this repo.
to-questionnaire
mattpocock/skills
Turn a decision you can't fully answer into a questionnaire for someone else to fill in.
loop-me
mattpocock/skills
Grill me about specs for the workflows I want to build, within this workspace.