Cox Proportional Hazard Model > # Demonstration of Cox Proportional Hazard model > library( survival ) # Library of survival analysis functions > # Get Afifi's text book lung cancer data > Lung <- read.table("http://users.humboldt.edu/rizzardi/Data.dir/Surv.txt", + header=F, na.strings=".") > > names(Lung) <+ c("ID","STAGET","Stagen","Hist","Treat","Perfbl","Poinf","Smokfu","Smokbl","Days","Dea th") > > # Death: 0 = Alive(censored), 1=Dead > # STAGET: Tumor size: 0=small, 1=large > # Hist: Histology: 1=squamous cells, 2=other types of cells > # Treat: 0=control (saline), 1=BCG > attach( Lung ) > > Lsurv <- with( Lung, Surv(Days,Death)) # makes survival analysis data ################################# > coxfitSTAGET <- coxph( Lsurv ~ STAGET ) # 1=large tumor, 0=small > coxfitSTAGET Call: coxph(formula = Lsurv ~ STAGET) coef exp(coef) se(coef) z p STAGET 0.496 1.64 0.141 3.52 0.00043 Likelihood ratio test=12.5 on 1 df, p=0.000413 n= 401 > ############################################## > coxfitTreat <- coxph( Lsurv ~ Treat ) # 0=saline, 1=BCG > coxfitTreat Call: coxph(formula = Lsurv ~ Treat) coef exp(coef) se(coef) z p Treat 0.0755 1.08 0.140 0.538 0.59 Likelihood ratio test=0.29 on 1 df, p=0.59 n= 401 > ######################################################### > coxfitBOTH <- coxph( Lsurv ~ Treat + STAGET ) > coxfitBOTH Call: coxph(formula = Lsurv ~ Treat + STAGET) coef exp(coef) se(coef) z p Treat 0.0832 1.09 0.140 0.593 0.55000 STAGET 0.4973 1.64 0.141 3.527 0.00042 Likelihood ratio test=12.8 on 2 df, p=0.00164 n= 401 > ############################################################################# > fakeage <- runif(401,min=40,max=70) > coxfitJunk <- coxph( Lsurv ~ STAGET + fakeage ) > coxfitJunk Call: coxph(formula = Lsurv ~ STAGET + fakeage) coef exp(coef) se(coef) z p STAGET 0.49715 1.644 0.14102 3.525 0.00042 fakeage -0.00292 0.997 0.00813 -0.359 0.72000 Likelihood ratio test=12.6 > > on 2 df, p=0.00184 n= 401 1 > hazard <- basehaz( coxfitSTAGET ) > names(hazard) [1] "hazard" "time" > plot(hazard$time, hazard$hazard, type="l",xlab="days",ylab="baseline hazard") > title(main="baseline hazard for Cox Proportional model (STAGET)") > 0.4 0.0 0.2 baseline hazard 0.6 0.8 baseline hazard for Cox Proportional model (STAGET) 0 500 1000 1500 2000 2500 3000 days > > coxfitTRTstrataSTG <- coxph( Lsurv ~ Treat + strata(STAGET) ) > coxfitTRTstrataSTG Call: coxph(formula = Lsurv ~ Treat + strata(STAGET)) coef exp(coef) se(coef) z p Treat 0.0827 1.09 0.140 0.59 0.56 Likelihood ratio test=0.35 on 1 df, p=0.555 n= 401 > hazard2 <- basehaz( coxfitTRTstrataSTG ) > names( hazard2 ) [1] "hazard" "time" "strata" > > windows() > plot( hazard2$time, hazard2$hazard, type="n", xlab="days",ylab="baseline hazard") > points( hazard2$time[hazard2$strata=="STAGET=0"], + hazard2$hazard[hazard2$strata=="STAGET=0"], type="l" ) > points( hazard2$time[hazard2$strata!="STAGET=0"], + hazard2$hazard[hazard2$strata!="STAGET=0"], type="l", lty=2 ) > legend( 250,1, legend=c("Staget=0","Staget=1"),lty=c(1,2)) > title(main="baseline hazard for Cox Proportional model") 1.0 baseline hazard for Cox Proportional model 0.6 0.4 0.2 0.0 baseline hazard 0.8 Staget=0 Staget=1 0 500 1000 1500 2000 2500 3000 days 2 # Demonstration of Cox Proportional Hazard model library( survival ) # Library of survival analysis functions # Get Afifi's text book lung cancer data Lung <- read.table("http://users.humboldt.edu/rizzardi/Data.dir/Surv.txt", header=F, na.strings=".") names(Lung) <c("ID","STAGET","Stagen","Hist","Treat","Perfbl","Poinf","Smokfu","Smokbl","Days","Death") # # # # Death: 0 = Alive(censored), 1=Dead STAGET: Tumor size: 0=small, 1=large Hist: Histology: 1=squamous cells, 2=other types of cells Treat: 0=control (saline), 1=BCG attach( Lung ) Lsurv <- with( Lung, Surv(Days,Death)) # makes survival analysis data coxfitSTAGET <- coxph( Lsurv ~ STAGET ) # 1=large tumor, 0=small coxfitSTAGET coxfitTreat <- coxph( Lsurv ~ Treat ) # 0=saline, 1=BCG coxfitTreat coxfitBOTH <- coxph( Lsurv ~ Treat + STAGET ) coxfitBOTH fakeage <- runif(401,min=40,max=70) coxfitJunk <- coxph( Lsurv ~ STAGET + fakeage ) coxfitJunk hazard <- basehaz( coxfitSTAGET ) names(hazard) plot(hazard$time, hazard$hazard, type="l",xlab="days",ylab="baseline hazard") title(main="baseline hazard for Cox Proportional model (STAGET)") coxfitTRTstrataSTG <- coxph( Lsurv ~ Treat + strata(STAGET) ) hazard2 <- basehaz( coxfitTRTstrataSTG ) names( hazard2 ) windows() plot( hazard2$time, hazard2$hazard, type="n", xlab="days",ylab="baseline hazard") points( hazard2$time[hazard2$strata=="STAGET=0"], hazard2$hazard[hazard2$strata=="STAGET=0"], type="l" ) points( hazard2$time[hazard2$strata!="STAGET=0"], hazard2$hazard[hazard2$strata!="STAGET=0"], type="l", lty=2 ) legend( 250,1, legend=c("Staget=0","Staget=1"),lty=c(1,2)) title(main="baseline hazard for Cox Proportional model") 3