Chapter 11 - Joint Analysis of Longitudinal and Survival Data
Slides
Lecture slides here. (To convert html to pdf, press E \(\to\) Print \(\to\) Destination: Save to pdf)
Base R Code
Show the code
################################################################### This code generates all numerical results in chapter 11. ################################################################################################################################# Analysis of the anti-retroviral drug trial#############################################################load required packageslibrary(nlme) # for linear mixed effects modellibrary(survival)# read in the study datasetdata <-read.table("Data//Anti-retroviral Trial//aids.txt")head(data)#load the JM packageinstall.packages("JM")library(JM)###################################################### Figure 11.2 Histograms of CD4 count and square-root# transformation#####################################################par(mfrow=c(1,2))hist(data$CD4,xlab="CD4 count", main ="", lwd=2)hist(sqrt(data$CD4),xlab="Square root of CD4 count",main="",lwd=2)# taking square root of CD4 countdata$y <-sqrt(data$CD4)# create a de-duplicated data for survival sub-modeldata.surv <- data[!duplicated(data$id),]# Joint model fit for the HIV/AIDS dataset# longitudinal sub-modellongit.sub <-lme(y ~ obsmo + obsmo:drug + sex + hist,random =~ obsmo|id, data = data)# survival sub-modelsurv.sub <-coxph(Surv(time, status) ~ drug + sex + hist,data = data.surv, x =TRUE)# combine the two models# piecewise linear baseline with six internal knotsjoint.model <-jointModel(longit.sub, surv.sub,timeVar ="obsmo",method ="piecewise-PH-aGH")joint.model$coefficients# print out the summarysummary(joint.model)####################################### Figure 11.3####################################### compute the mean trajectories based on the longitudinal# sub-model resultst <- (0:180)/10g0 <-2.2123g1 <--0.0414g3 <-0.9153g4 <-0.0061ddC.nonhist <- (g0+g3+g1*t)^2ddC.hist <- (g0+g1*t)^2ddI.nonhist <- (g0+g3+(g1+g4)*t)^2ddI.hist <- (g0+(g1+g4)*t)^2######################################################## Figure 11.3# Model-based estimates of the mean trajectories# of CD4 count for female patients by treatment# group and previous infection status. Solid, ddC;# dotted, ddI######################################################par(mfrow=c(1,2))plot(t, ddC.nonhist,type='l',frame.plot=F,main="No previous infection",xlim=c(0,20),ylim=c(0,10),xlab="Time (months)", ylab="Mean CD4 cell count", lwd=2, cex.main =1)lines(t,ddI.nonhist,lty=3,lwd=2)plot(t, ddC.hist,type='l',frame.plot=F,main="Previous infection",xlim=c(0,20),ylim=c(0,10),xlab="Time (months)", ylab="Mean CD4 cell count", lwd=2, cex.main =1)lines(t,ddI.hist,lty=3,lwd=2)