Kaplan–Meier survival with log-rank and number at risk
On this page
Goal
Compare survival across three treatment arms. By the end you will have Kaplan–Meier curves with a number-at-risk table, median survival per arm, log-rank and Gehan–Breslow–Wilcoxon tests, adjusted pairwise comparisons, and a two-arm hazard ratio, ready to export.
You need: CurveBook installed and the basics from the first curve-fit tutorial.
Seeded dataset
Clean-room synthetic preclinical survival cohort (Survival Cohort, Survival table: Time in days, event status 1 = event, 0 = right-censored; leave other arm columns blank on each subject's row):
Days | Control | Drug A | Combination |
|---|---|---|---|
12 | 1 | ||
18 | 1 | ||
22 | 1 | ||
25 | 0 | ||
28 | 1 | ||
35 | 1 | ||
24 | 1 | ||
34 | 1 | ||
42 | 0 | ||
48 | 1 | ||
56 | 1 | ||
64 | 0 | ||
40 | 0 | ||
55 | 1 | ||
68 | 0 | ||
75 | 1 | ||
84 | 0 | ||
90 | 0 |
Desktop app steps
1. Create the survival table
- On Welcome to CurveBook, click New Data Table, then Survival, then Create Table.
- Name the three Y columns
Control,Drug A, andCombination. - Type or paste the dataset above. Each subject gets one row: its time in the X column and
1(event) or0(censored) under its own arm.
You should see: the filled table, plus a linked survival graph in the Navigator under Graphs.
2. Run the Kaplan–Meier analysis
- Click Analyze on the toolbar, choose Kaplan–Meier Survival Analysis, and click OK.
- Choose Analyze › Change Analysis Parameters… (
Cmd/Ctrl+Alt+P). - On the Survival Tests tab, tick Gehan-Breslow-Wilcoxon test. With three or more arms you can also tick Log-rank test for trend.
- On the Pairwise Log-Rank tab, choose Holm–Šídák, then click OK.
You should see: a results sheet with the cohort summary (median survival per arm), the comparison of survival curves (log-rank and Gehan–Breslow–Wilcoxon), pairwise comparisons, and a number-at-risk table.
3. Tune the survival graph
The number-at-risk table is shown under a survival graph by default.
- Open the survival graph from the Navigator and click Format on the toolbar.
- On the Axes tab, select X and set Major tick interval (for example
20days). - To mark median survival, select Y, open Advanced, and add an extra tick at
0.5with a gridline and a label such as Median 50%.
You should see: the X axis re-ticked and a labelled 50% reference line across the plot.
4. Change how the curves are drawn
- With the graph showing, click Graph Type on the toolbar.
- Under Survival Y, choose % Survival or % Event. Under Curve, choose Staircase or Point-to-point. Under Error, choose None, SEM, or 95% CI.
- Click OK.
You should see: the curves redrawn in the new style. The analysis itself does not change.
5. Get a hazard ratio for two arms
A hazard ratio compares exactly two arms. To compare Control with Drug A without deleting Combination:
- In the data table, click the first
Combinationvalue, then Shift-click its last value. - Press
Cmd/Ctrl+Eto exclude those cells.
You should see: the excluded values struck through, and the results update by themselves with a Hazard ratio tab (Mantel–Haenszel and log-rank, each with a 95% CI). Press Cmd/Ctrl+E on the same cells to include them again.
CLI and MCP steps
Save the dataset above as survival-cohort.csv and run this curvebook.batch.v1 manifest (survival-workflow.json):
{
"schema": "curvebook.batch.v1",
"inputs": [
{
"path": "survival-cohort.csv",
"sheet": "data-1",
"kind": "survival"
}
],
"commands": [
{
"cmd": "stats.run",
"params": {
"sheet_id": "km-three-arm",
"source_sheet_id": "data-1",
"kind": "survival",
"multiplicity": "holm_sidak",
"title": "Kaplan-Meier (3 Arms)"
}
},
{
"cmd": "stats.run",
"params": {
"sheet_id": "km-two-arm-hr",
"source_sheet_id": "data-1",
"kind": "survival",
"selected_data_sets": [0, 1],
"title": "Kaplan-Meier (Control vs Drug A HR)"
}
},
{
"cmd": "graph.create",
"params": {
"sheet_id": "graph-km",
"data_sheet_id": "data-1",
"kind": "kaplan_meier",
"title": "Survival by Treatment Arm"
}
},
{
"cmd": "graph.setSpec",
"params": {
"sheet_id": "graph-km",
"survival_number_at_risk": true
}
},
{
"cmd": "analysis.exportCsv",
"params": {
"sheet_id": "km-three-arm",
"path": "km-three-arm.csv"
}
},
{
"cmd": "analysis.exportJson",
"params": {
"sheet_id": "km-two-arm-hr",
"path": "km-two-arm-hr.json",
"pretty": true
}
},
{
"cmd": "result.generateReport",
"params": {
"result_sheet_id": "km-three-arm",
"format": "markdown",
"path": "km-methods.md"
}
}
],
"exports": [
{ "out": "survival-study.curvebook", "format": "curvebook" },
{ "sheet": "graph-km", "out": "km-survival.svg", "format": "svg" },
{ "sheet": "graph-km", "out": "km-survival.pdf", "format": "pdf" }
]
}
Execute the workflow:
curvebook-cli batch survival-workflow.json --workdir . --json
In an MCP client, run the same steps via command_run and inspect survival medians, log-rank χ2, pairwise P values, and hazard ratios through result://km-three-arm and result://km-two-arm-hr.
Reading the results
- Median survival: Reported per arm with 95% confidence interval. When an arm's survival curve never drops to or below 50% (such as
Combinationin this cohort), median survival is reported as Undefined rather than extrapolated. - Omnibus tests: The Log-rank (Mantel–Cox) test weights all time points equally; the Gehan–Breslow–Wilcoxon test places more weight on early events.
- Pairwise tests: With three or more arms, read the Holm–Šídák multiplicity-adjusted pairwise P values before claiming differences between specific pairs.
- Hazard ratio (two arms): Check both Mantel–Haenszel and log-rank hazard ratios with their 95% confidence intervals.
- Key caveats:
- Kaplan–Meier assumes non-informative censoring (censored subjects have the same future event risk as those still under observation).
- A single hazard ratio summarizes the whole curve only when hazards are approximately proportional over time. If survival curves cross, inspect the curves and consider Cox regression with time-varying covariates.
- Greenwood standard errors become wide in the right tail when very few subjects remain at risk—always show the Number at Risk table beneath the plot.
- For full estimator formulas, CI transformations, and Cox proportional hazards regression, see Statistical analyses reference.
Exporting
Open the results sheet first, then:
- Survival tables and test statistics: File › Export › Results (CSV)… or File › Export › Results (JSON)….
- Methods text: File › Export › Methods Report… (
.md,.txt, or.tex). - Figure with the number-at-risk table: open the graph, choose File › Export › Figure…, pick PDF (Vector), SVG (Vector), or PNG (Raster), and click Export.