Model Calibration Curve logo

Model Calibration Curve

OrganizationPopular
aipoch
model-calibration-curve

Use when assessing how well a survival model's predicted probabilities agree with observed outcomes by fitting a Cox model and generating bootstrap calibration curves at one or more prediction horizons from a clinical CSV file. NOT for: nomogram construction, univariate Cox screening, ROC analysis, or decision-curve analysis.

Overview

Publisheraipoch
Repositorymedical-research-skills
Skill namemodel-calibration-curve
Stars
1.9K
Forks
175
Bundled files
11
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 11 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by aipoch on GitHub. Read the source before you install it.

Installation

Install the Model Calibration Curve AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.

Use it in TypingMind

Enable Model Calibration Curve in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Model Calibration Curve on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Model Calibration Curve is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Model Calibration Curve

When to Use

Use this skill when you need to:

  • validate a survival model with bootstrap calibration curves;
  • compare predicted and observed survival probabilities at multiple horizons;
  • export calibration statistics together with a PDF visualization.

Typical user requests:

  • "Generate 1-, 2-, and 3-year calibration curves for this prognosis model."
  • "Check whether the Cox model built from age, gender, and risk is well calibrated."
  • "Export calibration statistics and a calibration PDF from this clinical cohort."

When Not to Use

Do not use this skill for:

  • nomogram construction;
  • univariate or multivariable Cox feature screening;
  • ROC, calibration-free discrimination, or decision-curve analysis;
  • non-survival endpoints or multiclass classification tasks.

When to Read External Files

SituationFile to ReadPurpose
Need algorithm detailsreferences/algorithm.mdStatistical method and formulas
Need to run analysisscripts/main.RGet the complete command
Encounter errorsreferences/troubleshooting.mdFind solutions
Need CLI examplesreferences/cli-guide.mdParameter usage examples

Input Validation

This skill accepts:

  • A clinical CSV file with sample IDs as row names, survival time, event indicator, and pre-selected prognostic features
  • Requests to assess calibration of a survival (Cox) model via bootstrap resampling at one or more prediction horizons

If the user's request does not involve survival model calibration from a clinical CSV file — for example, asking to construct a nomogram, screen Cox features, generate an ROC curve, analyze a decision curve, or work with non-survival outcomes — do not proceed with this workflow. Instead respond:

"model-calibration-curve is designed to validate survival model calibration by generating bootstrap calibration curves from a clinical CSV file. Your request appears to be outside this scope. Please use a nomogram-construction skill for nomogram building, a roc-diagnostic-performance skill for ROC analysis, or a decision-curve-analysis skill for DCA."


Prerequisites

R packages required: rms, qs, openxlsx, optparse.

Install with:

r
install.packages(c("rms", "qs", "openxlsx", "optparse"), repos = "https://cloud.r-project.org")

Or run the bootstrap installer:

bash
Rscript scripts/install_dependencies.R

Note: --help requires optparse to be loaded. If the package check fires before option parsing, install optparse first, then run --help. The root fix (deferring heavy package checks until after argument parsing) must be applied in scripts/main.R.


Usage

bash
Rscript scripts/main.R \
  --data_file ./clinical_data.csv \
  --features age,stage,risk \
  --years 1,2,3 \
  --output_dir ./output/

Arguments

ShortLongTypeDefaultDescription
-d--data_filecharacterrequiredClinical CSV file with sample IDs as row names
-f--featurescharacterrequiredComma-separated model features used in the Cox model
-t--time_colcharacterfutimeSurvival time column
-e--event_colcharacterfustatEvent indicator column using 0/1 encoding
-y--yearscharacter1,2,3Prediction horizons in the same units as time_col
-b--bootstrap_repsinteger1000Bootstrap replications for rms::calibrate()
-o--output_dircharacter./output/Output directory
--overwriteflagFALSEAllow writing into a non-empty output directory
-s--seedinteger42Random seed for reproducibility
-T--timeout_secondsinteger0Elapsed time limit in seconds; 0 disables timeout
--plot_widthdouble6PDF width in inches
--plot_heightdouble6PDF height in inches
--font_familycharactersansPDF font family
--line_widthdouble1.5Calibration curve line width
--colorscharacter#0073C2,#EFC000,#868686,#CD534C,#7AA6DDComma-separated colors for time-point curves
--plot_titlecharacterCalibration CurvePlot title
--base_cexdouble0.9Base text-size multiplier

Input Format

Clinical Data (--data_file)

CSV file with row names as sample IDs and columns for model features, survival time, and event indicator.

csv
"",age,gender,stage,futime,fustat,risk
"SAMPLE_001",">65","Female","StageI&II",1.12,0,"high"
"SAMPLE_002","<=65","Male","StageIII&IV",1.92,1,"high"
"SAMPLE_003",">65","Male","StageI&II",4.47,1,"low"

Requirements

  • File extension must be .csv.
  • Row names must be unique sample IDs.
  • All requested features plus time_col and event_col must exist.
  • Survival time values must be finite numbers greater than 0.
  • Event values must use 0/1 encoding.
  • Complete-case filtering must leave at least 30 samples and at least 10 events.

Feature Selection (--features)

  • Comma-separated without line breaks: age,gender,risk
  • Character predictors are converted to factors before Cox fitting.
  • If every requested feature is absent after validation, the run stops.

Output Files

