Survival Analysis Fundamentals
This page covers the statistical theory behind the Kaplan-Meier and Cox Regression tabs. See those pages for usage instructions.
Time-to-Event Data and Censoring
Survival analysis is a set of methods for analyzing time until an event occurs. Despite the name "survival," the event need not be death — it can be machine failure, customer churn, time to recidivism, or any event of interest.
The defining feature of survival data is censoring. Subjects who did not experience the event during the observation period (e.g., patients still alive at the end of a clinical trial, or patients lost to follow-up) carry only incomplete information: "the event had not occurred by at least this time."
Simply excluding censored observations biases the analysis toward subjects who experienced the event sooner, underestimating survival times. Treating censored observations as "no event" overstates survival times since the true event time is unknown.
The consistency of survival analysis estimators assumes that the censoring time is independent of the event time (independent censoring)1. Here independence means independence within each group for a Kaplan-Meier (KM) estimator computed by group, and independence conditional on the covariates for the Cox model. The consistency of the Cox model estimators also requires the proportional hazards model to be correct. When censoring is related to the probability of the event — for example, when patients drop out due to worsening side effects — this assumption breaks down, consistency is lost, and the estimates carry a bias that does not vanish as the sample size grows.
MIDAS handles right censoring only (censoring due to end of observation or loss to follow-up). Left censoring (when the event had already occurred by the start of observation but its exact time is unknown) and interval censoring (when the event time can only be placed between two observation times) are not supported.
Why Ordinary Regression Fails
Without censoring, survival times could be analyzed as a response variable in ordinary regression. But censored data provides inequality information — "the true value is at least as large as the observed value" — and the usual residual () cannot be defined. Survival analysis incorporates this inequality into the likelihood function, correctly accounting for censoring.
Survival Function and Hazard Function
The distribution of survival time is characterized by two functions.
The survival function is the probability of not having experienced the event by time . It decreases monotonically over time, and when no event occurs at time 0.
The hazard function is the instantaneous rate of event occurrence at time , given survival up to that point:
The hazard is a rate (per unit time), not a probability, so it can exceed 1. The survival and hazard functions are related by ; knowing one determines the other.
Kaplan-Meier Estimator
The Kaplan-Meier estimator is a nonparametric estimator of the survival function. It makes no distributional assumptions, estimating directly from observed event times.
Each subject's observed time is the time until the event or censoring, whichever occurs first. Let the distinct event times be , with subjects at risk (subjects whose observed time is at least ) and events at each time :
This cumulatively multiplies the "survival fraction" at each event time. Censoring is reflected through changes in the risk set. A censored subject is in the risk set at event times up to and including the censoring time and leaves it for later event times. A censored subject is not counted in the number of events .
When multiple events occur at the same time (ties), is the total number of events at that time and is the size of the risk set immediately before that time.
Under independent censoring, the KM estimator is a consistent estimator of over the range of where the observed time is at least with positive probability. Even within this range, censoring shrinks the risk set near the end of follow-up, so the variance of the estimate grows. Beyond this range, is not determined by the data however large the sample.
The variance is estimated using Greenwood's formula, derived via the delta method:
Confidence intervals are constructed from this variance. Writing for the standard error of from Greenwood's formula, the standard error of is by the delta method. MIDAS uses the log transformation method, computing . At times where , the lower bound of this interval is positive, but the upper bound can exceed 1, so MIDAS truncates the upper bound at 1. At times where , is undefined, and MIDAS sets the interval to .
RMST (Restricted Mean Survival Time)
RMST is the area under the survival function up to a restriction time .
It equals , the expected survival time when follow-up is restricted to . Unlike the hazard ratio, RMST does not require the proportional hazards assumption.
Since the KM estimator is a step function, the integral reduces to a sum of rectangles. Let be the event times at or before , with , , , and for :
Variance
Variation in the KM estimator at each event time propagates to RMST through the remaining area under the curve. Let (the area under the KM curve from to ):
The contribution of each time point to the RMST variance need not be monotone in time. It is the product of two factors. The factor is larger at earlier times. The factor , the same term as in Greenwood's formula, captures the variation of the KM estimator at and grows as the risk set shrinks.
RMST is asymptotically normal as . The confidence interval is therefore Wald-type: . RMST takes values from 0 to , so MIDAS truncates the lower bound of this interval at 0 and the upper bound at .
Only the time points with and add a positive value to the variance sum. At the integration interval has length 0, so . At a time point with , and therefore , and MIDAS takes the term at this time point as 0. In a group with no time point that adds a positive value, the variance estimate is 0 and MIDAS does not estimate RMST.
Group Differences
For the RMST difference between two groups, , the groups are independent, so the variance is the sum of each group's variance.
The confidence interval is Wald-type, and MIDAS truncates it to the range of the difference, from to . For three or more groups, pairwise differences and confidence intervals are computed without adjusting for multiplicity.
Cox Proportional Hazards Model
Model Formulation
The Cox (1972) proportional hazards model is a semiparametric model that estimates the effect of covariates on hazard:
is the baseline hazard (the hazard when all covariates are zero), and is the hazard ratio for a one-unit increase in covariate .
It is called "semiparametric" because is estimated parametrically, but no functional form is specified for . After estimating , the cumulative baseline hazard can be estimated nonparametrically, which in turn allows computing the survival function for specific covariate values:
where . The estimator handles ties with the same Efron method used to estimate the coefficients. MIDAS outputs and at user-specified covariate values.
Variance of the Baseline Hazard and Survival Estimates
The estimate of has two sources of uncertainty. Writing for the estimate of the cumulative baseline hazard at the estimated coefficients , its increment at each event time is a ratio whose denominator is the sum of over the risk set, so the increments vary from sample to sample even if were known. In addition, depends on , so the sampling error of propagates into . MIDAS estimates the variance as the sum of a term for each source, treating the two sources as uncorrelated, with the second term obtained by the delta method:
where is the sum of over the risk set at , is the same sum over the subjects with an event at , is the estimated variance-covariance matrix of , and is the gradient of with respect to divided by . The inner sum over is the Efron correction for ties, the same progressively reduced denominator as in the partial likelihood; without ties () the first term reduces to . The first term is a cumulative sum of positive terms, and its increment per time point grows toward the end of follow-up as the risk set shrinks. in the second term is a cumulative sum of terms whose sign can change from one time point to the next, so the total variance need not be monotone in time. The second term grows with the distance between and the covariate values in the data, because contains itself.
MIDAS constructs the confidence interval on the scale, which is the scale for the survival function. By the delta method, the standard error of is , and the factor cancels in this ratio. The interval for is , and the interval for follows through with the bounds swapped. This scale keeps the interval for positive and the interval for inside . The intervals are pointwise, so they do not guarantee simultaneous coverage of the whole curve.
The covariates in this model are fixed values for each subject throughout the observation period. Handling covariates that change over time (time-varying covariates) requires extensions that MIDAS does not currently support.
Proportional Hazards Assumption
The core assumption is that covariate effects are constant over time. That is, the hazard ratio does not depend on .
When this assumption is violated (e.g., a treatment effect that fades over time), the estimated represents a weighted average of the time-varying effect, with weights that depend on the risk set composition and baseline hazard, making interpretation difficult. The weights of this average depend on the shape of the baseline hazard and cannot be determined in advance, so what the estimate is actually estimating is unknowable (Struthers & Kalbfleisch, 1986).
Schoenfeld Residuals
Schoenfeld residuals are used to diagnose potential violations of the proportional hazards assumption. They are defined at each event time for each covariate :
is the value of covariate for the subject who experienced the event. is the weighted mean of covariate over the risk set, defined at a time without ties as:
Here ranges over subjects in the risk set , is the covariate vector for subject , and is the linear predictor. The weight is subject-specific — subjects with higher hazard contribute more — and is the same for all covariates .
At a time with ties, MIDAS uses the same weighted mean as the Efron method in the partial likelihood, with the weights of the tied subjects reduced step by step. When events are tied at time , the shared by the residuals of those subjects is:
and are the same sums as in the variance of the baseline hazard section. and are those sums with replaced by . With , this formula reduces to the formula for a time without ties.
The sum of Schoenfeld residuals equals the score function (the gradient of the log partial likelihood with respect to ). Schoenfeld (1982) shows this equality under the Breslow method for ties. The equality also holds with the Efron method that MIDAS uses: with the definition of above, the sum of the residuals at a tied time is the same expression as that time's term in the score function of the Efron partial likelihood. The score function is zero at the that maximizes the partial likelihood. MIDAS computes iteratively, so the score function at is not exactly zero. The sum of residuals is therefore close to zero rather than exactly zero.
Scaled Schoenfeld residuals adjust the residuals by the variance-covariance matrix so that they can be read as estimates of , the coefficient of covariate at time :
where is the total number of events, and is the entry of (the estimated variance-covariance matrix). That the expected value of is approximately follows from two approximations. The first treats the variation of over time as small and keeps only the first-order term of a Taylor expansion. The second treats the variance-covariance matrix of the covariates over the risk set, weighted by , as nearly constant over time. The exact scaling uses the inverse of this matrix at each time, and replaces it with a value common to all times (Grambsch & Therneau, 1994, pp. 516–519). In data where the distribution of the covariates within the risk set changes substantially over time, this approximation fails, and cannot be read as an estimate of .
Under proportional hazards, shows no systematic trend over time. Individual values have high variance, so the residuals are plotted against time and smoothed (e.g., with LOESS) to assess trends (Grambsch & Therneau, 1994).
MIDAS displays the following diagnostics (usage):
- Proportional Hazards Diagnostics: Displays the Pearson correlation (rho) between scaled Schoenfeld residuals and a KM-based time transform for each covariate
- Scaled Schoenfeld residual plots: Plots against time with a LOESS smooth
- log(-log(S(t))) plot: Plots Kaplan-Meier estimates as versus by group. When the hazards of the groups are proportional, the curves are parallel apart from sampling variation (how to read the plot)
The curves of the log(-log(S(t))) plot need not be parallel even if the model's proportional hazards assumption holds. MIDAS does not adjust the curves for the other covariates. In addition, MIDAS splits a covariate with six or more distinct values into two groups at the median, so each group mixes different covariate values and the hazards of the two groups need not be proportional.
The sign of rho can disagree with the direction of the trend seen in the residual plot. The rho uses the KM-based time transform as its time axis, while the residual plots use raw time on the horizontal axis. is a step function that stays constant between event times; it does not decrease in time, but it is not a linear transform of time. A nondecreasing transform that is not linear can change the sign of a Pearson correlation, so the disagreement can occur when the residual trend changes direction partway.
Partial Likelihood
Cox model parameters are estimated using partial likelihood. For subject who experienced an event at time , consider the conditional probability that subject is the one who experiences the event among the risk set , the subjects whose observed time is at least :
Each factor corresponds to the conditional probability within the risk set at time . Substituting , the terms cancel between numerator and denominator, so estimating does not require knowing . The formula above assumes distinct event times. When multiple events occur at the same time (ties), the conditional probability is not uniquely defined, requiring an approximation. The Breslow method applies the same risk set to each tied event; the Efron method progressively reduces the risk set among tied events and is generally more accurate. MIDAS uses the Efron method.
Although the partial likelihood is not a full likelihood, it has been shown to yield estimators with the same asymptotic properties as maximum likelihood — consistency and asymptotic normality (Cox, 1975; Andersen & Gill, 1982).
Interpreting Hazard Ratios
Holding other covariates constant, is interpreted as the hazard ratio (HR):
- HR > 1: A subject whose is one unit larger has a hazard higher
- HR < 1: A subject whose is one unit larger has a hazard lower
- HR = 1: The hazard does not depend on
The width of the confidence interval reflects estimation precision: a narrow interval indicates a more precise estimate, while a wide interval indicates limited information from the data. The hazard ratio and its confidence interval show the direction and magnitude of the association between and the hazard.
Model Fit Metrics
Concordance Index
The concordance index (Harrell's C) measures how well the model predicts the ordering of survival times.
Among comparable pairs (where one subject experienced an event while the other was still at risk), concordance is the proportion of pairs where the risk score ordering agrees with the event ordering. A pair with equal risk scores counts as 0.5 of an agreeing pair. A value of 0.5 indicates no discrimination (equivalent to random prediction); 1.0 indicates perfect discrimination. Pairs in which both subjects experienced an event at the same time are not counted as comparable. For data with many tied event times, the value differs from one computed under a definition that includes those pairs.
The that MIDAS reports is biased upward relative to the discrimination on new data. MIDAS computes on the data used for fitting, with risk scores from the estimated on that same data, and this also fits the chance variation in the data. The bias grows as the number of covariates grows relative to the number of events.
The standard error is estimated via the influence function (infinitesimal jackknife). For each observation , the influence is , where is the number of comparable pairs involving observation whose ordering agrees (a pair with equal risk scores counts as 0.5), is the number of comparable pairs involving observation , is the concordance, and is the total number of comparable pairs. Then .
AIC
where is the log partial likelihood and is the number of covariates. Lower values indicate a better balance between fit and parsimony.
AIC can compare only models fitted to the same set of observations, because the partial likelihood becomes a different function when the rows used change. MIDAS drops rows in which any selected covariate is missing before fitting, so changing the covariate set can change the rows used. In that case, the difference in AIC between two models does not reflect the difference in covariates alone.
See also
- The Kaplan-Meier Tab - Estimating survival curves and comparing groups with RMST
- The Cox Regression Tab - Using Cox regression and interpreting results
- Tutorial: Kaplan-Meier Analysis - A practical example with sample data
References
- Cox, D. R. (1972). Regression models and life-tables. Journal of the Royal Statistical Society: Series B, 34(2), 187-220. https://www.jstor.org/stable/2985181
- Kaplan, E. L., & Meier, P. (1958). Nonparametric estimation from incomplete observations. Journal of the American Statistical Association, 53(282), 457-481. https://www.jstor.org/stable/2281868
- Cox, D. R. (1975). Partial likelihood. Biometrika, 62(2), 269-276. https://www.jstor.org/stable/2335362
- Andersen, P. K., & Gill, R. D. (1982). Cox's regression model for counting processes: A large sample study. The Annals of Statistics, 10(4), 1100-1120. https://www.jstor.org/stable/2240714
- Struthers, C. A., & Kalbfleisch, J. D. (1986). Misspecified proportional hazard models. Biometrika, 73(2), 363-369. https://www.jstor.org/stable/2336212
- Schoenfeld, D. (1982). Partial residuals for the proportional hazards regression model. Biometrika, 69(1), 239-241. https://www.jstor.org/stable/2335876
- Grambsch, P. M., & Therneau, T. M. (1994). Proportional hazards tests and diagnostics based on weighted residuals. Biometrika, 81(3), 515-526. https://www.jstor.org/stable/2337123
Footnotes
-
Independent censoring is a different condition from non-informative censoring. Non-informative censoring means that the distribution of the censoring time does not involve the parameters of the event time distribution, and it does not follow from independent censoring. The consistency stated in the text follows from independent censoring and does not use non-informative censoring. Independent censoring is a sufficient condition for consistency, not a necessary one. ↩
Also available as a Markdown file.