Survival analysis: Kaplan-Meier

TODO

  • link to survivalCoxPH, survivalParametric

Install required packages

survival

Simulated right-censored event times with Weibull distribution

Simulated survival time \(T\) influenced by time independent covariates \(X_{j}\) with effect parameters \(\beta_{j}\) under assumption of proportional hazards, stratified by sex.

\(T = (-\ln(U) \, b \, e^{-\bf{X} \bf{\beta}})^{\frac{1}{a}}\), where \(U \sim \mathcal{U}(0, 1)\), \(a\) is the Weibull shape parameter and \(b\) is the Weibull scale parameter.

Survival data in counting process (start-stop) notation.

Plot simulated data

plot of chunk rerSurvivalKM01
plot of chunk rerSurvivalKM01

Kaplan-Meier-Analysis

Estimate survival-function

Survival function \(S(t) = 1-F(t)\), hazard function

\[ \begin{equation*} \lambda(t) = \lim_{\Delta_{t} \to 0^{+}} \frac{P(t \leq T < t + \Delta_{t} \, | \, T \geq t)}{\Delta_{t}} = \frac{P(t \leq T < t + \Delta_{t}) / \Delta_{t}}{P(T > t)} = \frac{f(t)}{S(t)}, \quad t \geq 0 \end{equation*} \]

Call: survfit(formula = Surv(obsT, status) ~ IV, data = dfSurv, type = "kaplan-meier", 
    conf.type = "log")

      n events median 0.95LCL 0.95UCL
IV=A 60     53   13.0       8      29
IV=B 60     46   35.0      20      58
IV=C 60     58    9.5       4      13

Arbitrary quantiles for estimated survival function.

$quantile
  25   50   75 
 4.0 14.0 46.5 

$lower
25 50 75 
 3 10 34 

$upper
25 50 75 
 6 19 65 

Estimated mean survival time

Call: survfit(formula = Surv(obsT, status) ~ 1, data = dfSurv, type = "kaplan-meier", 
    conf.type = "log")

         n     events     *rmean *se(rmean)     median    0.95LCL    0.95UCL 
    180.00     157.00      33.16       3.01      14.00      10.00      19.00 
    * restricted mean with upper limit =  120 

50-day and 100-day survival including point-wise confidence interval.

Call: survfit(formula = Surv(obsT, status) ~ 1, data = dfSurv, type = "kaplan-meier", 
    conf.type = "log")

 time n.risk n.event survival std.err lower 95% CI upper 95% CI
   50     42     140    0.222  0.0310        0.169        0.292
  100     27      13    0.150  0.0266        0.106        0.212

All estimated values for survival function including point-wise confidence interval.

Plot estimated survival function

Global estimate including pointwise confidence intervals.

plot of chunk rerSurvivalKM02a
plot of chunk rerSurvivalKM02a

Separate estimates for levels of factor IV

plot of chunk rerSurvivalKM03a
plot of chunk rerSurvivalKM03a

Plot cumulative incidence function

Separate estimates for levels of factor IV

plot of chunk rerSurvivalKM03b
plot of chunk rerSurvivalKM03b

Plot cumulative hazard

\(\hat{\Lambda}(t)\)

plot of chunk rerSurvivalKM04
plot of chunk rerSurvivalKM04

Log-rank-test for equal survival-functions

Global test

Call:
survdiff(formula = Surv(obsT, status) ~ IV, data = dfSurv)

      N Observed Expected (O-E)^2/E (O-E)^2/V
IV=A 60       53     49.9     0.196     0.301
IV=B 60       46     71.7     9.220    18.251
IV=C 60       58     35.4    14.402    20.264

 Chisq= 26.1  on 2 degrees of freedom, p= 2e-06 

Stratified for factor sex

Call:
survdiff(formula = Surv(obsT, status) ~ IV + strata(sex), data = dfSurv)

      N Observed Expected (O-E)^2/E (O-E)^2/V
IV=A 60       53     50.9    0.0828      0.13
IV=B 60       46     71.7    9.2289     18.36
IV=C 60       58     34.3   16.3299     23.16

 Chisq= 28.4  on 2 degrees of freedom, p= 7e-07 

Further resources

Detach (automatically) loaded packages (if possible)

Get the article source from GitHub

R markdown - markdown - R code - all posts