flexsurvreg
.sim.fmsm(x, trans, t, newdata=NULL, start=1, M=10, tvar="trans",
tcovs=NULL, debug=FALSE)
flexsurvreg
. See
msfit.flexsurvreg
for the required form of the model and
the data.
Alternatively x
can bmsfit.flexsurvreg
.M
individuals, to simulate trajectories until.msfit.flexsurvreg
.M
individuals.x
is a list of models.newdata
, i.e. those whose values change at the
same rate as time. Age is a typical example. During simulation, their
values will be updated after each transition time, by adst
and t
. The rows of each
matrix represent simulated individuals. The columns of t
contain the
times when the individual changes state, to the corresponding states in
st
.
The first columns will always contain the starting states and the
starting times. The last column of t
represents either the
time when the individual moves to an absorbing state, or right-censoring
in a transient state at the time given in the t
argument to sim.fmsm
.sim.fmsm
relies on the presence of a function to sample random
numbers from the parametric survival distribution used in the fitted
model x
, for example rweibull
for Weibull models.
If x
was fitted using a custom distribution,
called dist
say, then there must be a function called (something like)
rdist
either in the working environment, or supplied through the
dfns
argument to flexsurvreg
. This must be in the same
format as standard R functions such as rweibull
, with first argument
n
, and remaining arguments giving the parameters of the
distribution. It must be vectorised with respect to the parameter arguments.
This function is only valid for semi-Markov ("clock-reset") models,
though no warning or error is currently given if the model is not of
this type. An equivalent for time-inhomogeneous Markov ("clock-forward")
models has currently not been implemented.
Note the random sampling method for flexsurvspline
models is
currently very inefficient, so that looping over the M
individuals will be very slow.pmatrix.simfs
,totlos.simfs
bexp <- flexsurvreg(Surv(years, status) ~ trans, data=bosms3, dist="exp")
tmat <- rbind(c(NA,1,2),c(NA,NA,3),c(NA,NA,NA))
sim.fmsm(bexp, M=10, t=5, trans=tmat)
Run the code above in your browser using DataLab