# PRACTICAL EXERCISE 5 # ==================== # Read bonemarrow transplantation data: bonemarrow=read.table("http://www.uio.no/studier/emner/matnat/math/STK4080/h12/bone-marrow.txt",header=T) # We use the mstate package, so this has to be installed and loaded. # We first define the possible transitions between the three states # state 1: transplanted, state 2: platelets recovered, and 3: dead tmat=transMat(list(c(2, 3), c(3), c()), names = c("transplanted", "recovered", "relapsed.dead")) # We then convert the data-frame to long format, where there are 2-3 lines # for each person (depending on the trasitions they make): bonemarrowlong=msprep(time=c(NA,"TP","T2"), status=c(NA,"P","DF"), data=bonemarrow,trans=tmat) # We then fit a stratified cox-model with no covariates, extract the # cumulative transition intensities and make a plot of these cox.bm=coxph(Surv(Tstart,Tstop,status)~strata(trans),data=bonemarrowlong, method="breslow") haz.bm=msfit(cox.bm,trans=tmat) plot(haz.bm,xlab="Days post-transplant",xlim=c(0,1000)) # We the obtain the estimated transition probabilities prob.bm=probtrans(haz.bm,predt=0) # We may list the estimated transition probabilities from state 1 by: prob.bm[[1]] # And similarily from state 2: prob.bm[[2]] # The transition probabilities may be plotted in a stacked manner: plot(prob.bm,type="stacked",ord=c(2,1,3)) # Or they may be plotted as separate estimates: plot(prob.bm,type="single",xlim=c(0,1000)) # To compute estimates with (e.g.) s = 14 you give the command: prob.bm=probtrans(haz.bm,predt=14) # The plotting comands remain unchanged