{"data":{"slug":"github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-nomogram-construction-9de0b904db3c","title":"Build Prognosis Nomogram from Survival Predictors","summary":"Construct a prognosis nomogram from pre-selected survival predictors, export the nomogram bundle, and generate a C-index table. Use for survival outcome modeling with pre-selected features.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-nomogram-construction-9de0b904db3c","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-nomogram-construction-9de0b904db3c","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-nomogram-construction-9de0b904db3c.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-awesome-med-research-skills-data-analysis-nomogram-construction-9de0b904db3c\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure the input CSV file has sample IDs as row names in the first column, at least 3 prognostic features, and at least 20 complete samples with 10 events. Install required R packages (`rms`, `openxlsx`, `qs`, `optparse`) before running the script.","instructions":"---\nname: nomogram-construction\ndescription: \"Use when constructing a prognosis nomogram from survival-related clinical predictors, exporting the nomogram bundle and C-index table, and optionally rendering the final nomogram PDF. NOT for: univariate\/multivariable Cox feature screening, calibration curves, ROC analysis, decision-curve analysis, or non-survival outcomes.\"\nlicense: MIT\nskill-author: AIPOCH\n---\n\n# Nomogram Construction\n\n## When to Use\n\nUse this skill when you need to:\n- build a prognosis nomogram from already selected clinical prognostic variables;\n- estimate model discrimination with a C-index table;\n- export a nomogram bundle and generate a publication-ready nomogram PDF.\n\nTypical user requests:\n- \"Build a prognosis nomogram from age, stage, and risk score.\"\n- \"Use these Cox-selected predictors to construct a nomogram and calculate the C-index.\"\n- \"Generate a nomogram PDF from a survival prediction model.\"\n\n## When Not to Use\n\nDo not use this skill for:\n- screening prognostic variables from scratch with Cox regression;\n- ROC curves, calibration curves, or decision-curve analysis;\n- diagnosis models, binary classification, or non-survival outcomes;\n- single-cell, differential-expression, or pathway analysis.\n\n## When to Read External Files\n\n| Situation | File to Read | Purpose |\n|-----------|--------------|---------|\n| **Need algorithm details** | `references\/algorithm.md` | Cox-based nomogram workflow, C-index, and assumptions |\n| **Need to run analysis** | `scripts\/main.R` | Execute `Rscript scripts\/main.R --mode build ...` or `--mode plot ...` |\n| **Encounter errors** | `references\/troubleshooting.md` | Common `SKILL_*` errors and solutions |\n| **Need CLI examples** | `references\/cli-guide.md` | Detailed command-line examples |\n| **Need test data** | `tests\/data\/` | Example clinical CSV for smoke testing |\n\n## Input Validation\n\nThis skill accepts:\n\n- A clinical CSV file with survival time, event indicator, and pre-selected prognostic features\n- Requests to build a Cox-based prognostic nomogram and compute the C-index\n- Requests to re-render a nomogram PDF from an existing `.qs` bundle (plot mode)\n\nIf the user's request does not involve nomogram construction from survival data \u2014 for example, asking to screen features with Cox regression, generate calibration curves, perform ROC analysis, or analyze non-survival binary outcomes \u2014 do not proceed with this workflow. Instead respond:\n\n> \"nomogram-construction is designed to build a prognosis nomogram from pre-selected survival predictors and export the nomogram bundle with C-index table. Your request appears to be outside this scope. Please use a Cox feature-screening skill for variable selection, or a calibration-curve\/ROC skill for model validation.\"\n\n---\n\n## Prerequisites\n\nR packages required: `rms`, `openxlsx`, `qs`, `optparse`.\n\nInstall with:\n```r\ninstall.packages(c(\"rms\", \"openxlsx\", \"qs\", \"optparse\"), repos = \"https:\/\/cloud.r-project.org\")\n```\n\nOr run the bootstrap installer:\n```bash\nRscript scripts\/install_dependencies.R\n```\n\n> Note: `--help` requires `optparse` to be loaded. If the package check fires before option parsing, install `optparse` first, then run `--help`.\n\n---\n\n## Usage\n\n### Build Nomogram Bundle\n\n```bash\nRscript scripts\/main.R \\\n  --mode build \\\n  --data_file .\/clinical_data.csv \\\n  --features age,stage,risk \\\n  --time_col futime \\\n  --event_col fustat \\\n  --years 1,2,3 \\\n  --output_dir .\/output\/ \\\n  --seed 42\n```\n\n### Render Nomogram Plot\n\n```bash\nRscript scripts\/main.R \\\n  --mode plot \\\n  --nomo_data_file .\/output\/data\/Nomogram_list.qs \\\n  --plot_save .\/output\/plot\/nomogram_plot.pdf\n```\n\n---\n\n## Arguments\n\n| Short | Long | Type | Default | Description |\n|-------|------|------|---------|-------------|\n| `-m` | `--mode` | character | `build` | Execution mode: `build` or `plot` |\n| `-d` | `--data_file` | character | **required for build** | Clinical CSV file with sample IDs as row names |\n| `-f` | `--features` | character | **required for build** | Comma-separated prognostic features |\n| `-t` | `--time_col` | character | `futime` | Survival time column |\n| `-e` | `--event_col` | character | `fustat` | Event column encoded as `1=event`, `0=censored` |\n| `-y` | `--years` | character | `1,2,3` | Prediction time points in years |\n| `-o` | `--output_dir` | character | `.\/output\/` | Output directory for build mode |\n|  | `--overwrite` | flag | `FALSE` | Allow writing into a non-empty output directory |\n| `-n` | `--nomo_data_file` | character | **required for plot** | Nomogram bundle in `.qs` format |\n| `-p` | `--plot_save` | character | **required for plot** | Output PDF path |\n| `-w` | `--plot_width` | double | `11` | Plot width in inches |\n| `-H` | `--plot_height` | double | `8` | Plot height in inches |\n| `-F` | `--font_size` | double | `8` | Plot font size |\n| `-l` | `--line_width` | double | `5` | Plot line width |\n|  | `--font_family` | character | `sans` | Font family for PDF output |\n| `-s` | `--seed` | integer | `42` | Random seed for reproducibility |\n| `-T` | `--timeout_seconds` | integer | `0` | Elapsed time limit in seconds; `0` disables timeout |\n\n---\n\n## Input Format\n\n### Clinical Data (`data_file`)\n\nCSV file with sample IDs as row names and one column per feature\/end-point variable.\n\n```csv\n\",age,stage,risk,futime,fustat\nSAMPLE_001,65,StageIII,high,365,1\nSAMPLE_002,52,StageII,low,730,0\nSAMPLE_003,78,StageIV,high,180,1\n```\n\n**Requirements**\n- File format must be CSV.\n- Sample IDs must be stored in the first column as row names.\n- At least 3 prognostic features are required.\n- `time_col` must contain finite numeric values greater than `0`.\n- `event_col` must contain only `0` and `1`.\n- At least 20 complete samples and at least 10 events are required after filtering incomplete rows.\n\n### Nomogram Bundle (`nomo_data_file`)\n\nThe plot mode reads the `.qs` bundle produced by build mode.\n\nRequired bundle objects:\n- `nomogram`\n- `c_index`\n- `model`\n- `data`\n- `features`\n- `time_points`\n\n---\n\n## Output Files\n\n### Build Mode\n\n| File | Description |\n|------|-------------|\n| `data\/Nomogram_list.qs` | Serialized nomogram bundle |\n| `data\/analysis_data.rds` | Complete-case dataset used for modeling |\n| `table\/nomogram_c_index.xlsx` | Nomogram discrimination summary |\n| `session_info.txt` | Session information and build parameters |\n\n### Plot Mode\n\n| File | Description |\n|------|-------------|\n| `plot\/nomogram_plot.pdf` | Rendered nomogram PDF |\n| `plot\/session_info.txt` | Plotting session information and parameters |\n\n### `nomogram_c_index.xlsx`\n\n| Column | Description |\n|--------|-------------|\n| `metric` | Reported metric name |\n| `value` | Metric value |\n\n---\n\n## Workflow\n\n### Step 1: Validate Input\n- Check file existence and CSV format.\n- Validate required feature, time, and event columns.\n- Validate time\/event values and minimum sample\/event counts.\n\n### Step 2: Prepare Modeling Dataset\n- Keep only requested features and outcome columns.\n- Convert character predictors to factors.\n- Remove incomplete rows across model variables.\n\n### Step 3: Fit Cox-Based Nomogram Model\n- Fit an `rms::cph` survival model.\n- Build survival functions at requested time points.\n- Construct the nomogram object.\n\n### Step 4: Evaluate Performance\n- Compute the model C-index.\n- Save a compact discrimination summary table.\n\n### Step 5: Save And Plot\n- Save the nomogram bundle and analysis dataset.\n- Render the nomogram PDF in plot mode.\n\n---\n\n## Examples\n\n### Basic Build\n\n```bash\nRscript scripts\/main.R \\\n  --mode build \\\n  -d clinical_data.csv \\\n  -f age,stage,risk \\\n  -o .\/output\/\n```\n\n### Custom Prediction Horizons\n\n```bash\nRscript scripts\/main.R \\\n  --mode build \\\n  -d clinical_data.csv \\\n  -f age,stage,risk,treatment \\\n  -y 1,3,5 \\\n  -o .\/output\/\n```\n\n### Plot Existing Bundle\n\n```bash\nRscript scripts\/main.R \\\n  --mode plot \\\n  -n .\/output\/data\/Nomogram_list.qs \\\n  -p .\/output\/plot\/nomogram_plot.pdf \\\n  -w 12 -H 9 -F 10\n```\n\n---\n\n## Error Handling\n\n| Error | Cause | Solution |\n|-------|-------|----------|\n| `SKILL_FILE_NOT_FOUND` | Input file does not exist | Verify the file path |\n| `SKILL_EMPTY_DATA` | Input file is empty or has no usable rows and columns | Re-export the input file with valid rows and columns |\n| `SKILL_MISSING_COLUMNS` | Required columns are absent from the clinical data | Check column names and spelling |\n| `SKILL_INVALID_DATA` | Invalid time\/event encoding, malformed bundle, or unreadable CSV\/QS file | Check input values and file integrity |\n| `SKILL_INSUFFICIENT_DATA` | Too few features, complete samples, or events | Provide more valid predictors or samples |\n| `SKILL_ANALYSIS_ERROR` | `cph()` fitting, nomogram construction, or output writing failed | Check data quality, factor levels, and event distribution |\n| `SKILL_INVALID_PARAMETER` | Missing required CLI value, invalid mode, invalid years, or overwrite conflict | Review command-line arguments |\n| `SKILL_PACKAGE_NOT_FOUND` | Required R package is not installed | Install with: `Rscript -e \"install.packages(c('rms', 'openxlsx', 'qs'), repos='https:\/\/cloud.r-project.org')\"` |\n| `SKILL_TIMEOUT` | The configured timeout was exceeded | Increase `--timeout_seconds` or reduce workload |\n\n**IF error persists**, READ: `references\/troubleshooting.md`\n\n---\n\n## Testing\n\n### Smoke Test With Included Data\n\n```bash\nRscript scripts\/main.R --help\n\nRscript scripts\/main.R \\\n  --mode build \\\n  -d tests\/data\/yuhou_cli_data.csv \\\n  -f age,gender,risk \\\n  -o tests\/expected_output\/ \\\n  --overwrite\n\nRscript scripts\/main.R \\\n  --mode plot \\\n  -n tests\/expected_output\/data\/Nomogram_list.qs \\\n  -p tests\/expected_output\/plot\/nomogram_plot.pdf\n```\n\n### Automated Smoke Test Script\n\n```bash\nRscript tests\/run_smoke_test.R\n```\n\nOptional shell wrapper:\n\n```bash\nbash tests\/run_smoke_test.sh\n```\n\n### Expected Output\n\n```text\ntests\/expected_output\/\n|-- data\/analysis_data.rds\n|-- data\/Nomogram_list.qs\n|-- plot\/nomogram_plot.pdf\n|-- plot\/session_info.txt\n|-- session_info.txt\n`-- table\/nomogram_c_index.xlsx\n```\n\nHistorical development artifacts may still exist in `tests\/output\/`, but standardized validation uses `tests\/expected_output\/`.\n\n---\n\n## References\n\n1. Harrell FE (2015). *Regression Modeling Strategies*.\n2. Iasonos A et al. (2008). How to build and interpret a nomogram for cancer prognosis. *Journal of Clinical Oncology*.\n3. Balachandran VP et al. (2015). Nomograms in oncology: more than meets the eye. *The Lancet Oncology*.\n\n**For detailed algorithm**, READ: `references\/algorithm.md`\n\n---\n\n## Implementation Checklist\n\n- [x] CLI parsing with `optparse`\n- [x] `set.seed()` for reproducibility\n- [x] `requireNamespace()` dependency checks\n- [x] Session info recording\n- [x] Timeout parameter exposed as CLI option\n- [x] File reading instructions in `SKILL.md`\n- [x] Modular script structure in `scripts\/`\n- [x] Test data provided in `tests\/data\/`\n- [x] Error handling with `SKILL_*` codes\n- [x] References documented in `references\/`\n\n---\n\n*Last updated: 2026-04-27 | Version: 2.1.0*\n","use_cases":["Build a prognosis nomogram from age, stage, and risk score.","Use Cox-selected predictors to construct a nomogram and calculate the C-index.","Generate a nomogram PDF from a survival prediction model."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/aipoch\/medical-research-skills\/blob\/686e09dfdb45d9fa1a08664f06bb93769b3c9d91\/awesome-med-research-skills\/Data%20Analysis\/nomogram-construction\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T07:23:25.000000Z","updated_at":"2026-11-24T07:13:04.000000Z","seo_title":"Build Prognosis Nomogram from Survival Predictors","seo_description":"Construct a prognosis nomogram from survival predictors, export the nomogram bundle, and generate a C-index table. Use for survival outcome modeling with pre-selected Cox","seo_keywords":["build nomogram from survival predictors","export nomogram bundle","generate C-index table","prognosis nomogram construction","survival outcome modeling"]}}