#Example from the mstate vignette
#We determine the subject specific transition probabilities for subjects
#in the ebmt3 data-set
if(require("mstate")){
data(ebmt3)
n <- nrow(ebmt3)
tmat <- transMat(x = list(c(2, 3), c(3), c()), names = c("Tx",
"PR", "RelDeath"))
#From days to years
ebmt3$prtime <- ebmt3$prtime/365.25
ebmt3$rfstime <- ebmt3$rfstime/365.25
#Covariates we will use
covs <- c("dissub", "age", "drmatch", "tcd", "prtime")
msbmt <- msprep(time = c(NA, "prtime", "rfstime"), status = c(NA,
"prstat", "rfsstat"), data = ebmt3, trans = tmat, keep = covs)
#Expand covariates so that we can have transition specific covariates
msbmt2 <- expand.covs(msbmt, covs, append = TRUE, longnames = FALSE)
#-------------Model---------------------#
#Simple model, transition specific covariates, each transition own baseline hazard
c1 <- coxph(Surv(Tstart, Tstop, status) ~ dissub1.1 + dissub2.1 +
age1.1 + age2.1 + drmatch.1 + tcd.1 + dissub1.2 + dissub2.2 +
age1.2 + age2.2 + drmatch.2 + tcd.2 + dissub1.3 + dissub2.3 +
age1.3 + age2.3 + drmatch.3 + tcd.3 + strata(trans), data = msbmt2,
method = "breslow")
#Predict transition probabilities for first 30 subjects.
tp_subjects <- predict_tp(c1, predt = 0, direction = "forward",
newdata = ebmt3[1:30,], trans = tmat)
#Now we can plot the transition probabilities for each subject separately:
plot(tp_subjects, id = 1)
#tp_subjects has length number of subjects in newdata + 1
#And tp_subjects[[i]] is an object of class "probtrans", so you can
#use all probtrans functions: summary, plot etc.
}
Run the code above in your browser using DataLab