Skip to content

Planning and reporting a survival study

Power in survival studies comes from events, not people. Plan the number of events you need, then report curves, numbers at risk, effects and checks.

Applied ~11 min7 steps

What runs in CodeSplash

You will be able to

  • Estimate the events and participants a survival comparison needs
  • Explain why follow-up length changes the sample size
  • List what a complete survival report contains

Read first

01

Events are the currency

Read

In a survival study, power depends on the number of events, not the number of people. Schoenfeld's formula for comparing two groups:

D=(z1−α/2+z1−β)2p(1−p) (log⁡HR)2D = \frac{(z_{1-\alpha/2} + z_{1-\beta})^2}{p(1-p)\,(\log \text{HR})^2}

DD is events, pp the share in one arm. Notice what isn't there: patients, follow-up, baseline risk. Those only decide how long it takes to collect DD events.

02

Predict the size

Predict

Predict first

You want 80% power at the 5% level to detect a hazard ratio of 0.7, with equal arms.

How many events do you need? Drag to your guess.

Make your guess between 20 and 1000 events, then reveal.

Reveal

CodeSplash gives 247 events. If you expect half the patients to have the event during the study, that means 494 people. If only a quarter do, you need twice as many people for the same events.

03

Work it out

In the app

The power method can solve for sample size, power or the smallest detectable hazard ratio.

Power analysis: survival (log-rank / Cox)Recorded · Python and R agreeRecorded 2026-11-09 · 10 values compared
R

N = 494, events = 247, HR = 0.70, α = 0.05, 1 − β = 0.800

Participants
494
Events
247
Power
0.8003
Hazard ratio
0.7000

Plots

Power by total sample sizeHow does power grow with sample size (or effect size), and where does it reach the target?
View data
PowerHazard ratioTotal sample size
0.0339HR = 0.772
0.0781HR = 0.7732.825
0.1140HR = 0.7763.650
0.1490HR = 0.7794.475
0.1837HR = 0.77125.30
0.2182HR = 0.77156.13
0.2524HR = 0.77186.95
0.2863HR = 0.77217.78
0.3196HR = 0.77248.60
0.3523HR = 0.77279.43
0.3843HR = 0.77310.25
0.4156HR = 0.77341.07
0.4459HR = 0.77371.90
0.4753HR = 0.77402.73
0.5037HR = 0.77433.55
0.5311HR = 0.77464.38
0.5575HR = 0.77495.20
0.5829HR = 0.77526.02
0.6071HR = 0.77556.85
0.6304HR = 0.77587.67
0.6525HR = 0.77618.50
0.6737HR = 0.77649.33
0.6938HR = 0.77680.15
0.7129HR = 0.77710.98
0.7310HR = 0.77741.80
0.7482HR = 0.77772.63
0.7645HR = 0.77803.45
0.7799HR = 0.77834.27
0.7944HR = 0.77865.10
0.8081HR = 0.77895.92
0.8210HR = 0.77926.75
0.8332HR = 0.77957.58
0.8446HR = 0.77988.40
0.8553HR = 0.771019.23
0.8654HR = 0.771050.05
0.8748HR = 0.771080.88
0.8837HR = 0.771111.70
0.8919HR = 0.771142.53
0.8997HR = 0.771173.35
0.9069HR = 0.771204.17
0.9137HR = 0.771,235
0.0374HR = 0.702
0.1080HR = 0.7032.825
0.1701HR = 0.7063.650
0.2314HR = 0.7094.475
0.2917HR = 0.70125.30
0.3504HR = 0.70156.13
0.4068HR = 0.70186.95
0.4606HR = 0.70217.78
0.5113HR = 0.70248.60
0.5588HR = 0.70279.43
0.6030HR = 0.70310.25
0.6439HR = 0.70341.07
0.6815HR = 0.70371.90
0.7159HR = 0.70402.73
0.7472HR = 0.70433.55
0.7756HR = 0.70464.38
0.8013HR = 0.70495.20
0.8244HR = 0.70526.02
0.8451HR = 0.70556.85

First 60 of 123 rows.

  • Schoenfeld (1983): events depend only on the hazard ratio, allocation and error rates; participants = events / P(event).
  • Power uses the one-tail normal approximation of the formula it inverts (the far tail is negligible).
The exact R script · R R version 4.5.1 (2025-06-13)
# Power analysis — survival (log-rank / Cox)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method power.survival 1.0.0 · spec f7f210f564cc83ed
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr) # Schoenfeld's formula (twin of codesplash.stats.power)

# %% Inputs
solve_for <- "n" # n | power | effect
hr <- 0.7
alloc <- 0.5 # proportion in group 1
p_event <- 0.5 # probability of an event during follow-up
n_given <- 200
target <- 0.8
alpha <- 0.05
alternative <- "two-sided"
warnings <- list()

