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 (yi−y^iy_i - \hat{y}_i) 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 TT is characterized by two functions.

The survival function S(t)=P(T>t)S(t) = P(T > t) is the probability of not having experienced the event by time tt. It decreases monotonically over time, and S(0)=1S(0) = 1 when no event occurs at time 0.

The hazard function h(t)h(t) is the instantaneous rate of event occurrence at time tt, given survival up to that point:

h(t)=lim⁡Δt→0P(t≤T<t+Δt∣T≥t)Δth(t) = \lim_{\Delta t \to 0} \frac{P(t \le T < t + \Delta t \mid T \ge t)}{\Delta t}

The hazard is a rate (per unit time), not a probability, so it can exceed 1. The survival and hazard functions are related by S(t)=exp⁡(−∫0th(u) du)S(t) = \exp\left(-\int_0^t h(u)\,du\right); 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 S(t)S(t) 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 t1<t2<⋯<tkt_1 < t_2 < \cdots < t_k, with nin_i subjects at risk (subjects whose observed time is at least tit_i) and did_i events at each time tit_i:

S^(t)=∏ti≤t(1−dini)\hat{S}(t) = \prod_{t_i \le t} \left(1 - \frac{d_i}{n_i}\right)

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 did_i.

When multiple events occur at the same time (ties), did_i is the total number of events at that time and nin_i is the size of the risk set immediately before that time.

Under independent censoring, the KM estimator is a consistent estimator of S(t)S(t) over the range of tt where the observed time is at least tt 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, S(t)S(t) is not determined by the data however large the sample.

The variance is estimated using Greenwood's formula, derived via the delta method:

Var⁡^[S^(t)]=S^(t)2∑ti≤tdini(ni−di)\widehat{\operatorname{Var}}[\hat{S}(t)] = \hat{S}(t)^2 \sum_{t_i \le t} \frac{d_i}{n_i(n_i - d_i)}

Confidence intervals are constructed from this variance. Writing SE\text{SE} for the standard error of S^(t)\hat{S}(t) from Greenwood's formula, the standard error of log⁡S^(t)\log \hat{S}(t) is SE/S^(t)\text{SE}/\hat{S}(t) by the delta method. MIDAS uses the log transformation method, computing exp⁡ ⁣(log⁡S^(t)±z⋅SE/S^(t))\exp\!\bigl(\log \hat{S}(t) \pm z \cdot \text{SE}/\hat{S}(t)\bigr). At times where S^(t)>0\hat{S}(t) > 0, 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 S^(t)=0\hat{S}(t) = 0, log⁡S^(t)\log \hat{S}(t) is undefined, and MIDAS sets the interval to [0,0][0, 0].

RMST (Restricted Mean Survival Time)

RMST is the area under the survival function up to a restriction time τ\tau.

RMST(τ)=∫0τS(t) dt\text{RMST}(\tau) = \int_0^\tau S(t)\,dt

It equals E[min⁡(T,τ)]E[\min(T, \tau)], the expected survival time when follow-up is restricted to τ\tau. Unlike the hazard ratio, RMST does not require the proportional hazards assumption.

Since the KM estimator S^(t)\hat{S}(t) is a step function, the integral reduces to a sum of rectangles. Let t1<t2<⋯<tmt_1 < t_2 < \cdots < t_m be the event times at or before τ\tau, with t0=0t_0 = 0, tm+1=τt_{m+1} = \tau, S^0=1\hat{S}_0 = 1, and S^i=S^(ti)\hat{S}_i = \hat{S}(t_i) for i≥1i \ge 1:

RMST^(τ)=∑i=0mS^i(min⁡(ti+1,τ)−ti)\widehat{\text{RMST}}(\tau) = \sum_{i=0}^{m} \hat{S}_i\bigl(\min(t_{i+1}, \tau) - t_i\bigr)

Variance

Variation in the KM estimator at each event time propagates to RMST through the remaining area under the curve. Let A(ti)=∫tiτS^(t) dtA(t_i) = \int_{t_i}^{\tau} \hat{S}(t)\,dt (the area under the KM curve from tit_i to τ\tau):

