#Chapter 6 library(survival) # Proportionality. # Test interactions of covariates and log(t) and look for significance at .05. If significant # then not proportional. # Notes on Schoenfeld residuals: If covariate has a proportional hazard over time then the # the plot of the scaled Schoenfeld residuals and its smoothed line should show no trend over # time. (Slope should approximate zero!.) # Using the UIS data again. #Continuing the analysis of the model developed in Chapter 4. #Creating the necessary dummy variables (ivhx3 and ndrugfp1) as well as interaction # variables with log(time). uis$ivhx3[uis$ivhx>0] <- 1*(uis$ivhx==3) uis$ndrugfp1 <- 1/((uis$ndrugtx+1)/10) uis$ndrugfp2 <- (1/((uis$ndrugtx+1)/10))*log((uis$ndrugtx+1)/10) #Model from table 5.11 table5.11 <- coxph(formula=Surv(time, censor)~age+ becktota+ ndrugfp1+ ndrugfp2+ ivhx3+ race+ treat+ site+ age:site + race:site, data=uis, method="breslow", na.action=na.exclude) print(summary(table5.11)) print(table5.11) #Testing for proportionality. zph.table5.11 <- cox.zph(table5.11, transform = 'log') print(zph.table5.11) #Fig. 6.4, p. 215 windows(6,6) plot(zph.table5.11[1]) abline(h=0, lty=3) windows(6,6) p2 <- plot(zph.table5.11[2]) abline(h=0, lty=3) windows(6,6) p3 <- plot(zph.table5.11[3]) abline(h=0, lty=3) windows(6,6) p5 <- plot(zph.table5.11[5]) abline(h=0, lty=3) windows(6,6) p6 <- plot(zph.table5.11[6]) abline(h=0, lty=3) windows(6,6) p7 <- plot(zph.table5.11[7]) abline(h=0, lty=3) windows(6,6) p8 <- plot(zph.table5.11[8]) abline(h=0, lty=3) windows(6,6) p10 <- plot(zph.table5.11[10]) abline(h=0, lty=3) #Fig. 6.5, p. 217. # First we run the cox model and then we compute the Score residuals by specifying the option # type to equal "score". The object score is a matrix and not a data set so in order to have the # residuals in the uis data set we set new variables to be equal to the specific columns of the matrix # which corresponds to the residuals for specific variables. So, the first column of the matrix score # contains the residuals for the varaible age and therefore we set the new variable residage to equal this # column of the matrix. table511.ph <- coxph(formula=Surv(time, censor)~age+ becktota+ ndrugfp1+ ndrugfp2+ ivhx3+ race+ treat+ site+ agesite + racesite, data=uis, method="breslow", na.action=na.exclude) score <- resid(table511.ph, type="score") windows(6,6) plot(uis$age, score[,1], ylab="Score Residuals", xlab="AGE") windows(6,6) plot(uis$becktota, score[,2], ylab="Score Residuals", xlab="BECKTOTA") windows(6,6) plot(uis$ndrugtx, score[,3], ylab="Score Residuals", xlab="NDRUGTX") windows(6,6) plot(uis$age, score[ ,9], ylab="Score Residuals", xlab="AGE by SITE Interaction")