Skip to content

Sample Size for Survival & Binary Endpoints

A trial with a time-to-event endpoint is sized in events. The information in a log-rank test or a Cox model grows with the number of deaths or progressions that the trial observes, so 500 patients with 100 events tell you less than 300 patients with 200 events. This page computes the events for a target hazard ratio, converts them to patients, and checks the plan by simulation, in R and Python. It ends with the sample size for a binary endpoint.

Sample Size & Power covers the four quantities of a power analysis for a two-sample t-test, and this page builds on it. The page needs no data file, because every number comes from the design assumptions below or from random draws with a fixed seed.

The example is a two-arm trial with overall survival as the primary endpoint and 1:1 randomization.

Assumption Value
Hazard ratio to detect, treatment against control 0.70
Significance level, two-sided 0.05
Power 0.90
Median survival in the control arm 12 months
Accrual period, at a constant rate 18 months
Follow-up after the last patient enters 12 months

Survival times are exponential in both arms, so the hazard is constant and the hazard ratio is the same at every time. Cox Proportional Hazards explains the hazard ratio, and Kaplan-Meier & Log-rank explains the test that this design plans.

Schoenfeld’s formula gives the number of events at which a log-rank test of level alpha has the target power against a hazard ratio HR.

events = (z_alpha + z_power)^2 / (p1 * p2 * log(HR)^2)

z_alpha is the normal quantile at 1 - alpha / 2 for a two-sided test, z_power is the quantile at the power, and p1 and p2 are the shares of patients in the two arms. With 1:1 randomization p1 * p2 is 1/4, and the formula starts with a factor of 4. No survival time appears in it. The median and the follow-up decide how long the events take to arrive, and they leave the number of events unchanged.

library(gsDesign)
library(rpact)
library(survival)
library(ggplot2)
dir.create("outputs", showWarnings = FALSE)
hazard_ratio <- 0.70
alpha <- 0.05
power <- 0.90
control_median <- 12
accrual <- 18
follow_up <- 12
z_alpha <- qnorm(1 - alpha / 2)
z_power <- qnorm(power)
events <- 4 * (z_alpha + z_power)^2 / log(hazard_ratio)^2
cat(sprintf("z_alpha = %.4f, z_power = %.4f\n", z_alpha, z_power))
cat(sprintf("Events at HR %.2f: %.2f, round up to %d\n", hazard_ratio,
events, ceiling(events)))
for (other_ratio in c(0.60, 0.80)) {
other_events <- 4 * (z_alpha + z_power)^2 / log(other_ratio)^2
cat(sprintf("Events at HR %.2f: %.2f\n", other_ratio, other_events))
}
z_alpha = 1.9600, z_power = 1.2816
Events at HR 0.70: 330.38, round up to 331
Events at HR 0.60: 161.07
Events at HR 0.80: 844.09

The design needs 330.38 events, so 331. The assumed hazard ratio drives that number, because the events grow with the inverse square of its logarithm: a hazard ratio of 0.60 needs 161.07 events, and a hazard ratio of 0.80 needs 844.09. A shift of 0.10 in the assumed hazard ratio cuts the events about in half or multiplies them by more than 2.5.

nEvents() in gsDesign and getSampleSizeSurvival() in rpact both default to a one-sided test at alpha = 0.025, so the code states sided = 2 and alpha = 0.05. For a symmetric normal test the two conventions give the same events. rpact also needs the survival and accrual assumptions, because it returns the patients in the same object. lifelines has two planning functions, sample_size_necessary_under_cph() and power_under_cph(), and the first one appears here.

