$npx -y skills add Aperivue/medsci-skills --skill replicate-studyReplicate an existing cohort study's methodology on a different database. Extracts study design from a source paper, maps variables to the target DB via harmonization table, generates analysis code, and produces a replication difference report.
| 1 | # Replicate Study Skill |
| 2 | |
| 3 | You are assisting a medical researcher in replicating an existing published study's methodology |
| 4 | on a different database. This is a common research strategy: take a validated methodology from |
| 5 | Paper A (e.g., NHIS cohort study) and apply it to Database B (e.g., KNHANES, NHANES, or another |
| 6 | cohort) to produce a new paper with the same analytical rigor. |
| 7 | |
| 8 | ## When to Use |
| 9 | |
| 10 | - Researcher has a published paper they want to replicate on their own data |
| 11 | - Swapping exposure/outcome variables within the same DB |
| 12 | - Cross-national replication (e.g., Korean study → US data, or vice versa) |
| 13 | - Extending a single-institution study to a national cohort |
| 14 | |
| 15 | ## Inputs |
| 16 | |
| 17 | 1. **Source paper**: PDF, DOI, or markdown of the paper to replicate |
| 18 | 2. **Target database path**: CSV/SAS data file(s) to use |
| 19 | 3. **Harmonization table** (optional): CSV mapping source → target variables |
| 20 | - Default: `${SKILL_DIR}/references/harmonization_knhanes_nhanes.csv` (if KNHANES↔NHANES) |
| 21 | |
| 22 | ## Reference Files |
| 23 | |
| 24 | - `${SKILL_DIR}/references/methodology_extraction_template.md` — checklist for extracting study design |
| 25 | - `${SKILL_DIR}/references/harmonization_knhanes_nhanes.csv` — KNHANES↔NHANES variable mapping (67 rows) |
| 26 | - `${SKILL_DIR}/references/harmonization_3country.csv` — KNHANES+NHANES+CHNS 3-country mapping (45 rows, if available) |
| 27 | - Upstream templates (read on demand): |
| 28 | - `medsci-skills/skills/write-paper/references/paper_types/nhis_cohort.md` |
| 29 | - `medsci-skills/skills/write-paper/references/paper_types/cross_national.md` |
| 30 | - `medsci-skills/skills/analyze-stats/references/analysis_guides/survey_weighted.md` |
| 31 | - `medsci-skills/skills/analyze-stats/references/analysis_guides/propensity_score.md` |
| 32 | |
| 33 | ## Workflow |
| 34 | |
| 35 | ### Phase 1: Source Paper Analysis |
| 36 | |
| 37 | 1. Read the source paper (PDF → text, or markdown). |
| 38 | 2. Extract methodology using the extraction template: |
| 39 | - **Study design**: cohort / cross-sectional / case-control |
| 40 | - **Database**: name, country, years, N |
| 41 | - **Population**: inclusion/exclusion criteria, age range |
| 42 | - **Exposure**: variable name, definition, coding |
| 43 | - **Outcome**: variable name, definition, coding |
| 44 | - **Covariates**: full list with definitions |
| 45 | - **Statistical methods**: regression type, adjustment model, subgroup analyses |
| 46 | - **Survey design**: weights, strata, PSU (if applicable) |
| 47 | - **Sensitivity analyses**: list all |
| 48 | 3. Output: structured extraction summary for user review. |
| 49 | |
| 50 | ### Phase 2: Variable Mapping |
| 51 | |
| 52 | 1. Load the harmonization table (CSV with columns: domain, concept, source_var, target_var, notes). |
| 53 | 2. For each extracted variable (exposure, outcome, covariates): |
| 54 | - Find the matching row in the harmonization table |
| 55 | - Flag: DIRECT_MATCH / RECODE_NEEDED / NOT_AVAILABLE / PROXY_AVAILABLE |
| 56 | 3. Generate a **mapping report**: |
| 57 | - Green: directly available (no recoding) |
| 58 | - Yellow: available but needs recoding (document transformation) |
| 59 | - Red: not available in target DB (propose proxy or exclusion) |
| 60 | 4. Output: variable mapping table for user approval. |
| 61 | |
| 62 | ### Phase 3: Code Generation |
| 63 | |
| 64 | 1. Generate analysis code (Python with `pandas` + R via `subprocess` for survey-weighted): |
| 65 | a. **Data loading & cleaning**: read target DB, apply inclusion/exclusion |
| 66 | b. **Variable derivation**: recode variables per mapping table |
| 67 | c. **Survey design setup**: define svydesign object (strata, PSU, weights) |
| 68 | d. **Table 1**: demographics by exposure group (weighted) |
| 69 | e. **Main analysis**: replicate the primary model (logistic/Cox/linear regression) |
| 70 | f. **Subgroup analyses**: if specified in source paper |
| 71 | g. **Sensitivity analyses**: replicate all listed in source paper |
| 72 | 2. Use `/analyze-stats` templates where available (survey_weighted, propensity_score). |
| 73 | 3. All code must be self-contained and reproducible. |
| 74 | |
| 75 | ### Phase 4: Difference Report |
| 76 | |
| 77 | Generate a structured difference report documenting: |
| 78 | |
| 79 | | Section | Content | |
| 80 | |---------|---------| |
| 81 | | Study Design | Same / Modified (explain) | |
| 82 | | Database | Source DB → Target DB (N, years, country) | |
| 83 | | Population | Inclusion/exclusion differences | |
| 84 | | Variable Mapping | Full mapping table with match status | |
| 85 | | Unavailable Variables | What's missing and how handled | |
| 86 | | Methodological Differences | Any forced changes (e.g., BMI cutoffs, LDL calculation) | |
| 87 | | Expected Differences | Why results may differ (population, measurement, cultural) | |
| 88 | |
| 89 | Save as `replication_report.md` in the working directory. |
| 90 | |
| 91 | ### Phase 5: Validation Checklist |
| 92 | |
| 93 | Before reporting completion, verify: |
| 94 | |
| 95 | - [ ] All source paper covariates accounted for (mapped, proxied, or documen |