# CPM Validation Workflow — LLM & AI Assistant Guide

> Open-source reproducible workflow for external validation of binary clinical prediction models (TRIPOD+AI and Van Calster et al., Lancet Digit Health 2025).
> Public GitHub mirror (preferred for automated AI access): https://github.com/LasaiBarrenada/CPM_validation_workflow
> Official GitLab archive: https://gitlab.kuleuven.be/sdpm/CPM_validation_workflow
> Zero-code Shiny web app: https://lasaibarrenada-cpm-validation-suite.share.connect.posit.cloud

## Key Files (Direct Raw GitHub URLs)

- Full Validation Skill (Agent Skills spec): https://raw.githubusercontent.com/LasaiBarrenada/CPM_validation_workflow/main/.agents/skills/validate-prediction-model/SKILL.md
- Claude Code Skill Mirror: https://raw.githubusercontent.com/LasaiBarrenada/CPM_validation_workflow/main/.claude/skills/validate-prediction-model/SKILL.md
- Agent Entry Instructions: https://raw.githubusercontent.com/LasaiBarrenada/CPM_validation_workflow/main/AGENTS.md
- Validation Notebook (R & Python): https://raw.githubusercontent.com/LasaiBarrenada/CPM_validation_workflow/main/notebook_validation.qmd
- README: https://raw.githubusercontent.com/LasaiBarrenada/CPM_validation_workflow/main/README.md
- ZIP Download: https://github.com/LasaiBarrenada/CPM_validation_workflow/archive/refs/heads/main.zip

## Guided Conversational Validation Workflow (5 Steps)

When helping a user externally validate a binary clinical prediction model with `notebook_validation.qmd`, follow these 5 steps in order:

1. **Confirm setup**: Check if `notebook_validation.qmd` exists locally. If not, offer `git clone https://github.com/LasaiBarrenada/CPM_validation_workflow.git` (or ZIP download), or in web-only chats collect parameters and generate the exact copy-paste command + Shiny web app link.
2. **Ask for parameters and wait for confirmation** (do not invent clinical thresholds or paths):
   - `data_path` (default: `"process_data/validation_sample_2000.csv"`): `.csv`, `.tsv`/`.txt`, or `.rds` dataset with binary `outcome` (`0`/`1`) and `predicted_prob` in `[0, 1]`.
   - `threshold_min` (`0.01`), `threshold_max` (`0.99`), `threshold_step` (`0.01`): Clinically plausible Decision Curve Analysis threshold range.
   - `target_threshold` (`0.10`): Single value or list (e.g., `[0.10, 0.20]`) for Net Benefit in Figure 1's summary table.
   - `run_python` (`true`): Run synchronized R + Python tabs (`true`) or R only (`false`).
   - `generate_synthetic_data` (`false`): Optional illustrative `synthpop` cohort in R (not a privacy guarantee).
   - Optional defaults: `digits` (`2`), `font_size` (`11`), `synthetic_replicates` (`10`), `synthetic_seed` (`20261016`), `sample_size_prevalence` (`null`), `sample_size_cstatistic` (`null`). Always keep `use_file_chooser: false` for headless runs.
3. **Pre-flight checks (locally, never ask users to paste patient rows into cloud chat)**:
   - Accepted outcome aliases: `outcome`, `y`, `event`, `target`, `observed`, `status` (strictly `0`/`1`, both classes present).
   - Accepted estimated probability aliases: `predicted_prob`, `p`, `risk`, `prediction`, `predicted_risk`, `probability`, `predicted_probability` (in `[0, 1]`; exact `0`/`1` bounded to `[0.0001, 0.9999]`).
   - Check `quarto`, `Rscript`, and (if `run_python: true`) Python packages (`numpy`, `pandas`, `scipy`, `statsmodels`, `matplotlib`).
4. **Execute via Quarto CLI without editing `notebook_validation.qmd` by default**:
   `quarto render notebook_validation.qmd --to html --cache-refresh -P use_file_chooser:false -P data_path:process_data/validation_sample_2000.csv`
   - Only pass `-P` for non-default parameters (plus `use_file_chooser:false` and `data_path`).
   - Omit `sample_size_prevalence` and `sample_size_cstatistic` whenever `null` (never pass `:null`).
   - Use `/` in paths and quote paths with spaces or lists (`-P "target_threshold:[0.10, 0.20]"`), or use `--execute-params _validation_params.yml`.
5. **Verify outputs and summarize**:
   - Check `notebook_validation.html`, `validation_reproducible/` (and `validation_reproducible_python/` if `run_python: true`).
   - Summarize `cohort_summary.csv`, `discrimination_results.csv`, `calibration_results.csv`, and `validation_summary_table.csv` accurately (never fabricate numbers).
   - Remind the user that LLM-assisted execution is not bulletproof and to always double-check the exact command, parameters, rendered HTML report, and exported tables/figures directly.