gs_events <- nEvents(hr = hazard_ratio, alpha = alpha, beta = 1 - power,
sided = 2, ratio = 1)
gs_unequal <- nEvents(hr = hazard_ratio, alpha = alpha, beta = 1 - power,
sided = 2, ratio = 2)
schoenfeld <- getSampleSizeSurvival(
hazardRatio = hazard_ratio, alpha = alpha, sided = 2, beta = 1 - power,
median2 = control_median, accrualTime = c(0, accrual),
followUpTime = follow_up)
freedman <- getSampleSizeSurvival(
hazardRatio = hazard_ratio, alpha = alpha, sided = 2, beta = 1 - power,
median2 = control_median, accrualTime = c(0, accrual),
followUpTime = follow_up, typeOfComputation = "Freedman")
freedman_by_hand <- (z_alpha + z_power)^2 *
((1 + hazard_ratio) / (1 - hazard_ratio))^2
cat(sprintf("gsDesign nEvents, 1:1: %.2f\n", gs_events))
cat(sprintf("gsDesign nEvents, 2:1: %.2f\n", gs_unequal))
cat(sprintf("rpact, Schoenfeld: %.2f\n", schoenfeld$maxNumberOfEvents))
cat(sprintf("rpact, Freedman: %.2f\n", freedman$maxNumberOfEvents))
cat(sprintf("Freedman by hand: %.2f\n", freedman_by_hand))
gsDesign nEvents, 1:1: 330.38
gsDesign nEvents, 2:1: 371.68
rpact, Schoenfeld: 330.38
rpact, Freedman: 337.41
Freedman by hand: 337.41

gsDesign and rpact both return 330.38, the result of the hand calculation, and both name Schoenfeld’s approximation as their method. With 2:1 randomization the product p1 * p2 falls from 1/4 to 2/9, and the events rise to 371.68.

rpact offers a second formula, Freedman’s. For 1:1 randomization it replaces 4 / log(HR)^2 with ((1 + HR) / (1 - HR))^2, and it asks for 337.41 events, about 2% more than Schoenfeld’s formula. The two formulas rest on different approximations to the same log-rank test, and they move apart as the hazard ratio moves away from 1.

lifelines computes Freedman’s formula. Its alpha is two-sided, and it has no option for Schoenfeld’s formula. The function returns patients per arm, each rounded up, from the probability that a patient in each arm has an event. With both probabilities set to 1, patients are events: 169 per arm and 338 in total, which is 337.41 split between two arms and rounded up in each.

When rpact loads, it prints a reminder that its installation qualification has not been run. The reminder concerns regulated environments, and it does not change any result.

The trial ends 30 months after the first patient enters, and some patients are still alive on that day. Divide the events by the probability that a patient has an event before the analysis to get the patients. With a constant hazard, accrual at a constant rate over A months, and F months of follow-up after the last entry, that probability has a closed form.

P(event) = 1 - (exp(-hazard * F) - exp(-hazard * (A + F))) / (hazard * A)

The hazard is log(2) divided by the median, and the treatment hazard is 0.70 times the control hazard. rpact does this calculation inside getSampleSizeSurvival(). The Python tab writes the formula out, with an optional dropout hazard that a later section uses.

patients <- schoenfeld$maxNumberOfSubjects
planned <- 2 * ceiling(patients / 2)
cat(sprintf("Patients: %.2f, round up to %d (%d per arm)\n", patients,
planned, planned / 2))
cat(sprintf("Events / patients: %.4f\n", events / patients))
cat(sprintf("Patients with Freedman events: %.2f\n",
freedman$maxNumberOfSubjects))
Patients: 527.83, round up to 528 (264 per arm)
Events / patients: 0.6259
Patients with Freedman events: 539.06

A control patient has a probability of 0.6891 of an event before the analysis, and a treated patient 0.5627. The mean is 0.6259, so 330.38 events need 527.83 patients, and rpact returns the same 527.83. Round up to an even number: 528 patients, 264 per arm. About 63% of them will have had an event when the trial ends at month 30.

lifelines takes the two probabilities as p_exp and p_con and returns 270 per arm, 540 in total. That is the Freedman count, and rpact gives 539.06 patients with its Freedman option. power_under_cph() runs the same formula in the other direction. It gives the 264-per-arm plan a power of 0.8940, under 0.90 because Freedman’s formula asks for more events than Schoenfeld’s.

The events are fixed, so a longer follow-up needs fewer patients and a shorter follow-up needs more. The code repeats the calculation for every follow-up length from 3 to 36 months with the accrual period held at 18 months, prints five of them, and draws the whole curve.

