predict_tp {icmstate} | R Documentation |
Calculate subject specific transition probabilities from a multi-state proportional hazards model.
Description
Given a coxph model fit on multi-state data (prepared with msprep
),
determine transition probabilities for subjects in newdata
.
Usage
predict_tp(
object,
predt,
direction = c("forward", "fixedhorizon"),
newdata,
trans
)
Arguments
object |
A |
predt |
A positive number indicating the prediction time. This is either
the time at which the prediction is made (if |
direction |
One of |
newdata |
A
Note that newdata must contain a column containing the variable which was
used to determine the stratum of a transition in |
trans |
A transition matrix as created by |
Details
When using this function for newdata
with many subjects, consider running the
function multiple times for parts of newdata
to negate the risk of
running our of memory.
Using this function, it is only possible to consider models with transition specific covariates.
If you would like to have covariates shared over transitions or proportional
hazards assumptions between transitions, see probtrans_coxph
.
Value
An object of class "probtrans.subjects"
.
This is a list of length n (number of subjects in newdata), with each list element
an object of class probtrans
for the associated
subject. List elements can be accessed using [[x]]
, with x
ranging from 1 to n. Additionally, each list element
has an element $id
, representing the subject id and the output object
also has an element $subject_ids
representing the subject ids in order.
See Also
probtrans_coxph
, plot.probtrans.subjects
,
summary.probtrans.subjects
Examples
#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.
}