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.
What runs in CodeSplash
- Power analysis — survival (log-rank / Cox) Verified in Python and R
- Kaplan–Meier survival curves Verified in Python and R
- Log-rank test (compare survival curves) Verified in Python and R
- Cox proportional hazards regression Verified in Python and R
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
Events are the currency
ReadIn a survival study, power depends on the number of events, not the number of people. Schoenfeld's formula for comparing two groups:
is events, the share in one arm. Notice what isn't there: patients, follow-up, baseline risk. Those only decide how long it takes to collect events.
Predict the size
PredictPredict 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.
Work it out
In the appThe power method can solve for sample size, power or the smallest detectable hazard ratio.
N = 494, events = 247, HR = 0.70, α = 0.05, 1 − β = 0.800
- Participants
- 494
- Events
- 247
- Power
- 0.8003
- Hazard ratio
- 0.7000
Plots
View data
| Power | Hazard ratio | Total sample size |
|---|---|---|
| 0.0339 | HR = 0.77 | 2 |
| 0.0781 | HR = 0.77 | 32.825 |
| 0.1140 | HR = 0.77 | 63.650 |
| 0.1490 | HR = 0.77 | 94.475 |
| 0.1837 | HR = 0.77 | 125.30 |
| 0.2182 | HR = 0.77 | 156.13 |
| 0.2524 | HR = 0.77 | 186.95 |
| 0.2863 | HR = 0.77 | 217.78 |
| 0.3196 | HR = 0.77 | 248.60 |
| 0.3523 | HR = 0.77 | 279.43 |
| 0.3843 | HR = 0.77 | 310.25 |
| 0.4156 | HR = 0.77 | 341.07 |
| 0.4459 | HR = 0.77 | 371.90 |
| 0.4753 | HR = 0.77 | 402.73 |
| 0.5037 | HR = 0.77 | 433.55 |
| 0.5311 | HR = 0.77 | 464.38 |
| 0.5575 | HR = 0.77 | 495.20 |
| 0.5829 | HR = 0.77 | 526.02 |
| 0.6071 | HR = 0.77 | 556.85 |
| 0.6304 | HR = 0.77 | 587.67 |
| 0.6525 | HR = 0.77 | 618.50 |
| 0.6737 | HR = 0.77 | 649.33 |
| 0.6938 | HR = 0.77 | 680.15 |
| 0.7129 | HR = 0.77 | 710.98 |
| 0.7310 | HR = 0.77 | 741.80 |
| 0.7482 | HR = 0.77 | 772.63 |
| 0.7645 | HR = 0.77 | 803.45 |
| 0.7799 | HR = 0.77 | 834.27 |
| 0.7944 | HR = 0.77 | 865.10 |
| 0.8081 | HR = 0.77 | 895.92 |
| 0.8210 | HR = 0.77 | 926.75 |
| 0.8332 | HR = 0.77 | 957.58 |
| 0.8446 | HR = 0.77 | 988.40 |
| 0.8553 | HR = 0.77 | 1019.23 |
| 0.8654 | HR = 0.77 | 1050.05 |
| 0.8748 | HR = 0.77 | 1080.88 |
| 0.8837 | HR = 0.77 | 1111.70 |
| 0.8919 | HR = 0.77 | 1142.53 |
| 0.8997 | HR = 0.77 | 1173.35 |
| 0.9069 | HR = 0.77 | 1204.17 |
| 0.9137 | HR = 0.77 | 1,235 |
| 0.0374 | HR = 0.70 | 2 |
| 0.1080 | HR = 0.70 | 32.825 |
| 0.1701 | HR = 0.70 | 63.650 |
| 0.2314 | HR = 0.70 | 94.475 |
| 0.2917 | HR = 0.70 | 125.30 |
| 0.3504 | HR = 0.70 | 156.13 |
| 0.4068 | HR = 0.70 | 186.95 |
| 0.4606 | HR = 0.70 | 217.78 |
| 0.5113 | HR = 0.70 | 248.60 |
| 0.5588 | HR = 0.70 | 279.43 |
| 0.6030 | HR = 0.70 | 310.25 |
| 0.6439 | HR = 0.70 | 341.07 |
| 0.6815 | HR = 0.70 | 371.90 |
| 0.7159 | HR = 0.70 | 402.73 |
| 0.7472 | HR = 0.70 | 433.55 |
| 0.7756 | HR = 0.70 | 464.38 |
| 0.8013 | HR = 0.70 | 495.20 |
| 0.8244 | HR = 0.70 | 526.02 |
| 0.8451 | HR = 0.70 | 556.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
)
))
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.
Why long follow-up can rescue a small trial
ReadMore 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.
What a complete report shows
CheckpointCheck yourself
Put these parts of a survival report in the order a reader needs them.
Show the answer
The order:
- Who was followed, for how long, and how many events and censored subjects there were
- Kaplan–Meier or cumulative incidence curves with numbers at risk
- Medians or survival at fixed times, with intervals
- Hazard ratios with intervals and the adjustment set
- 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
. Small effects are expensive.
Write the sentence
ReflectHere'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.
Recap
Recap- Events set the power; people and time are how you collect them.
- Small effects cost many more events, because is squared.
- Report who was followed, curves with numbers at risk, summaries, effects with intervals, and your assumption checks.
Concepts in this lesson