curve <- data.frame(follow_up = 3:36, patients = NA)
for (i in seq_len(nrow(curve))) {
plan <- getSampleSizeSurvival(
hazardRatio = hazard_ratio, alpha = alpha, sided = 2, beta = 1 - power,
median2 = control_median, accrualTime = c(0, accrual),
followUpTime = curve$follow_up[i])
curve$patients[i] <- plan$maxNumberOfSubjects
}
shown <- curve[curve$follow_up %in% c(6, 12, 18, 24, 36), ]
cat("follow_up study_months patients rounded\n")
cat(sprintf("%9d %12d %8.1f %7d\n", shown$follow_up,
accrual + shown$follow_up, shown$patients,
2 * ceiling(shown$patients / 2)), sep = "")
follow_up_plot <- ggplot(curve, aes(follow_up, patients)) +
geom_line(color = "#1f4e5f", linewidth = 1) +
geom_point(data = shown, color = "#1f4e5f", size = 2.5) +
geom_hline(yintercept = events, linetype = "dashed", color = "#e07a5f") +
annotate("text", x = 36, y = events, hjust = 1, vjust = -0.6,
label = sprintf("%d events", ceiling(events))) +
expand_limits(y = 0) +
labs(x = "Follow-up after the last patient enters (months)",
y = "Patients required") +
theme_minimal(base_size = 12)
ggsave("outputs/survival-size-followup-r.png", follow_up_plot, width = 6,
height = 4, dpi = 150)
follow_up study_months patients rounded
6 24 658.8 660
12 30 527.8 528
18 36 459.8 460
24 42 419.4 420
36 54 376.2 378

Patients required against follow-up length from 3 to 36 months, drawn with ggplot2. The curve falls steeply at short follow-up, passes 528 patients at 12 months, and flattens toward 376 at 36 months, above a dashed line at 331 events.

With 6 months of follow-up the trial needs 660 patients and reports at month 24. With 24 months it needs 420 and reports at month 42. The saving shrinks as the follow-up grows: the six months from 6 to 12 remove 132 patients, and the twelve months from 24 to 36 remove 42. The curve stays above the dashed line at 331 events, because a trial cannot observe more events than it has patients.

The table assumes that the control median is 12 months. Many protocols remove that dependence with an event-driven analysis: the analysis takes place when the 331st event is recorded, whatever the calendar date.

Some patients withdraw or are lost before the analysis. If a proportion d of the randomized patients will contribute nothing, divide the sample size by 1 - d. The common wrong formula multiplies by 1 + d, and it leaves the trial short.

A time-to-event trial can do better than either rule. A patient who is lost at month 9 was at risk for nine months and is censored on that day, so the patient still contributes. rpact models dropout as a second exponential clock: dropoutRate1 = 0.10 with dropoutTime = 12 means that 10% of the patients in that arm would be lost by month 12 if no event came first. The Python tab gets the same number from event_probability() with a dropout hazard.

dropout <- 0.10
divided <- planned / (1 - dropout)
multiplied <- planned * (1 + dropout)
cat(sprintf("Divide by 1 - d: %.1f randomized, %.1f remain\n", divided,
divided * (1 - dropout)))
cat(sprintf("Multiply by 1 + d: %.1f randomized, %.1f remain\n",
multiplied, multiplied * (1 - dropout)))
censored <- getSampleSizeSurvival(
hazardRatio = hazard_ratio, alpha = alpha, sided = 2, beta = 1 - power,
median2 = control_median, accrualTime = c(0, accrual),
followUpTime = follow_up, dropoutRate1 = dropout, dropoutRate2 = dropout,
dropoutTime = 12)
cat(sprintf("rpact, dropout as censoring: %.2f patients for %.2f events\n",
censored$maxNumberOfSubjects, censored$maxNumberOfEvents))
Divide by 1 - d: 586.7 randomized, 528.0 remain
Multiply by 1 + d: 580.8 randomized, 522.7 remain
rpact, dropout as censoring: 569.61 patients for 330.38 events