# %% Solve (closed form)
n_exact <- NA
events_exact <- NA
target_power <- NA
if (solve_for %in% c("n", "power") && abs(log(hr)) < 1e-12) stop("A hazard ratio of 1 means no difference to detect.")
if (solve_for == "n") {
  target_power <- target
  events_exact <- cs_power_schoenfeld_events(hr, alloc, alpha, target, alternative)
  events <- cs_power_ceil(events_exact)
  n_exact <- events_exact / p_event
  n <- cs_power_ceil(n_exact)
  power <- cs_power_schoenfeld_power(hr, n * p_event, alloc, alpha, alternative)
} else if (solve_for == "power") {
  n <- n_given
  events <- n * p_event # expected events
  power <- cs_power_schoenfeld_power(hr, events, alloc, alpha, alternative)
} else {
  target_power <- target
  n <- n_given
  events <- n * p_event
  hr <- cs_power_schoenfeld_hr(events, alloc, alpha, target, alternative)
  power <- cs_power_schoenfeld_power(hr, events, alloc, alpha, alternative)
}

# %% Curves
n_ref <- if (is.finite(n)) n else 200
xs <- cs_power_grid(2, max(2.5 * n_ref, 12))
hrs <- hr^c(0.75, 1, 1.25) # nearer to / farther from 1 on the log scale
curve <- do.call(rbind, lapply(hrs, function(h) {
  data.frame(x = xs, power = cs_power_schoenfeld_power(h, xs * p_event, alloc, alpha, alternative), series = sprintf("HR = %.2f", h))
}))

# %% Result
cs_publish(list(
  method = "power.survival",
  methodVersion = "1.0.0",
  title = "Power analysis: survival (log-rank / Cox)",
  engine = cs_engine_info("stats"),
  summary = sprintf("Log-rank / Cox comparison: N = %s, events = %.1f, HR = %.3f, power = %.3f at %s alpha = %s.", format(n, big.mark = ","), events, hr, power, alternative, format(alpha)),
  apa = sprintf("N = %s, events = %.0f, HR = %s, α = %s, 1 − β = %.3f", format(n, big.mark = ","), events, cs_fmt_num(hr), format(alpha), power),
  statistics = list(
    list(key = "n", label = "Participants", value = n, format = "integer"),
    list(key = "events", label = "Events", value = events),
    list(key = "power", label = "Power", value = power),
    list(key = "hr", label = "Hazard ratio", value = hr)
  ),
  warnings = warnings,
  notes = c("Schoenfeld (1983): events depend only on the hazard ratio, allocation and error rates; participants = events / P(event).",
            "Power uses the one-tail normal approximation of the formula it inverts (the far tail is negligible)."),
  charts = list(cs_chart(
    "power", "power-curve", "Power by total sample size",
    list(x = cs_col("Total sample size", curve$x), power = cs_col("Power", curve$power), series = cs_col("Hazard ratio", curve$series)),
    controls = list(target = if (is.na(target_power)) 0.8 else target)
  )),
  values = list(
    n = n, n_exact = n_exact, events = events, events_exact = events_exact, power = power,
    target_power = target_power, hr = hr, alloc = alloc, p_event = p_event, alpha = alpha
  )
))
Python

N = 494, events = 247, HR = 0.70, α = 0.05, 1 − β = 0.800

Participants
494
Events
247
Power
0.8003
Hazard ratio
0.7000

To keep this page light, the plots are shown once, under the R tab.

  • Schoenfeld (1983): events depend only on the hazard ratio, allocation and error rates; participants = events / P(event).
  • Power uses the one-tail normal approximation of the formula it inverts (the far tail is negligible).
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Power analysis — survival (log-rank / Cox)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method power.survival 1.0.0 · spec f7f210f564cc83ed
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
import math

import codesplash as cs
from codesplash.stats import power as pw  # Schoenfeld's formula (twin of R cs_power_schoenfeld_*)

# %% Inputs
solve_for = "n"  # n | power | effect
hr = 0.7
alloc = 0.5  # proportion in group 1
p_event = 0.5  # probability of an event during follow-up
n_given = 200
target = 0.8
alpha = 0.05
alternative = "two-sided"
warnings = []

# %% Solve (closed form)
n_exact = None
events_exact = None
target_power = None
if solve_for in ("n", "power") and abs(math.log(hr)) < 1e-12:
    raise ValueError("A hazard ratio of 1 means no difference to detect.")
if solve_for == "n":
    target_power = target
    events_exact = pw.schoenfeld_events(hr, alloc, alpha, target, alternative)
    events = pw.ceil_n(events_exact)
    n_exact = events_exact / p_event
    n = pw.ceil_n(n_exact)
    power = pw.schoenfeld_power(hr, n * p_event, alloc, alpha, alternative)
elif solve_for == "power":
    n = n_given
    events = n * p_event  # expected events
    power = pw.schoenfeld_power(hr, events, alloc, alpha, alternative)
