Your data
Rows with a missing value in a column you use are left out and counted.
Result
Groups
| Group | Subjects | Events | Censored | Median | CI for median | Restricted mean | Observed / expected |
|---|
Cox proportional hazards model
| Term | Coefficient | Std error | Hazard ratio | CI | p | PH check p |
|---|
Method and citation
Kaplan-Meier (Kaplan & Meier 1958): at each time ti with di events among ni still at risk, the curve is multiplied by 1 - d_i / n_i. Subjects censored at ti are still counted at risk at ti. The standard error is Greenwood's (1926), S(t) * sqrt(sum d_i / (n_i (n_i - d_i))), and the band is built on the log(−log S) scale so it stays between 0 and 1. The median is the first time the curve is at or below 0.5; its interval is where the band crosses 0.5. The restricted mean is the area under the curve up to the horizon: the average event-free time within it.
Log-rank test (Mantel 1966): at every event time, each group's expected events are its share of those at risk times the events; the statistic compares observed with expected, summed over times, using the hypergeometric covariance, on (groups − 1) degrees of freedom. Gehan-Breslow weights each time by the number at risk, Tarone-Ware by its square root.
Cox regression (Cox 1972): the hazard is h0(t) * exp(b1 x1 + ... + bp xp) with the baseline h0 left unspecified, fitted by maximising the partial likelihood with Newton-Raphson. Tied event times use Efron's (1977) approximation or Breslow's. A group column becomes one 0/1 term per group against the reference; text covariates likewise against their first value. A stratified model (strata column) gives each stratum its own baseline hazard h0s(t) and shares the coefficients: risk sets never cross strata, and the strata's partial likelihoods multiply. The test of equal curves is stratified the same way, summing each stratum's observed-minus-expected and its variance (Kalbfleisch & Prentice, The Statistical Analysis of Failure Time Data, 2nd ed., Wiley 2002). Reported: coefficients, standard errors from the inverse information, Wald intervals for the hazard ratios, likelihood-ratio, Wald and score tests, Harrell's concordance (Harrell et al. 1982) and, per term, the Grambsch & Therneau (1994) test of scaled Schoenfeld residuals against 1 − KM(t).
Verified by tests in the source against independent implementations: every curve value and band, median and interval, restricted mean, log-rank statistic, Cox coefficient, standard error, log-likelihood, likelihood-ratio test, concordance and proportional-hazards statistic on the example and on three seeded data sets with heavy ties, three groups and a text covariate, against lifelines 0.30.3 and statsmodels 0.15.0 (Cox coefficients agree with statsmodels to 1e-8); the weighted tests against statsmodels' survdiff; and pinned values for the example (log-rank 16.79; Efron hazard ratio 4.82; likelihood-ratio 16.35, Wald 14.53, score 17.25).
BibTeX
@article{kaplan1958nonparametric,
author = {Kaplan, E. L. and Meier, Paul},
title = {Nonparametric Estimation from Incomplete Observations},
journal = {Journal of the American Statistical Association},
volume = {53}, number = {282}, pages = {457--481}, year = {1958},
doi = {10.1080/01621459.1958.10501452}
}
@article{mantel1966evaluation,
author = {Mantel, Nathan},
title = {Evaluation of Survival Data and Two New Rank Order Statistics Arising in Its Consideration},
journal = {Cancer Chemotherapy Reports},
volume = {50}, number = {3}, pages = {163--170}, year = {1966}
}
@article{cox1972regression,
author = {Cox, D. R.},
title = {Regression Models and Life-Tables},
journal = {Journal of the Royal Statistical Society, Series B},
volume = {34}, number = {2}, pages = {187--220}, year = {1972},
doi = {10.1111/j.2517-6161.1972.tb00899.x}
}
@article{efron1977efficiency,
author = {Efron, Bradley},
title = {The Efficiency of Cox's Likelihood Function for Censored Data},
journal = {Journal of the American Statistical Association},
volume = {72}, number = {359}, pages = {557--565}, year = {1977},
doi = {10.1080/01621459.1977.10480613}
}
@article{grambsch1994proportional,
author = {Grambsch, Patricia M. and Therneau, Terry M.},
title = {Proportional Hazards Tests and Diagnostics Based on Weighted Residuals},
journal = {Biometrika},
volume = {81}, number = {3}, pages = {515--526}, year = {1994},
doi = {10.1093/biomet/81.3.515}
}
@article{harrell1982evaluating,
author = {Harrell, Frank E., Jr. and Califf, Robert M. and Pryor, David B. and Lee, Kerry L. and Rosati, Robert A.},
title = {Evaluating the Yield of Medical Tests},
journal = {JAMA},
volume = {247}, number = {18}, pages = {2543--2546}, year = {1982},
doi = {10.1001/jama.1982.03320430047030}
}
@article{freireich1963effect,
author = {Freireich, Emil J. and others},
title = {The Effect of 6-Mercaptopurine on the Duration of Steroid-Induced Remissions in Acute Leukemia},
journal = {Blood},
volume = {21}, number = {6}, pages = {699--716}, year = {1963}
}
This is an independent implementation from the papers' mathematics; no code from the authors or from other libraries was copied. lifelines and statsmodels were used only to produce the reference numbers the tests check against.
Example data
"Load example" uses the remission data of Freireich et al. (1963), Blood 21(6): 42 children with acute leukaemia in remission, given 6-mercaptopurine (6-MP) or placebo, with the weeks until relapse or until follow-up ended (relapsed = 0 means still in remission, censored). The sex and logWBC (log white blood cell count) columns come from the version in Kleinbaum & Klein's textbook Survival Analysis: A Self-Learning Text, as redistributed in the MIT-licensed lifelines package. It is bundled with this page, so loading it makes no network request.
Limits
- Independent censoring. Every method here assumes that a subject who is censored had the same outlook as those still watched. If people leave follow-up because they are about to have the event (or because they are doing well), the curves are biased and nothing in the data can show it.
- Proportional hazards. A Cox hazard ratio is one number for the whole follow-up. When the check flags a term, the effect changes over time; report curves or split time instead of leaning on that ratio.
- Small samples. Bands, tests and Wald intervals are large-sample approximations. With few events per Cox term (under about 10) estimates are unstable, and when a term perfectly separates who fails first the coefficient is infinite: the tool warns rather than printing a number you should trust.
- Concordance is in-sample. It is measured on the rows the model was fitted on, so it flatters the model.
- Right censoring only. Every subject starts at time 0 and is followed until the event or censoring.
- Not modelled: late entry (left truncation), time-varying covariates, competing risks, frailty or clustering, interval censoring, weights, and parametric (Weibull, log-normal) models.
Questions
What does a Kaplan-Meier curve show?
The share of subjects who have not yet had the event (died, relapsed, churned, failed) at each time, estimated so that subjects who left the study early still count for as long as they were watched. Those subjects are called censored: you know they lasted at least that long, not how long in total.
What does my CSV need?
One row per subject, a header row, a column with the time from that subject's start to the event or to the end of follow-up, and a column saying whether the event happened (1/0, true/false, yes/no or event/censored). Add a group column to compare curves, and numeric or text columns as Cox covariates.
What is the difference between the log-rank test and Cox regression?
The log-rank test asks whether the groups' curves differ at all. Cox regression estimates by how much: a hazard ratio of 2 means the event rate in that group is twice the reference group's at every time, and it can adjust for other covariates at the same time.
Why does the median say not reached?
Fewer than half of that group had the event by the last time anyone was observed, so the curve never drops to 50% and the median cannot be estimated from these data. The same applies to the upper end of a confidence interval.
What is the proportional-hazards check?
A Cox model assumes each hazard ratio is constant over time. The check (Grambsch and Therneau 1994) tests whether each term's scaled Schoenfeld residuals trend against time. A small p-value means the effect seems to grow or fade, so the single hazard ratio is an average over a changing effect.
When should I stratify instead of adding a covariate?
Stratify by a variable whose effect fails the proportional-hazards check, or that you need to adjust for but not estimate, such as study site. Each stratum gets its own baseline hazard, the other hazard ratios are shared across strata, and the test of equal curves compares groups only within each stratum. The price: the stratifying variable gets no hazard ratio of its own.
Which test should I pick: log-rank, Gehan-Breslow or Tarone-Ware?
Decide before you look at the data. The log-rank test weights every event time equally and is most powerful when hazards are proportional. Gehan-Breslow weights early times, where more subjects are at risk, and Tarone-Ware sits between the two.
Is my data uploaded anywhere?
No. The CSV is read and analysed by JavaScript in this browser tab. There are no accounts, cookies or analytics vendors.