Teach survival analysis: censoring mechanisms, Kaplan–Meier and Nelson–Aalen estimators,…
- User
Teach survival analysis: censoring mechanisms, Kaplan–Meier and Nelson–Aalen estimators, log-rank tests, Cox proportional hazards model with assumptions/diagnostics (Schoenfeld), time-varying covariates, competing risks, and interpretation; include a tiny worked example.
- Assistant
Survival Analysis: A Concise Tutorial
Survival analysis studies time-to-event data, where the outcome is the time until an event (e.g., death, failure, relapse). Key challenges: censoring (partial observation) and handling ties/discrete times.
1. Censoring Mechanisms
Censoring occurs when the exact event time is unknown:
- Right-censoring (most common): Event not observed by study end or withdrawal (e.g., patient alive at follow-up). Denoted ( T_i^* = \min(T_i, C_i) ), (\delta_i = I(T_i \leq C_i)), where ( T_i ) is true time, ( C_i ) censor time.
- Left-censoring: Event occurred before observation starts (e.g., infection before study).
- Interval-censoring: Event known only in ([L_i, R_i]). Assumption: non-informative censoring (censoring independent of survival time given covariates).
2. Kaplan-Meier (KM) Estimator
Non-parametric estimate of survivor function ( S(t) = P(T > t) ).
At ordered distinct event times ( t_1 < t_2 < \dots < t_k ): [ \hat{S}(t) = \prod_{t_j \leq t} \left(1 - \frac{d_j}{n_j}\right) ]
- ( n_j ): at risk just before ( t_j ).
- ( d_j ): events at ( t_j ).
Variance (Greenwood): ( \widehat{\Var}(\hat{S}(t)) = \hat{S}(t)^2 \sum_{t_j \leq t} \frac{d_j}{n_j(n_j - d_j)} ). 95% CI: ( \hat{S}(t) \pm 1.96 \sqrt{\widehat{\Var}} ) (log or logit transforms for better coverage).
Plots: Step function, drops at events.
3. Nelson-Aalen (NA) Estimator
Estimates cumulative hazard ( \hat{\Lambda}(t) = \int_0^t \frac{dN(u)}{Y(u)} = \sum_{t_j \leq t} \frac{d_j}{n_j} ), where ( N(t) ) = events by ( t ), ( Y(t) ) = at risk.
Relation: ( \hat{S}(t) \approx \exp(-\hat{\Lambda}(t)) ) (1 - KM for small hazards).
4. Log-Rank Test
Compares ( k ) groups (e.g., treatment vs. control). Null: same hazard across groups.
Test statistic: ( \chi^2 = \sum_g \frac{(O_g - E_g)^2}{V_g} ), or Mantel-Haenszel form:
- Expected ( E_g(t_j) = \frac{n_{g,j} d_j}{n_j} ).
- ( O_g = \sum d_{g,j} ), ( V_g \approx \sum \frac{n_{g,j} n_{g^c,j} d_j}{n_j^2 (n_j - d_j)} ).
Global ( p )-value from ( \chi^2_{k-1} ).
5. Cox Proportional Hazards (PH) Model
Semi-parametric: ( h(t|X) = h_0(t) \exp(\beta^T X) ), or ( \lambda(t|X) = \lambda_0(t) \exp(\beta^T X) ).
Partial likelihood (no baseline hazard): [ \ell(\beta) = \sum_i \delta_i \left[ \beta^T X_i - \log \sum_{k \in R(t_i)} \exp(\beta^T X_k) \right] ] Estimates ( \hat{\beta} ) via Efron/Peto approximation for ties.
Assumptions:
- Proportional Hazards (PH): ( h(t|X)/h(t|X') ) constant over ( t ). Test via Schoenfeld residuals.
- Linear in ( \beta^T X ) (check via martingale residuals).
- No ties or handled approximately.
Diagnostics:
- Schoenfeld residuals: ( r_{ij} = X_i - \frac{S^{(1)}(t_j, \hat{\beta})}{S^{(0)}(t_j, \hat{\beta})} ) for individual ( i ) at event ( j ). Scaled: ( \hat{\gamma} r_{ij} ). Plot vs. time; slope ≠0 violates PH. Test: correlate with time (corr ( r_{ij}, \hat{\gamma} r_{ij} \cdot g(t_j) ), ( g(t) = t ) or rank(t)).
- Martingale residuals for functional form/outliers.
- Deviance residuals for goodness-of-fit.
Time-varying covariates: Extend to ( h(t|X(t)) = h_0(t) \exp(\beta^T X(t)) ). Data in counting process format: intervals where ( X(t) ) constant.
Interpretation:
- ( \exp(\hat{\beta}_j) ): Hazard ratio (HR) per unit increase in ( X_j ). E.g., HR=1.5: 50% higher hazard.
- Baseline survival: ( \hat{S}_0(t) = \exp(-\hat{\Lambda}_0(t)) ), ( \hat{\Lambda}0(t) = \sum \frac{d_j}{ \sum{k \in R(t_j)} \exp(\hat{\beta}^T X_k) } ) (Breslow).
- Predicted survival: ( \hat{S}(t|X) = \hat{S}_0(t)^{\exp(\hat{\beta}^T X)} ).
6. Competing Risks
Multiple mutually exclusive events (e.g., death from cancer vs. heart disease). Ignore → bias.
- Cause-specific hazard: ( h_k(t) = \lim_{\Delta t \to 0} P(t \leq T < t+\Delta t, cause=k \mid T \geq t)/\Delta t ). Fit separate Cox models.
- Cumulative incidence function (CIF): ( F_k(t) = P(T \leq t, cause=k) = \int_0^t h_k(u) [1 - F_{all}(u)] du ), where ( F_{all} = \sum F_k ).
- Non-parametric: Aalen-Johansen: ( \hat{F}k(t) = \sum{t_j \leq t} \hat{F}{k,-}(t{j-1}) \frac{d_{k j}}{n_j} ), ( \hat{F}_{-,} = 1 - \hat{S} ) (KM ignoring cause).
- Regression: Fine-Gray (subdistribution hazard): ( h_k^{sd}(t) = P(cause=k, t \leq T < t+dt \mid no prev. event)/dt ). Models ( \log(-\log(1-F_k(t))) ).
Test CIFs: Gray's test (like weighted log-rank).
Tiny Worked Example
Data (n=6, time to relapse or censor; treatment=1/0):
ID Time Status (1=relapse) Treat 1 1 1 0 2 2 1 1 3 3 0 0 4 4 1 0 5 5 1 1 6 6 0 1 KM by treatment:
- Treat=0 (n=3): Events at 1(d=1,n=3), 4(d=1,n=2). ( \hat{S}(t) ): 0.667 (t=1+), 0.333 (t=4+).
- Treat=1 (n=3): Events at 2(d=1,n=3), 5(d=1,n=2). ( \hat{S}(t) ): 0.667 (t=2+), 0.333 (t=5+). Pooled NA: ( \hat{\Lambda}(1)=1/6=0.167 ), ( \hat{\Lambda}(2)=1/5=0.2 ) (cum=0.367), etc.
Log-rank: Events at t=1: O0=1,E0=1/2 2=1? Wait, full calc: Times:1(O0=1,E0=3/61=0.5,V=0.25), t=2(O1=1,E1=3/61=0.5,V=0.25), t=4(O0=1,E0=2/41=0.5,V=0.25), t=5(O1=1,E1=2/4*1=0.5,V=0.25). O0-E0=0.5-0.5=0 +1-0.5=0.5 +0.5-0.5=0 → total (0.5)^2/1=0.25? Group totals: O0=2,E0=1.5; O1=2,E1=2.5. χ²=(0.5)^2/1 + (-0.5)^2/1=0.5, p≈0.48 (no diff).
Cox PH: Fit → ( \hat{\beta}_{treat} \approx 0 ) (HR=1, no effect). Schoenfeld: Check residuals vs time (flat → PH holds).
For code: Use
survivalin R (survfit,coxph,cox.zph).This scratches the surface—practice with software (R/Python lifelines) on real data! Questions?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.