else:
    target_power = target
    n = n_given
    events = n * p_event
    hr = pw.schoenfeld_hr(events, alloc, alpha, target, alternative)
    power = pw.schoenfeld_power(hr, events, alloc, alpha, alternative)

# %% Curves
n_ref = n if math.isfinite(n) else 200.0
xs = pw.grid(2.0, max(2.5 * n_ref, 12.0))
hrs = [hr ** s for s in (0.75, 1.0, 1.25)]  # nearer to / farther from 1 on the log scale
curve = [(float(x), pw.schoenfeld_power(h, float(x) * p_event, alloc, alpha, alternative), f"HR = {h:.2f}") for h in hrs for x in xs]

# %% Result
cs.publish({
    "method": "power.survival",
    "methodVersion": "1.0.0",
    "title": "Power analysis: survival (log-rank / Cox)",
    "engine": cs.engine_info("scipy"),
    "summary": f"Log-rank / Cox comparison: N = {n:,.0f}, events = {events:,.1f}, HR = {hr:.3f}, power = {power:.3f} at {alternative} α = {alpha}.",
    "apa": f"N = {n:,.0f}, events = {events:,.0f}, HR = {cs.fmt_num(hr)}, α = {alpha}, 1 − β = {power:.3f}",
    "statistics": [
        {"key": "n", "label": "Participants", "value": n, "format": "integer"},
        {"key": "events", "label": "Events", "value": events},
        {"key": "power", "label": "Power", "value": power},
        {"key": "hr", "label": "Hazard ratio", "value": hr},
    ],
    "warnings": warnings,
    "notes": [
        "Schoenfeld (1983): events depend only on the hazard ratio, allocation and error rates; participants = events / P(event).",
        "Power uses the one-tail normal approximation of the formula it inverts (the far tail is negligible).",
    ],
    "charts": [cs.chart(
        "power", "power-curve", "Power by total sample size",
        {"x": cs.col("Total sample size", [c[0] for c in curve]), "power": cs.col("Power", [c[1] for c in curve]),
         "series": cs.col("Hazard ratio", [c[2] for c in curve])},
        controls={"target": target if target_power is not None else 0.8},
    )],
    "values": {
        "n": n, "n_exact": n_exact, "events": events, "events_exact": events_exact, "power": power,
        "target_power": target_power, "hr": hr, "alloc": alloc, "p_event": p_event, "alpha": alpha,
    },
})

Now reverse the question. With 500 patients and a 0.3 event probability, you collect 150 events, and at 90% power the smallest detectable hazard ratio is 0.62. If only a larger effect would be plausible, the study can't answer your question. Look at the interval you would expect to get, not only at power.

04

Why long follow-up can rescue a small trial

Read

More follow-up means more events, so sometimes it substitutes for more people. It has limits: the extra events come late, when treatment effects may have changed, and you must assume that hazards stay proportional for the formula to hold.

Plan losses too. If 10% will drop out, those people don't contribute their later events.

05

What a complete report shows

Checkpoint

Check yourself

Put these parts of a survival report in the order a reader needs them.

  1. 1Who was followed, for how long, and how many events and censored subjects there were
  2. 2The proportional-hazards check and what you did about it
  3. 3Medians or survival at fixed times, with intervals
  4. 4Hazard ratios with intervals and the adjustment set
  5. 5Kaplan–Meier or cumulative incidence curves with numbers at risk

Show the answer

The order:

  1. Who was followed, for how long, and how many events and censored subjects there were
  2. Kaplan–Meier or cumulative incidence curves with numbers at risk
  3. Medians or survival at fixed times, with intervals
  4. Hazard ratios with intervals and the adjustment set
  5. The proportional-hazards check and what you did about it

Readers first need to know what was observed, then how it looks, then the summaries and effects, then whether the assumptions hold.

Check yourself

Two designs have equal power for the same hazard ratio. Design A: 300 patients, 50% events. Design B: 600 patients, 25% events. What explains it?

Show the answer

Answer: a

Both give 150 events. That's the quantity in Schoenfeld's formula.

Check yourself

Moving the planned hazard ratio from 0.7 to 0.8 does what to the events you need?

Show the answer

Answer: c

(log⁡0.7)2/(log⁡0.8)2≈2.6(\log 0.7)^2 / (\log 0.8)^2 \approx 2.6. Small effects are expensive.

06

Write the sentence

Reflect

Here's the kind of sentence to aim for, using the lung data.

"Of 228 patients, 165 died during follow-up. In a Cox model adjusted for sex, each additional year of age was associated with a hazard ratio of 1.017 (95% CI 0.999 to 1.036). A global test showed no clear departure from proportional hazards (p = .250)."

What in that sentence would you change for your readers? Compare it with the APA sentence on the card, which you can copy to a report.

07

Recap

Recap
  • Events set the power; people and time are how you collect them.
  • Small effects cost many more events, because log⁡HR\log \text{HR} is squared.
  • Report who was followed, curves with numbers at risk, summaries, effects with intervals, and your assumption checks.

Concepts in this lesson