FileFormatDescription
data/calibration_data.qsQS serialized objectSerialized calibration result bundle, including calibration objects and summary metadata
table/calibration_statistics.xlsxExcel workbook (.xlsx)Per-time-point means and overall model summary
plot/calibration_curve.pdfPDF (.pdf)Combined calibration curve visualization
session_info.txtPlain text (.txt)Session information and run parameters

calibration_statistics.xlsx

Workbook sheets:

  • Time_Point_Stats: predicted mean, observed mean, and bias-corrected mean for each calibration horizon.
  • Model_Summary: overall C-index, sample count, event count, selected features, and fitted formula.

Workflow

Step 1: Validate Input

  • Confirm the clinical CSV exists and is readable.
  • Check that requested features, survival time, and event columns are present.
  • Remove incomplete rows across all required columns.

Step 2: Prepare Survival Modeling Data

  • Convert survival time and event columns to numeric.
  • Convert character predictors to factors.
  • Reject data with non-positive follow-up times, invalid event coding, too few samples, or too few events.

Step 3: Build Calibration Models

  • Fit a Cox proportional hazards model with the requested features.
  • Run rms::calibrate() for each prediction horizon using bootstrap resampling.
  • Compute the concordance index for the fitted model.

Step 4: Save Outputs

  • Serialize the calibration result bundle as .qs.
  • Export statistics to Excel.
  • Render a combined calibration PDF.
  • Record session metadata for reproducibility.

Examples

Basic Calibration Analysis

bash
Rscript scripts/main.R \
  --data_file clinical_data.csv \
  --features age,stage,risk \
  --output_dir ./output/

Custom Horizons And Bootstrap Count

bash
Rscript scripts/main.R \
  --data_file clinical_data.csv \
  --features age,gender,risk \
  --years 1,3,5 \
  --bootstrap_reps 1500 \
  --output_dir ./custom_output/

Custom Plot Styling

bash
Rscript scripts/main.R \
  --data_file clinical_data.csv \
  --features age,stage,risk \
  --plot_width 7 \
  --plot_height 6 \
  --line_width 2 \
  --colors "#1B9E77,#D95F02,#7570B3" \
  --plot_title "Three-Horizon Calibration" \
  --output_dir ./styled_output/

With Bundled Test Data

bash
Rscript scripts/main.R \
  --data_file tests/data/sample_clinical_survival_data.csv \
  --features age,gender,risk \
  --bootstrap_reps 20 \
  --output_dir tests/output/ \
  --overwrite

Error Handling

ErrorCauseSolution
SKILL_INVALID_PARAMETERMissing required argument, invalid numeric values, invalid event coding, insufficient complete cases, insufficient events, or failed model fittingCheck argument values, data validity, and event/sample counts
SKILL_FILE_NOT_FOUNDInput CSV does not existVerify the path
SKILL_MISSING_COLUMNSRequired feature/time/event columns are absentCheck column names and spelling
SKILL_EMPTY_DATAInput file is empty, complete-case filtering removed all rows, or no requested features remainedCheck file content and requested feature names
SKILL_SAMPLE_MISMATCHReserved for cross-file sample mismatch scenariosNot expected for this single-file workflow
SKILL_PACKAGE_NOT_FOUNDRequired R package is missingInstall with: Rscript -e "install.packages(c('rms', 'qs', 'openxlsx'), repos='https://cloud.r-project.org')"

IF error persists, READ: references/troubleshooting.md


Testing

Smoke Test With Included Data

bash
Rscript scripts/main.R --help

Rscript scripts/main.R \
  --data_file tests/data/sample_clinical_survival_data.csv \
  --features age,gender,risk \
  --bootstrap_reps 20 \
  --output_dir tests/output/ \
  --overwrite

Automated Smoke Test Script

bash
Rscript tests/run_smoke_test.R

Optional shell wrapper:

bash
bash tests/run_smoke_test.sh

Expected Output

text
tests/output/
|-- data/calibration_data.qs
|-- plot/calibration_curve.pdf
|-- session_info.txt
`-- table/calibration_statistics.xlsx

References

  1. Harrell FE. Regression Modeling Strategies.
  2. Steyerberg EW et al. Assessing the performance of prediction models.
  3. Austin PC, Steyerberg EW. Graphical assessment of calibration for survival models.

For detailed algorithm, READ: references/algorithm.md


Implementation Checklist

  • CLI parsing with optparse
  • set.seed() for reproducibility
  • Top-level CRAN dependency checks
  • Session info recording
  • Timeout parameter exposed as CLI option
  • Relative-path source() usage via get_script_dir()
  • Modular script structure in scripts/
  • Test data provided in tests/data/
  • Error handling with SKILL_* codes
  • Reference docs provided in references/

Last updated: 2026-04-27 | Version: 2.1.0

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Model Calibration Curve AI skill do?

Use when assessing how well a survival model's predicted probabilities agree with observed outcomes by fitting a Cox model and generating bootstrap calibration curves at one or more prediction horizons from a clinical CSV file. NOT for: nomogram construction, univariate Cox screening, ROC analysis, or decision-curve analysis.

Why use Model Calibration Curve on TypingMind?

Because you install it once and use it with any model. Model Calibration Curve is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Model Calibration Curve in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/aipoch/medical-research-skills/tree/main/awesome-med-research-skills/Data%20Analysis/model-calibration-curve. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Model Calibration Curve?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Model Calibration Curve?

As many as you like. As long as a model supports skills, you can use Model Calibration Curve with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Model Calibration Curve AI skill free?

Yes. It is published on GitHub by aipoch under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