Closed ghost closed 3 years ago
would love to have this functionality!
Apologies for the late reply.
It is straightforward to adapt the markov_msm
function to allow for competing risks. As an example (now added to the documentation for markov_msm
):
competing_risks <- function(listOfModels, ...) {
nRisks = length(listOfModels)
transmat = matrix(NA,nRisks+1,nRisks+1)
transmat[1,1+(1:nRisks)] = 1:nRisks
rownames(transmat) <- colnames(transmat) <- c("Initial",names(listOfModels))
rstpm2::markov_msm(listOfModels, ..., trans = transmat)
}
recurrence = gsm(Surv(time,status)~factor(rx), data=survival::colon, subset=(etype==1), df=3)
death = gsm(Surv(time,status)~factor(rx), data=survival::colon, subset=(etype==2), df=3)
cr = competing_risks(list(Recurrence=recurrence,Death=death),
newdata=data.frame(rx=levels(survival::colon$rx)),
t = seq(0,2500, length=301))
plot(cr, ggplot=TRUE) + facet_grid(~ rx)
cr_diff = diff(subset(cr,rx=="Lev+5FU"),subset(cr,rx=="Obs"))
plot(cr_diff, ggplot=TRUE, stacked=FALSE)
The first argument for competing_risks
is a list of models. Names from that list are used for labelling the states. The other arguments are as per the markov_msm
function, except for the transition matrix, which is defined by the competing_risks
function. For the example, we plot the probabilities of being in each of the three states for three different treatment arms. We also plot the difference in probabilities.
Is this helpful?
Sincerely, Mark.
Hi,
This might be a very naive question, but can this package fit models for competing risks like Stata's
stpm2cr
module? That is rather than fitting separate models for each competing, fit a full likelihood model with all competing risks. If we have only two competing risks, I don't think it would make much difference, would it?Thanks.