batch-cohort
Generate N analysis scripts from a single methodology template × multiple exposure/outcome combinations. The "80-person team" pattern — same validated method, swap variables only. Produces batch R/Python code + summary matrix.
Install
npx skills add https://github.com/Aperivue/medsci-skills/tree/main/skills/batch-cohort
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install aperivue-medsci-skills@llmmart
git clone https://github.com/Aperivue/medsci-skills.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole aperivue/medsci-skills collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Batch Cohort Analysis Skill
You are assisting a medical researcher in generating multiple analysis scripts from a single validated methodology template, each differing only in the exposure/outcome variable combination. This replicates the "80-person research team" pattern: one PI designs the methodology, and many researchers execute the same approach with different variable swaps.
When to Use
- Researcher has a validated analysis template (e.g., from /replicate-study or /cross-national)
- Wants to explore multiple exposure → outcome combinations on the same database
- Goal: systematic variable-swap code generation + batch execution + result matrix
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: If TRUE, generates paired scripts for both countries per combination
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 databaseEXPOSURE_LABEL: human-readable label for tables/figuresEXPOSURE_CODING: how to derive binary/categorical exposureOUTCOME_VAR: raw variable nameOUTCOME_LABEL: human-readable labelOUTCOME_CODING: how to derive binary outcome
- 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: check variable name exists in the CSV header
- NHANES: check which table contains the variable (use codebook.csv if available)
- NHIS: check claims code or variable name
- Define coding:
- Binary: threshold or category mapping (e.g.,
HE_glu >= 126 → diabetes = 1) - Categorical: level definitions (e.g.,
smoking: current/former/never)
- Binary: threshold or category mapping (e.g.,
- Check covariate overlap: If the exposure IS one of the standard covariates, remove it from the adjustment set for that analysis (no self-adjustment).
- Output: combination matrix 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
For each combination in the matrix:
- Clone the template script.
- Replace slot variables with the combination-specific values.
- Adjust covariates: Remove exposure variable from covariate list if present.
- 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 via
future/parallel) - Captures errors per script without stopping the batch
- Logs execution time per analysis
- Executes all N scripts sequentially (or in parallel via
Phase 4: Batch Execution (if execute or full mode)
- Run the master script.
- Collect results from each combination's output directory.
- Handle failures gracefully:
- Log which combinations failed and why
- Common failures: convergence issues, too few events, empty subgroups
- Suggest fixes for failed combinations
Phase 5: Summary Matrix
Aggregate all results into a single summary:
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 |
|---|---|---|---|---|---|---|---|---|
| Depression | Diabetes | 5,811 | 487 | 2.14 (1.52–3.01) | 1.89 (1.33–2.69) | 1.36 (0.91–2.05) | 0.137 | No |
| Obesity | Diabetes | 5,811 | 487 | 3.45 (2.71–4.39) | 3.38 (2.65–4.32) | 3.12 (2.42–4.02) | <0.001 | Yes |
| ... |
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.
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
│ ├── 02_obesity_diabetes/
│ │ └── ...
│ └── ...
├── 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
Critical Rules
- Never modify the core methodology across combinations — only swap exposure/outcome/covariates.
- Remove self-adjustment: If exposure = BMI, remove obesity from covariates. If exposure = education/income, remove the same variable from covariates. If outcome = MetS, consider removing obesity from covariates. Document all removals.
- Weighted analysis mandatory for KNHANES/NHANES/NHIS — inherited from template.
- Event count check: Before running, verify each outcome has ≥10 events per covariate (EPV rule). Flag underpowered combinations.
- Multiple comparisons: When generating >5 combinations, include a Bonferroni-corrected significance column in the summary matrix. Add a note about exploratory vs confirmatory framing.
- Reproducibility: Freeze the template version. Include a SHA256 hash of the data file in README.
- No p-hacking framing: The summary matrix is for hypothesis generation, not confirmation. State this explicitly in README and any manuscript output.
- Outcome definitions MUST include physician diagnosis: 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"). Lab-only definitions systematically overestimate exposure→outcome associations (validated: Joo 2026 replication showed US depression→DM wOR 1.92 without vs 1.54 with physician dx).
- Full covariate set is default: Always use 8 covariates (age, sex, education, income, smoking, alcohol, obesity, CVD) unless explicitly justified. Minimal models (age+sex+BMI only) overestimate effects due to residual confounding.
- Generated-code quality gate: Because this skill emits N near-identical scripts, a single reproducibility slip (a missing seed, an absolute path, a hand-typed data literal) replicates across the whole batch. After Phase 3, lint the generated scripts with the
/analyze-statscode-quality gate (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.
Cross-National Batch Mode
When cross_national: true:
- Generate paired scripts for each combination (Korea + US)
- Summary matrix includes both countries side-by-side
- Direction agreement column: ✓ if both countries show same direction of effect
- Uses /cross-national skill's dual-survey-design approach
Integration with Upstream Skills
| Need | Skill |
|---|---|
| Variable coding lookup | analyze-stats survey_weighted guide |
| Template creation from paper | /replicate-study Phase 1–3 |
| Cross-national paired analysis | /cross-national |
| ICD-10 claims algorithms | analyze-stats nhis_icd10_mapping guide |
| Write manuscript from results | /write-paper (nhis_cohort or cross_national type) |
| Figure generation | /make-figures (forest plot of all combinations) |
Example Invocations
Basic: Single DB, Multiple Exposures × Single Outcome
/batch-cohort
DB: /path/to/knhanes/HN18.csv
Template: /path/to/validated_analysis.R
Exposures: [depression, obesity, smoking, heavy_drinking, low_income, low_education]
Outcome: diabetes
Mode: full
Cross-National: Full Matrix
/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
NHIS Cohort: Claims-Based Batch
/batch-cohort
DB: /path/to/nhis_sample_cohort.csv
Template: nhis_cohort
Exposures: [atrial_fibrillation, heart_failure, COPD, CKD]
Outcomes: [all_cause_mortality, cardiovascular_death, stroke]
Mode: code_only
Anti-Hallucination
- Never fabricate variable names, dataset column names, or variable codings. If a variable mapping is uncertain, output
[VERIFY: variable_name]and ask the user to confirm against the data dictionary. - Never fabricate statistical results — no invented p-values, effect sizes, confidence intervals, or sample sizes. All numbers must come from executed code output.
- Never generate references from memory. Use
/search-litfor all citations. - If a function, package, or API does not exist or you are unsure, say so explicitly rather than guessing.
Files (medsci-skills)
-
references
-
base_template_knhanes.R 7.7 KB · in bundle
-
batch_template_generator.R 8.5 KB · in bundle
-
variable_coding_registry.md 5.8 KB
# Variable Coding Registry Pre-validated variable definitions for batch code generation. Each entry provides raw variable names, coding logic, and human-readable labels for KNHANES and NHANES. Add new variables as they are validated in replication studies. ## Exposures ### Depression (PHQ-9 ≥ 10) | Field | KNHANES | NHANES | |-------|---------|--------| | Raw vars | BP_PHQ_1 ~ BP_PHQ_9 | DPQ010 ~ DPQ090 | | Coding | sum(BP_PHQ_1:9), NA if any missing | recode text→0-3, sum, NA if any missing | | Binary | phq_score ≥ 10 → 1 | phq_score ≥ 10 → 1 | | Label | Depression (PHQ-9 ≥ 10) | Depression (PHQ-9 ≥ 10) | | Notes | Items are numeric 0-3 | Items are TEXT: "Not at all"→0, "Several days"→1, "More than half the days"→2, "Nearly every day"→3 | ### Obesity | Field | KNHANES | NHANES | |-------|---------|--------| | Raw vars | HE_obe (or BMXBMI) | BMXBMI (BMX_J) | | Coding | HE_obe ≥ 4 (Asian cutoff: BMI ≥ 25) | BMXBMI ≥ 30 (WHO cutoff) | | Binary | obesity = 1 if HE_obe ≥ 4 | obesity = 1 if BMXBMI ≥ 30 | | Label | Obesity (BMI ≥ 25, Asian) | Obesity (BMI ≥ 30, WHO) | | Notes | 6-level: 1=underweight to 6=morbid obesity | Continuous BMI; use 25 for Asian-Americans analysis | ### Current Smoking | Field | KNHANES | NHANES | |-------|---------|--------| | Raw vars | BS3_1 | SMQ020, SMQ040 | | Coding | BS3_1 %in% c(1,2) → current; 3 → former; 8 → never | SMQ020=="Yes" & SMQ040 %in% c("Every day","Some days") → current | | Binary | smoking_current = 1 if BS3_1 in (1,2) | smoking_current = 1 if above | | Label | Current smoking | Current smoking | | Notes | 1=daily, 2=occasional, 3=former, 8=never | Two-step: ≥100 lifetime cigs + currently smoke | ### Heavy/Frequent Drinking | Field | KNHANES | NHANES | |-------|---------|--------| | Raw vars | BD1_11 | ALQ111, ALQ121 | | Coding | BD1_11 in 2:6 → frequent; 1 → occasional; 8 → never | ALQ111=="No" → never; ALQ121 frequency mapping | | Binary | drinking_freq = 1 if BD1_11 in 2:6 | drinking_freq = 1 if ALQ121 indicates monthly+ | | Label | Frequent alcohol use | Frequent alcohol use | | Notes | 1=past-year abstainer, 2-6=frequency levels, 8=lifetime never | ALQ121 text labels; never=ALQ111=="No" (ALQ121 is NA) | ### Low Education | Field | KNHANES | NHANES | |-------|---------|--------| | Raw vars | edu | DMDEDUC2 | | Coding | edu in 1:3 → non-college; 4 → college+ | "Less than 9th grade"/"9-11th grade"/"High school" → non-college | | Binary | low_edu = 1 if edu in 1:3 | low_edu = 1 if non-college | | Label | Non-college education | Non-college education | ### Low Income | Field | KNHANES | NHANES | |-------|---------|--------| | Raw vars | incm | INDFMPIR (INQ_J) | | Coding | incm in 1:3 → bottom 80% | INDFMPIR < 1.3 → low income | | Binary | low_income = 1 if incm in 1:3 | low_income = 1 if PIR < 1.3 | | Label | Lower income (bottom 80%) | Low income (PIR < 1.3) | | Notes | 4-level quartile | Poverty income ratio; threshold varies by study | ## Outcomes ### Diabetes | Field | KNHANES | NHANES | |-------|---------|--------| | Raw vars | HE_glu, HE_HbA1c, DE1_dg | LBXSGL (BIOPRO_J), LBXGH (GHB_J), DIQ010 | | Coding | HE_glu≥126 \| HE_HbA1c≥6.5 \| DE1_dg==1 | LBXSGL≥126 \| LBXGH≥6.5 \| DIQ010=="Yes" | | Label | Diabetes mellitus | Diabetes mellitus | | Notes | FPG=fasting plasma glucose | LBXSGL not LBXSGLU; DIQ010 is text | ### Hypertension | Field | KNHANES | NHANES | |-------|---------|--------| | Raw vars | HE_sbp, HE_dbp, DI1_dg | BPXOSY1-4, BPXODI1-4, BPQ020 | | Coding | mean(SBP)≥140 \| mean(DBP)≥90 \| DI1_dg==1 | mean(SBP readings)≥140 \| mean(DBP)≥90 \| BPQ020=="Yes" | | Label | Hypertension | Hypertension | | Notes | HE_sbp/dbp are already averaged | Average of up to 4 readings; BPQ020 is text | ### CVD History | Field | KNHANES | NHANES | |-------|---------|--------| | Raw vars | DI4_dg, DI5_dg, DI6_dg | MCQ160B, MCQ160C, MCQ160D | | Coding | any == 1 → CVD | any == "Yes" → CVD | | Label | Cardiovascular disease history | Cardiovascular disease history | | Notes | 4=MI, 5=angina, 6=stroke | B=CHF, C=CHD, D=angina | ### Metabolic Syndrome | Field | KNHANES | NHANES | |-------|---------|--------| | Raw vars | HE_wc, HE_sbp, HE_dbp, HE_TG, HE_HDL_st2, HE_glu | BMXWAIST, BPXOSY, BPXODI, LBXSTR, LBDHDD, LBXSGL | | Coding | NCEP ATP III: ≥3 of 5 criteria | NCEP ATP III: ≥3 of 5 criteria | | Label | Metabolic syndrome (NCEP ATP III) | Metabolic syndrome (NCEP ATP III) | | Notes | Waist: M≥90, F≥85 (Korean) | Waist: M≥102, F≥88 (US/WHO) | ## Standard Covariate Set Default covariates for fully adjusted model (remove exposure if overlap): | Covariate | KNHANES var | NHANES var | Type | |-----------|-------------|------------|------| | Age | age | RIDAGEYR | Continuous | | Sex | sex | RIAGENDR | Binary | | Education | edu | DMDEDUC2 | Binary (college vs non) | | Income | incm | INDFMPIR | Binary (threshold varies) | | Smoking | BS3_1 | SMQ020+SMQ040 | 3-level (current/former/never) | | Alcohol | BD1_11 | ALQ111+ALQ121 | 3-level (frequent/occasional/never) | | Obesity | HE_obe | BMXBMI | Binary (country-specific cutoff) | | CVD | DI4-6_dg | MCQ160B-D | Binary | ## Survey Design | Component | KNHANES | NHANES | |-----------|---------|--------| | Strata | kstrata | SDMVSTRA | | PSU/Cluster | psu | SDMVPSU | | Weight | wt_itvex | WTMEC2YR (single-cycle) or WTMECPRP (pooled) | | R function | svydesign(id=~psu, strata=~kstrata, weights=~wt_itvex, nest=TRUE) | svydesign(id=~SDMVPSU, strata=~SDMVSTRA, weights=~WTMEC2YR, nest=TRUE) | ## Adding New Variables When a new variable is validated through /replicate-study or /cross-national: 1. Add an entry in the appropriate section (Exposure or Outcome) 2. Include both KNHANES and NHANES coding 3. Note any text-label gotchas for NHANES 4. Document the source paper that validated the coding
-
-
SKILL.md 11.4 KB
--- name: batch-cohort description: Generate N analysis scripts from a single methodology template × multiple exposure/outcome combinations. The "80-person team" pattern — same validated method, swap variables only. Produces batch R/Python code + summary matrix. triggers: batch cohort, batch analysis, 대량 분석, 변수 교체, variable swap, mass production, 80명 팀, batch generate, 일괄 코드 생성, exposure outcome matrix, combinatorial analysis tools: Read, Write, Edit, Bash, Grep, Glob model: opus --- # Batch Cohort Analysis Skill You are assisting a medical researcher in generating multiple analysis scripts from a single validated methodology template, each differing only in the exposure/outcome variable combination. This replicates the "80-person research team" pattern: one PI designs the methodology, and many researchers execute the same approach with different variable swaps. ## When to Use - Researcher has a **validated analysis template** (e.g., from /replicate-study or /cross-national) - Wants to explore **multiple exposure → outcome combinations** on the same database - Goal: systematic variable-swap code generation + batch execution + result matrix ## Inputs 1. **Database path(s)**: CSV/SAS data files (KNHANES, NHANES, NHIS, or any cleaned cohort) 2. **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) 3. **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 ### 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**: If TRUE, generates paired scripts for both countries per combination ## Workflow ### Phase 1: Template Validation 1. Read the methodology template (R script or paper type reference). 2. Identify the **slot variables** — parts that change per combination: - `EXPOSURE_VAR`: raw variable name in the database - `EXPOSURE_LABEL`: human-readable label for tables/figures - `EXPOSURE_CODING`: how to derive binary/categorical exposure - `OUTCOME_VAR`: raw variable name - `OUTCOME_LABEL`: human-readable label - `OUTCOME_CODING`: how to derive binary outcome 3. Verify the template runs successfully on at least one combination before batch generation. 4. Output: template summary with identified slots → user approval. ### Phase 2: Variable Specification For each exposure and outcome in the combination spec: 1. **Look up** the variable in the database: - KNHANES: check variable name exists in the CSV header - NHANES: check which table contains the variable (use codebook.csv if available) - NHIS: check claims code or variable name 2. **Define coding**: - Binary: threshold or category mapping (e.g., `HE_glu >= 126 → diabetes = 1`) - Categorical: level definitions (e.g., `smoking: current/former/never`) 3. **Check covariate overlap**: If the exposure IS one of the standard covariates, remove it from the adjustment set for that analysis (no self-adjustment). 4. Output: **combination matrix** 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 For each combination in the matrix: 1. **Clone** the template script. 2. **Replace** slot variables with the combination-specific values. 3. **Adjust covariates**: Remove exposure variable from covariate list if present. 4. **Set output paths**: Each combination gets its own results subdirectory. 5. **Generate a master runner script** (`run_all.R` or `run_all.sh`) that: - Executes all N scripts sequentially (or in parallel via `future`/`parallel`) - Captures errors per script without stopping the batch - Logs execution time per analysis ### Phase 4: Batch Execution (if `execute` or `full` mode) 1. Run the master script. 2. Collect results from each combination's output directory. 3. Handle failures gracefully: - Log which combinations failed and why - Common failures: convergence issues, too few events, empty subgroups - Suggest fixes for failed combinations ### Phase 5: Summary Matrix Aggregate all results into a single summary: **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 | |----------|---------|---|--------|---------------------|---------------------|---------------------|---------|-------------| | Depression | Diabetes | 5,811 | 487 | 2.14 (1.52–3.01) | 1.89 (1.33–2.69) | 1.36 (0.91–2.05) | 0.137 | No | | Obesity | Diabetes | 5,811 | 487 | 3.45 (2.71–4.39) | 3.38 (2.65–4.32) | 3.12 (2.42–4.02) | <0.001 | Yes | | ... | | | | | | | | | **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. ## 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 │ ├── 02_obesity_diabetes/ │ │ └── ... │ └── ... ├── 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 ``` ## Critical Rules 1. **Never modify the core methodology** across combinations — only swap exposure/outcome/covariates. 2. **Remove self-adjustment**: If exposure = BMI, remove obesity from covariates. If exposure = education/income, remove the same variable from covariates. If outcome = MetS, consider removing obesity from covariates. Document all removals. 3. **Weighted analysis mandatory** for KNHANES/NHANES/NHIS — inherited from template. 4. **Event count check**: Before running, verify each outcome has ≥10 events per covariate (EPV rule). Flag underpowered combinations. 5. **Multiple comparisons**: When generating >5 combinations, include a Bonferroni-corrected significance column in the summary matrix. Add a note about exploratory vs confirmatory framing. 6. **Reproducibility**: Freeze the template version. Include a SHA256 hash of the data file in README. 7. **No p-hacking framing**: The summary matrix is for **hypothesis generation**, not confirmation. State this explicitly in README and any manuscript output. 8. **Outcome definitions MUST include physician diagnosis**: 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"). Lab-only definitions systematically overestimate exposure→outcome associations (validated: Joo 2026 replication showed US depression→DM wOR 1.92 without vs 1.54 with physician dx). 9. **Full covariate set is default**: Always use 8 covariates (age, sex, education, income, smoking, alcohol, obesity, CVD) unless explicitly justified. Minimal models (age+sex+BMI only) overestimate effects due to residual confounding. 10. **Generated-code quality gate**: Because this skill emits N near-identical scripts, a single reproducibility slip (a missing seed, an absolute path, a hand-typed data literal) replicates across the whole batch. After Phase 3, lint the generated scripts with the `/analyze-stats` code-quality gate (`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. ## Cross-National Batch Mode When `cross_national: true`: - Generate paired scripts for each combination (Korea + US) - Summary matrix includes both countries side-by-side - Direction agreement column: ✓ if both countries show same direction of effect - Uses /cross-national skill's dual-survey-design approach ## Integration with Upstream Skills | Need | Skill | |------|-------| | Variable coding lookup | `analyze-stats` survey_weighted guide | | Template creation from paper | `/replicate-study` Phase 1–3 | | Cross-national paired analysis | `/cross-national` | | ICD-10 claims algorithms | `analyze-stats` nhis_icd10_mapping guide | | Write manuscript from results | `/write-paper` (nhis_cohort or cross_national type) | | Figure generation | `/make-figures` (forest plot of all combinations) | ## Example Invocations ### Basic: Single DB, Multiple Exposures × Single Outcome ``` /batch-cohort DB: /path/to/knhanes/HN18.csv Template: /path/to/validated_analysis.R Exposures: [depression, obesity, smoking, heavy_drinking, low_income, low_education] Outcome: diabetes Mode: full ``` ### Cross-National: Full Matrix ``` /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 ``` ### NHIS Cohort: Claims-Based Batch ``` /batch-cohort DB: /path/to/nhis_sample_cohort.csv Template: nhis_cohort Exposures: [atrial_fibrillation, heart_failure, COPD, CKD] Outcomes: [all_cause_mortality, cardiovascular_death, stroke] Mode: code_only ``` ## Anti-Hallucination - **Never fabricate variable names, dataset column names, or variable codings.** If a variable mapping is uncertain, output `[VERIFY: variable_name]` and ask the user to confirm against the data dictionary. - **Never fabricate statistical results** — no invented p-values, effect sizes, confidence intervals, or sample sizes. All numbers must come from executed code output. - **Never generate references from memory.** Use `/search-lit` for all citations. - If a function, package, or API does not exist or you are unsure, say so explicitly rather than guessing. -
skill.yml 1.3 KB
schema_version: 2 name: batch-cohort layer: B owner_domain: batch_analysis maturity: official when_to_use: "Generate N analysis scripts from one validated methodology template across many exposure/outcome combinations." when_NOT_to_use: "A single analysis (use analyze-stats); cross-country comparison (use cross-national)." inputs: - "methodology template" - "exposure/outcome combination matrix" outputs: - "N analysis scripts" - "summary matrix" side_effects: - writes_project_artifacts downstream_consumers: - analyze-stats - self-review forbidden_actions: - alter_methodology_per_combination_without_disclosure - fabricate_results_matrix # v2.1 quality card purpose: "Scale one validated method across many variable combinations, swapping only exposure/outcome, never the method." safety_boundaries: - "The methodology is held constant across all generated scripts; deviations are disclosed." - "Generated scripts run on real data; no results are pre-filled." known_limitations: - "Inherits the source template's assumptions; a flawed template propagates." - "No standalone demo; outputs are code to be executed and reviewed." validation_commands: - "execute each generated script and reconcile the summary matrix" - "/self-review" evidence_surface: manual_workflow
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.