# This file from www.richardsconsulting.co.uk/lectures # First load in the survival library library(survival) # 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 # Now the score test: coxfit$score # And finally the LRT: -2*(coxfit$loglik[1] - coxfit$loglik[2]) # Compare these values with the output given in the summary() command: summary(coxfit)