Dividing 528 by 0.90 gives 586.7 patients to randomize, and 528.0 of them remain after a 10% loss. Round up to 588 for two equal arms. Multiplying by 1.10 gives 580.8, and a 10% loss leaves 522.7, about five patients short of the plan.

With dropout as censoring, rpact asks for 569.61 patients, and the hand formula in Python agrees. That is 570 patients against 588, because each lost patient counts for the months of follow-up before the loss. The events stay at 330.38. Dropout changes how many patients it takes to observe them. Use the division by 1 - d when you cannot defend an assumption about when patients leave.

The formulas rest on a normal approximation, and a simulation tests the plan without it. The code below runs 2000 trials of 264 patients per arm with no dropout. Each trial draws an entry time over 18 months and an exponential survival time for every patient, censors the patients who are alive at month 30, and runs a two-sided log-rank test at the 5% level.

#' Simulate one two-arm exponential trial and run the log-rank test.
#'
#' @param n_per_arm Patients in each arm.
#' @param control_hazard Event hazard per month in the control arm.
#' @param hazard_ratio Treatment hazard divided by the control hazard.
#' @param accrual Length of the accrual period in months.
#' @param follow_up Months of follow-up after the last patient enters.
#' @return A named vector with the log-rank p-value and the event count.
SimulateTrial <- function(n_per_arm, control_hazard, hazard_ratio, accrual,
follow_up) {
arm <- rep(c(0, 1), each = n_per_arm)
entry <- runif(2 * n_per_arm, min = 0, max = accrual)
event_time <- rexp(2 * n_per_arm, rate = control_hazard * hazard_ratio^arm)
censor_time <- accrual + follow_up - entry
time <- pmin(event_time, censor_time)
status <- as.integer(event_time <= censor_time)
test <- survdiff(Surv(time, status) ~ arm)
c(p_value = test$pvalue, events = sum(status))
}
set.seed(2026)
n_simulations <- 2000
p_values <- numeric(n_simulations)
event_counts <- numeric(n_simulations)
for (i in seq_len(n_simulations)) {
trial <- SimulateTrial(planned / 2, log(2) / control_median, hazard_ratio,
accrual, follow_up)
p_values[i] <- trial["p_value"]
event_counts[i] <- trial["events"]
}
simulated_power <- mean(p_values < alpha)
standard_error <- sqrt(simulated_power * (1 - simulated_power) /
n_simulations)
cat(sprintf("Rejected in %d of %d trials\n", sum(p_values < alpha),
n_simulations))
cat(sprintf("Simulated power: %.3f (Monte Carlo SE %.3f)\n",
simulated_power, standard_error))
cat(sprintf("Mean events per trial: %.1f\n", mean(event_counts)))
Rejected in 1772 of 2000 trials
Simulated power: 0.886 (Monte Carlo SE 0.007)
Mean events per trial: 330.3

R rejects in 1772 of 2000 trials, a simulated power of 0.886, and Python in 1797, a power of 0.898. The two languages use different random number generators, so the same seed gives different trials. Each estimate has a Monte Carlo standard error of 0.007. The Python value is within one standard error of the 0.90 target, and the R value is two standard errors below it. A simulation of this length can show that the plan is close to 90% power, and it cannot separate 0.89 from 0.90.

The mean number of events is 330.3 in R and 330.7 in Python, next to the 330.38 that the plan expects. The simulation therefore supports both steps: the event probability that converts events to patients, and the events formula.

The same loop handles a design that the formulas do not cover, such as a treatment effect that starts after a delay or dropout that differs between the arms. Change the lines that draw the times.

A binary endpoint counts patients, so the sample size is a number of patients per arm. Suppose the endpoint is a disease flare within 24 weeks, expected in 20% of the control arm and 10% of the treatment arm, tested two-sided at 5% with 90% power.

power.prop.test() in R and the usual statsmodels recipe give different answers, because they use different normal approximations. power.prop.test() works on the difference of the two proportions. It takes the variance under the null from the pooled proportion and the variance under the alternative from the two separate proportions. The statsmodels recipe passes Cohen’s h from proportion_effectsize() to NormalIndPower. Cohen’s h is the difference of the two proportions after the transformation 2 * asin(sqrt(p)), which has a variance of 1 / n whatever the proportion. Each tab computes both.