Var^[RMST^(τ)]=∑ti≤τA(ti)2dini(ni−di)\widehat{\text{Var}}\bigl[\widehat{\text{RMST}}(\tau)\bigr] = \sum_{t_i \le \tau} A(t_i)^2 \frac{d_i}{n_i(n_i - d_i)}

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 A(ti)2A(t_i)^2 is larger at earlier times. The factor di/(ni(ni−di))d_i / \bigl(n_i(n_i - d_i)\bigr), the same term as in Greenwood's formula, captures the variation of the KM estimator at tit_i and grows as the risk set shrinks.

RMST is asymptotically normal as n→∞n \to \infty. The confidence interval is therefore Wald-type: RMST^±zα/2⋅SE\widehat{\text{RMST}} \pm z_{\alpha/2} \cdot \text{SE}. RMST takes values from 0 to τ\tau, so MIDAS truncates the lower bound of this interval at 0 and the upper bound at τ\tau.

Only the time points with ti<τt_i < \tau and ni>din_i > d_i add a positive value to the variance sum. At ti=τt_i = \tau the integration interval has length 0, so A(ti)=0A(t_i) = 0. At a time point with ni=din_i = d_i, S^(ti)=0\hat{S}(t_i) = 0 and therefore A(ti)=0A(t_i) = 0, 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, Δ=RMST1−RMST2\Delta = \text{RMST}_1 - \text{RMST}_2, the groups are independent, so the variance is the sum of each group's variance.

Var(Δ^)=Var(RMST^1)+Var(RMST^2)\text{Var}(\hat\Delta) = \text{Var}(\widehat{\text{RMST}}_1) + \text{Var}(\widehat{\text{RMST}}_2)

The confidence interval is Wald-type, and MIDAS truncates it to the range of the difference, from −τ-\tau to τ\tau. 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:

h(t∣X)=h0(t)exp⁡(β1X1+β2X2+⋯+βpXp)h(t \mid X) = h_0(t) \exp(\beta_1 X_1 + \beta_2 X_2 + \cdots + \beta_p X_p)

h0(t)h_0(t) is the baseline hazard (the hazard when all covariates are zero), and exp⁡(βj)\exp(\beta_j) is the hazard ratio for a one-unit increase in covariate XjX_j.

It is called "semiparametric" because β\beta is estimated parametrically, but no functional form is specified for h0(t)h_0(t). After estimating β\beta, the cumulative baseline hazard H0(t)H_0(t) can be estimated nonparametrically, which in turn allows computing the survival function S(t∣X)S(t|X) for specific covariate values:

