Development build · main @ 589f3ced80 · 2026-12-04 · May describe features that are not in a release yet Manual overviewA–Z index

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):

DaysControlDrug ACombination
121
181
221
250
281
351
241
341
420
481
561
640
400
551
680
751
840
900

Desktop app steps

1. Create the survival table

  1. On Welcome to CurveBook, click New Data Table, then Survival, then Create Table.
  2. Name the three Y columns Control, Drug A, and Combination.
  3. Type or paste the dataset above. Each subject gets one row: its time in the X column and 1 (event) or 0 (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

  1. Click Analyze on the toolbar, choose Kaplan–Meier Survival Analysis, and click OK.
  2. Choose Analyze › Change Analysis Parameters… (Cmd/Ctrl+Alt+P).
  3. On the Survival Tests tab, tick Gehan-Breslow-Wilcoxon test. With three or more arms you can also tick Log-rank test for trend.
  4. 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.

  1. Open the survival graph from the Navigator and click Format on the toolbar.
  2. On the Axes tab, select X and set Major tick interval (for example 20 days).
  3. To mark median survival, select Y, open Advanced, and add an extra tick at 0.5 with 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

  1. With the graph showing, click Graph Type on the toolbar.
  2. Under Survival Y, choose % Survival or % Event. Under Curve, choose Staircase or Point-to-point. Under Error, choose None, SEM, or 95% CI.
  3. 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:

  1. In the data table, click the first Combination value, then Shift-click its last value.
  2. Press Cmd/Ctrl+E to 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 Combination in 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.