control_rate <- 0.20
treated_rate <- 0.10
pooled <- power.prop.test(p1 = control_rate, p2 = treated_rate,
sig.level = alpha, power = power)
cohen_h <- 2 * asin(sqrt(control_rate)) - 2 * asin(sqrt(treated_rate))
arcsine_n <- 2 * (z_alpha + z_power)^2 / cohen_h^2
cat(sprintf("power.prop.test: %.2f, round up to %d per arm\n",
pooled$n, ceiling(pooled$n)))
cat(sprintf("Cohen's h = %.4f\n", cohen_h))
cat(sprintf("Arcsine formula by hand: %.2f, round up to %d per arm\n",
arcsine_n, ceiling(arcsine_n)))
power.prop.test: 265.86, round up to 266 per arm
Cohen's h = 0.2838
Arcsine formula by hand: 260.93, round up to 261 per arm

The approximation on the difference scale needs 265.86, so 266 patients per arm and 532 in total. The arcsine approximation needs 260.93, so 261 per arm. The cause of the gap is the approximation, and each language can produce both numbers: samplesize_proportions_2indep_onetail() in statsmodels reproduces power.prop.test(), and the hand formula in R reproduces NormalIndPower.

State in the protocol which function gave the number. The pooled-variance calculation matches the test that most trials then run, the z-test for two proportions, which is the chi-square test without continuity correction. No follow-up length enters this calculation, because every patient is assessed at week 24. A patient who leaves before week 24 has no observed endpoint, so the division by 1 - d from the dropout section is the right inflation here.

Do not power the trial for the hazard ratio that a small earlier study observed. An estimate from a few dozen events is imprecise, and the studies that lead to a larger trial are the ones whose estimates came out large. A design powered for 0.60 plans 162 events. If the true hazard ratio is 0.70 the trial needed 331, and if it is 0.80 the trial needed 845. Power the trial for the smallest effect that would change practice.

Do not count patients when the design needs events. The 528 patients are a means of observing 331 events by month 30. If the control arm lives longer than a 12-month median, or accrual is slower than planned, the same 528 patients produce fewer events by that date, and the power falls although enrollment is complete. Monitor the number of events, pooled over the two arms.

Do not reuse this sample size for a design with interim analyses. The 331 events belong to one analysis at a two-sided 5% level. A trial that tests the data several times uses stricter thresholds, and its maximum number of events is larger. Interim Analyses & Group Sequential Designs computes that inflation.

Schoenfeld, 1981 derives the asymptotic distribution of the log-rank statistic under proportional hazards, which gives the events formula of this page.

Freedman, 1982 gives the other events formula for the log-rank test, the one that lifelines computes, with tables of the patients required.

The gsDesign package by Anderson computes group sequential boundaries, spending functions, and sample sizes for clinical trials in R.

The rpact package by Wassmer and Pahlke designs and analyzes fixed, group sequential, and adaptive confirmatory trials in R.

The survival package by Therneau supplies the Kaplan-Meier, Cox, and parametric survival models in R.

Davidson-Pilon, 2019 describes lifelines, the Python library for survival analysis.

The gsDesign time-to-event sample size reference documents nEvents() and the functions that convert between a hazard ratio, a z-value, and a number of events. Use it to find the hazard ratio that a given number of events can detect.

The rpact getSampleSizeSurvival reference lists the arguments for piecewise accrual, piecewise exponential survival, and unequal allocation, which this page leaves at their defaults.

The lifelines statistics reference documents sample_size_necessary_under_cph(), power_under_cph(), and the log-rank test that the simulation uses.

The R power.prop.test reference and the statsmodels sample size reference for two proportions define the arguments of the two binary calculations, including unequal group sizes in statsmodels.

Sample Size & Power covers the t-test version of this calculation and the choice of an effect size. Kaplan-Meier & Log-rank and Cox Proportional Hazards analyze the data that this design collects.