Import packages

library(survival)


Cox proportional hazards model (predicting survival from heart dataset)

cox_mod <- coxph(Surv(start, stop, event) ~ age + year + surgery + transplant, data =  heart)
summary(cox_mod)
## Call:
## coxph(formula = Surv(start, stop, event) ~ age + year + surgery + 
##     transplant, data = heart)
## 
##   n= 172, number of events= 75 
## 
##                 coef exp(coef) se(coef)      z Pr(>|z|)  
## age          0.02717   1.02754  0.01371  1.981   0.0476 *
## year        -0.14635   0.86386  0.07047 -2.077   0.0378 *
## surgery     -0.63721   0.52877  0.36723 -1.735   0.0827 .
## transplant1 -0.01025   0.98980  0.31375 -0.033   0.9739  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##             exp(coef) exp(-coef) lower .95 upper .95
## age            1.0275     0.9732    1.0003    1.0555
## year           0.8639     1.1576    0.7524    0.9918
## surgery        0.5288     1.8912    0.2574    1.0860
## transplant1    0.9898     1.0103    0.5352    1.8307
## 
## Concordance= 0.636  (se = 0.037 )
## Rsquare= 0.084   (max possible= 0.969 )
## Likelihood ratio test= 15.11  on 4 df,   p=0.004476
## Wald test            = 14.49  on 4 df,   p=0.005877
## Score (logrank) test = 15.03  on 4 df,   p=0.004631


Cox proportional hazards model (predicting survival from lung dataset)

cox_mod2 <- coxph(Surv(time=lung$time, event=lung$status==2, type='right') ~ lung$sex + lung$ph.ecog)
summary(cox_mod2)
## Call:
## coxph(formula = Surv(time = lung$time, event = lung$status == 
##     2, type = "right") ~ lung$sex + lung$ph.ecog)
## 
##   n= 227, number of events= 164 
##    (1 observation deleted due to missingness)
## 
##                 coef exp(coef) se(coef)      z Pr(>|z|)    
## lung$sex     -0.5530    0.5752   0.1676 -3.300 0.000967 ***
## lung$ph.ecog  0.4875    1.6282   0.1122  4.344  1.4e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##              exp(coef) exp(-coef) lower .95 upper .95
## lung$sex        0.5752     1.7384    0.4142    0.7989
## lung$ph.ecog    1.6282     0.6142    1.3067    2.0288
## 
## Concordance= 0.642  (se = 0.026 )
## Rsquare= 0.12   (max possible= 0.999 )
## Likelihood ratio test= 29.05  on 2 df,   p=4.91e-07
## Wald test            = 28.96  on 2 df,   p=5.145e-07
## Score (logrank) test = 29.41  on 2 df,   p=4.104e-07