Km survival curve

From aipoch/medical-research-skills · View interactive version

Km survival curve is an AI agent skill from the GitHub repository aipoch/medical-research-skills. Use when generating Kaplan-Meier survival curves from tabular survival data containing time, event status, and a precomputed risk group. Supports command-line parameter input, parameter validation, automatic time-unit handling, single-file PDF figure export, and session metadata capture.

How to use this skill

Skill file

Source: https://github.com/aipoch/medical-research-skills

Kaplan-Meier Survival Curve Analysis

Use this skill to run Kaplan-Meier survival analysis on a tabular dataset and export a single PDF survival figure.

Use This Skill When

Primary Command

Rscript scripts/main.R \
  --input_file <input_file> \
  --output_dir <output_dir> \
  --time_col <time_column> \
  --status_col <status_column> \
  --risk_col <group_column>

Prerequisites

Core Arguments

| Argument | Required | Description |

|----------|----------|-------------|

| --input_file | Yes | Input data file in CSV or tab-delimited TXT/TSV format |

| --output_dir | No | Output directory, default ./KM_Results |

| --time_col | No | Survival time column, default futime |

| --status_col | No | Event status column, default fustat |

| --risk_col | No | Risk group column, default risk_group |

| --time_unit | No | Time unit label: year, month, or day, default year |

| --auto_convert_days | No | Heuristically convert large time values from days when time_unit is year or month, default true |

| --statistics_method | No | logrank or wald, default logrank |

Plot Customization Arguments

| Argument | Default | Description |

|----------|---------|-------------|

| --figure_width | 10 | Figure width in inches |

| --figure_height | 7 | Figure height in inches |

| --figure_family | sans | Font family |

| --title_x | Time | X-axis title. If left as default, the script renders Time (<time_unit>) |

| --title_y | Survival probability | Y-axis title |

| --title_main | empty | Plot title |

| --legend_position | top | top, bottom, left, right, none |

| --legend_show | true | Whether to show legend |

| --legend_title | empty | Legend title |

| --line_type | solid | Survival line type: solid, dashed, dotted, dotdash, longdash, twodash |

| --line_size | 1 | Survival line width |

| --line_colors | #4DBBD5,#E64B35,#00A087,#3C5488,#F39B7F,#8491B4,#91D1C2,#DC0000 | Comma-separated group colors |

| --censor_show | true | Whether to show censor markers |

| --censor_size | 7 | Censor marker size |

| --confidence_show | true | Whether to show confidence interval |

| --confidence_alpha | 0.2 | Confidence band transparency |

| --risk_table_show | true | Whether to show the risk table |

| --risk_table_border | true | Whether to show the risk table border |

| --risk_table_panel | false | Whether to show the risk table panel background |

| --risk_table_size | 6 | Risk table font size |

| --axis_title_size | 12 | Axis title font size |

| --axis_text_size | 10 | Axis tick-label font size |

| --legend_text_size | 11 | Legend text font size |

Input Requirements

Example input:

id	fustat	futime	risk_score	risk_group	GPR161	RIBC2
TCGA-C5-A1M5	1	5.62191780821918	-1.10702407761445	low	2.82521576230566	5.35318564979635
TCGA-VS-A94W	0	3.40547945205479	-0.671246677921865	high	4.26241812321536	4.00802068790173

Bundled test datasets:

Minimal Workflow

  1. Confirm the input file exists and identify the time, status, and group columns.
  2. Run scripts/main.R with the requested output directory and any optional plot parameters.
  3. Check the output directory for km-plot.pdf.

If you omit --input_file, the script exits with SKILL_MISSING_INPUT.

Outputs

Expected output:

<output_dir>/
├── km-plot.pdf
└── session_info.txt

Interpretation Guide

Time Conversion Caution

Reproducibility Note

Do Not Use This Skill When

Read These Files When Needed

| Need | File |

|------|------|

| Kaplan-Meier method details and interpretation | references/algorithm.md |

| More CLI examples | references/cli-guide.md |

| Error diagnosis | references/troubleshooting.md |

| Main execution entry point | scripts/main.R |

| Sample test data | tests/data/km_sample1.txt, tests/data/km_sample2.txt, tests/data/km_sample3.txt |

Quick Examples

Basic Kaplan-Meier analysis:

Rscript scripts/main.R \
  --input_file tests/data/km_sample1.txt \
  --output_dir tests/output_basic

Custom column names:

Rscript scripts/main.R \
  --input_file tests/data/km_sample1.txt \
  --time_col futime \
  --status_col fustat \
  --risk_col risk_group \
  --output_dir tests/output_custom_columns

Custom plot title:

Rscript scripts/main.R \
  --input_file tests/data/km_sample2.txt \
  --title_main "Study KM Curve" \
  --output_dir tests/output_title

Hide confidence interval and risk table:

Rscript scripts/main.R \
  --input_file tests/data/km_sample3.txt \
  --confidence_show false \
  --risk_table_show false \
  --output_dir tests/output_simple

Validation

Rscript scripts/main.R --help
Rscript scripts/main.R \
  --input_file tests/data/km_sample1.txt \
  --output_dir tests/validation_output

After running analysis, verify that tests/validation_output/km-plot.pdf exists.

Common Errors

If the issue is not obvious, read references/troubleshooting.md.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.