# This file from www.richardsconsulting.co.uk/lectures # First load in the survival library library(survival) Loading required package: splines # Now create a list of (i) survival times, (ii) censoring/event status, # and (iii) genders # # Note that '1' = death and '0' = censored in the status variable, and that # '0' = male and '1' = female in the gender variable. example2<-list(time =c(2, 5, 9, 11, 14, 4, 7, 10, 12, 15), status=c(1, 0, 1, 0, 1, 1, 0, 0, 0, 1), gender=c(0, 0, 0, 0, 0, 1, 1, 1, 1, 1)) # Fit a Cox proportional-hazards model coxfit<-coxph(Surv(time, status) ~ gender, example2) # Take a look at the value for the z test beta<- coxfit$coef stderr<-sqrt(coxfit$var) z<-beta / stderr z*z 1.001630 # Now the score test: coxfit$score 1.117647 # And finally the LRT: -2*(coxfit$loglik[1] - coxfit$loglik[2]) 1.163364 # Compare these values with the output given in the summary() command: summary(coxfit) Call: coxph(formula = Surv(time, status) ~ gender, data = example2) n= 10 coef exp(coef) se(coef) z p gender -1.16 0.315 1.16 -1 0.32 exp(coef) exp(-coef) lower .95 upper .95 gender 0.315 3.18 0.0326 3.03 Rsquare= 0.11 (max possible= 0.753 ) Likelihood ratio test= 1.16 on 1 df, p=0.281 Wald test = 1 on 1 df, p=0.317 Score (logrank) test = 1.12 on 1 df, p=0.290