S(t∣X)=exp⁡ ⁣(−H0(t)⋅exp⁡(β′X))S(t \mid X) = \exp\!\bigl(-H_0(t) \cdot \exp(\beta' X)\bigr)

where H0(t)=∫0th0(u) duH_0(t) = \int_0^t h_0(u)\,du. The estimator handles ties with the same Efron method used to estimate the coefficients. MIDAS outputs H0(t)H_0(t) and S(t∣X)S(t|X) at user-specified covariate values.

Variance of the Baseline Hazard and Survival Estimates

The estimate of H(t∣X)=H0(t)exp⁡(β′X)H(t|X) = H_0(t)\exp(\beta'X) has two sources of uncertainty. Writing H^0(t)\hat{H}_0(t) for the estimate of the cumulative baseline hazard at the estimated coefficients β^\hat\beta, its increment at each event time is a ratio whose denominator is the sum of exp⁡(β^′Xi)\exp(\hat\beta'X_i) over the risk set, so the increments vary from sample to sample even if β\beta were known. In addition, H^0(t)\hat{H}_0(t) depends on β^\hat\beta, so the sampling error of β^\hat\beta propagates into H^0(t)\hat{H}_0(t). 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:

Var⁡^[H^(t∣X)]=exp⁡(2β^′X)[∑ti≤t∑m=0di−11(S0(ti)−mdiD0(ti))2+g(t)′ V^ g(t)]\widehat{\operatorname{Var}}\bigl[\hat{H}(t \mid X)\bigr] = \exp(2\hat\beta'X)\left[\sum_{t_i \le t} \sum_{m=0}^{d_i - 1} \frac{1}{\bigl(S_0(t_i) - \tfrac{m}{d_i} D_0(t_i)\bigr)^2} + \mathbf{g}(t)'\,\hat{V}\,\mathbf{g}(t)\right]

where S0(ti)S_0(t_i) is the sum of exp⁡(β^′Xk)\exp(\hat\beta'X_k) over the risk set at tit_i, D0(ti)D_0(t_i) is the same sum over the did_i subjects with an event at tit_i, V^\hat{V} is the estimated variance-covariance matrix of β^\hat\beta, and g(t)=X H^0(t)+∂H^0(t)/∂β\mathbf{g}(t) = X\,\hat{H}_0(t) + \partial \hat{H}_0(t)/\partial\beta is the gradient of H^(t∣X)\hat{H}(t \mid X) with respect to β\beta divided by exp⁡(β^′X)\exp(\hat\beta'X). The inner sum over mm is the Efron correction for ties, the same progressively reduced denominator as in the partial likelihood; without ties (di=1d_i = 1) the first term reduces to ∑ti≤t1/S0(ti)2\sum_{t_i \le t} 1 / S_0(t_i)^2. 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. g(t)\mathbf{g}(t) 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 XX and the covariate values in the data, because g(t)\mathbf{g}(t) contains XX itself.

MIDAS constructs the confidence interval on the log⁡H\log H scale, which is the log⁡(−log⁡S)\log(-\log S) scale for the survival function. By the delta method, the standard error of log⁡H^(t∣X)\log \hat{H}(t \mid X) is SE[H^(t∣X)]/H^(t∣X)\text{SE}[\hat{H}(t \mid X)] / \hat{H}(t \mid X), and the factor exp⁡(β^′X)\exp(\hat\beta'X) cancels in this ratio. The interval for H(t∣X)H(t \mid X) is H^(t∣X)⋅exp⁡(±z⋅SE/H^)\hat{H}(t \mid X) \cdot \exp\bigl(\pm z \cdot \text{SE}/\hat{H}\bigr), and the interval for S(t∣X)S(t \mid X) follows through S=exp⁡(−H)S = \exp(-H) with the bounds swapped. This scale keeps the interval for HH positive and the interval for SS inside [0,1][0, 1]. The intervals are pointwise, so they do not guarantee simultaneous coverage of the whole curve.

The covariates XX 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 h(t∣X1)/h(t∣X2)=exp⁡(β′(X1−X2))h(t \mid X_1) / h(t \mid X_2) = \exp(\beta'(X_1 - X_2)) does not depend on tt.

When this assumption is violated (e.g., a treatment effect that fades over time), the estimated β\beta 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 t(i)t_{(i)} for each covariate jj:

rij=Xij−Xˉj(t(i))r_{ij} = X_{ij} - \bar{X}_j(t_{(i)})

XijX_{ij} is the value of covariate jj for the subject who experienced the event. Xˉj(t(i))\bar{X}_j(t_{(i)}) is the weighted mean of covariate jj over the risk set, defined at a time without ties as:

Xˉj(t(i))=∑k∈R(t(i))Xkjexp⁡(Xk′β^)∑k∈R(t(i))exp⁡(Xk′β^)\bar{X}_j(t_{(i)}) = \frac{\sum_{k \in \mathcal{R}(t_{(i)})} X_{kj} \exp(X_k'\hat\beta)}{\sum_{k \in \mathcal{R}(t_{(i)})} \exp(X_k'\hat\beta)}

Here kk ranges over subjects in the risk set R(t(i))\mathcal{R}(t_{(i)}), XkX_k is the covariate vector for subject kk, and Xk′β^X_k'\hat\beta is the linear predictor. The weight exp⁡(Xk′β^)\exp(X_k'\hat\beta) is subject-specific — subjects with higher hazard contribute more — and is the same for all covariates jj.

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 qq events are tied at time t(i)t_{(i)}, the Xˉj(t(i))\bar{X}_j(t_{(i)}) shared by the residuals of those qq subjects is:

Xˉj(t(i))=1q∑m=0q−1S1j(t(i))−mqD1j(t(i))S0(t(i))−mqD0(t(i))\bar{X}_j(t_{(i)}) = \frac{1}{q} \sum_{m=0}^{q-1} \frac{S_{1j}(t_{(i)}) - \tfrac{m}{q} D_{1j}(t_{(i)})}{S_0(t_{(i)}) - \tfrac{m}{q} D_0(t_{(i)})}

S0S_0 and D0D_0 are the same sums as in the variance of the baseline hazard section. S1jS_{1j} and D1jD_{1j} are those sums with exp⁡(β^′Xk)\exp(\hat\beta'X_k) replaced by Xkjexp⁡(β^′Xk)X_{kj}\exp(\hat\beta'X_k). With q=1q = 1, 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 β\beta). 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 Xˉj(t(i))\bar{X}_j(t_{(i)}) 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 β\beta that maximizes the partial likelihood. MIDAS computes β^\hat\beta iteratively, so the score function at β^\hat\beta is not exactly zero. The sum of residuals is therefore close to zero rather than exactly zero.

Scaled Schoenfeld residuals adjust the residuals rijr_{ij} by the variance-covariance matrix so that they can be read as estimates of βj(t)\beta_j(t), the coefficient of covariate jj at time tt:

rij∗=d∑k=1pV^jk rik+β^jr^*_{ij} = d \sum_{k=1}^{p} \hat{V}_{jk} \, r_{ik} + \hat\beta_j

where dd is the total number of events, and V^jk\hat{V}_{jk} is the (j,k)(j,k) entry of V^=I^(β^)−1\hat{V} = \hat{I}(\hat\beta)^{-1} (the estimated p×pp \times p variance-covariance matrix). That the expected value of rij∗r^*_{ij} is approximately βj(t(i))\beta_j(t_{(i)}) follows from two approximations. The first treats the variation of βj(t)\beta_j(t) 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 exp⁡(Xk′β^)\exp(X_k'\hat\beta), as nearly constant over time. The exact scaling uses the inverse of this matrix at each time, and d⋅V^d \cdot \hat{V} 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 rij∗r^*_{ij} cannot be read as an estimate of βj(t(i))\beta_j(t_{(i)}).

Under proportional hazards, rij∗r^*_{ij} 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 rij∗r^*_{ij} against time with a LOESS smooth
  • log(-log(S(t))) plot: Plots Kaplan-Meier estimates as log⁡(−log⁡(S(t)))\log(-\log(S(t))) versus log⁡(t)\log(t) 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 g(t)=1−S^(t−)g(t)=1-\hat{S}(t^-) as its time axis, while the residual plots use raw time on the horizontal axis. g(t)g(t) 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 ii who experienced an event at time t(i)t_{(i)}, consider the conditional probability that subject ii is the one who experiences the event among the risk set R(t(i))\mathcal{R}(t_{(i)}), the subjects whose observed time is at least t(i)t_{(i)}:

L(β)=∏i:eventexp⁡(Xi′β)∑j∈R(t(i))exp⁡(Xj′β)L(\beta) = \prod_{i:\text{event}} \frac{\exp(X_i'\beta)}{\sum_{j \in \mathcal{R}(t_{(i)})} \exp(X_j'\beta)}

Each factor corresponds to the conditional probability h(t(i)∣Xi)/∑jh(t(i)∣Xj)h(t_{(i)}|X_i) / \sum_j h(t_{(i)}|X_j) within the risk set at time t(i)t_{(i)}. Substituting h(t∣X)=h0(t)exp⁡(X′β)h(t|X) = h_0(t)\exp(X'\beta), the h0(t(i))h_0(t_{(i)}) terms cancel between numerator and denominator, so estimating β\beta does not require knowing h0(t)h_0(t). 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, exp⁡(βj)\exp(\beta_j) is interpreted as the hazard ratio (HR):

  • HR > 1: A subject whose XjX_j is one unit larger has a hazard (HR−1)×100%(\text{HR} - 1) \times 100\% higher
  • HR < 1: A subject whose XjX_j is one unit larger has a hazard (1−HR)×100%(1 - \text{HR}) \times 100\% lower
  • HR = 1: The hazard does not depend on XjX_j

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 XjX_j 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 η^i=Xiβ^\hat\eta_i = X_i\hat\beta 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 CC that MIDAS reports is biased upward relative to the discrimination on new data. MIDAS computes CC on the data used for fitting, with risk scores from the β^\hat\beta estimated on that same data, and this β^\hat\beta 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 ii, the influence is δi=(ci−C⋅Ni)/N\delta_i = (c_i - C \cdot N_i) / N, where cic_i is the number of comparable pairs involving observation ii whose ordering agrees (a pair with equal risk scores counts as 0.5), NiN_i is the number of comparable pairs involving observation ii, CC is the concordance, and NN is the total number of comparable pairs. Then SE=∑δi2SE = \sqrt{\sum \delta_i^2}.

AIC

AIC=−2ℓ(β^)+2p\text{AIC} = -2\ell(\hat\beta) + 2p

where ℓ(β^)\ell(\hat\beta) is the log partial likelihood and pp 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

References

Footnotes

  1. 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. ↩