msm
model fit, where observations
represent the exact transition times of the process, to counting process
data.
This enables, for example, flexible parametric multi-state models to
be fitted with flexsurvreg
from the
coxph
and the msm2Surv(data, subject, time, state, covs, Q)
msm
model fit with exacttimes=TRUE
or all obstype=2
.
Each row represents an observation of a state, and the time variable
contains Q
should have $(r,s)$ entry 0"msdata"
, with rows representing observed or censored transitions.
There will be one row for each observed transition in the original
data, and additional rows for every potential transition that could have
occurred out of each observed state.The data frame will have columns called:
Tstop
- Tstart
"id"
, "from"
, "to"
, "Tstart"
, "Tstop"
, "time"
, "status"
or "trans"
) have ".2"
appended to their names. The transition matrix in trans
attribute of the returned object. See the example code below.
msm
look like this: subj
days
status
age
treat
1 0 1 66 1
1 27 2 66 1
1 75 3 66 1
1 97 4 66 1
1 1106 4 69 1
2 0 1 49 0
2 90 2 49 0
2 1037 2 51 0
}
then the output of msm2Surv
will be a data frame looking like this:
id
from
to
Tstart
Tstop
time
status
age
treat
trans
1 1 2 0 27 27 1 66 1 1
1 1 4 0 27 27 0 66 1 2
1 2 3 27 75 48 1 66 1 3
1 2 4 27 75 48 0 66 1 4
1 3 4 75 97 22 1 69 1 5
2 1 2 0 90 90 1 49 0 1
2 1 4 0 90 90 0 49 0 2
2 2 3 90 1037 947 0 49 0 3
2 2 4 90 1037 947 0 49 0 4
}
At 27 days, subject 1 is observed to move from state 1 to state 2 (first row, status 1), which means that their potential transition from state 1 to state 4 is censored (second row, status 0).
See the
Liesbeth C. de Wreede, Marta Fiocco, Hein Putter (2011).
Jackson, C. H. (2014). flexsurv: Flexible parametric survival and multi-state models. R package version 0.5.
msprep
, in msmdat <- data.frame(
subj = c(1, 1, 1, 1, 1, 2, 2, 2),
days = c(0, 27, 75, 97, 1106, 0, 90, 1037),
status = c(1, 2, 3, 4, 4, 1, 2, 2),
age = c(66, 66, 66, 66, 69, 49, 49, 51),
treat = c(1, 1, 1, 1, 1, 0, 0, 0)
)
# transitions only allowed to next state up or state 4
Q <- rbind(c(1, 1, 0, 1),
c(0, 1, 1, 1),
c(0, 0, 1, 1),
c(0, 0, 0, 0))
dat <- msm2Surv(data=msmdat, subject="subj", time="days", state="status",
Q=Q)
dat
attr(dat, "trans")
Run the code above in your browser using DataLab