totlos.msm(x, start=1, end=NULL, fromt=0, tot=Inf, covariates="mean",
piecewise.times=NULL, piecewise.covariates=NULL,
num.integ=FALSE, discount=0, env=FALSE,
ci=c("none","normal","bootstrap"), cl=0.95, B=1000,
cores=NULL, ...)
envisits.msm(x, start=1, end=NULL, fromt=0, tot=Inf, covariates="mean",
piecewise.times=NULL, piecewise.covariates=NULL,
num.integ=FALSE, discount=0,
ci=c("none","normal","bootstrap"), cl=0.95, B=1000,
cores=NULL, ...)
msm
."mean"
, denoting the means of the covariates in
the data (this is the default),
the number 0
, indicating that all the covariates should be
set to zero,pmatrix.piecewise.msm
for how to specify
this. This is only required for time-inhomogeneous models specified
using explicipmatrix.piecewise.msm
for how to
specify this.totlos.msm
.
If TRUE
, return the expected number of visits to
each state. If FALSE
, return the total length of stay in each
state.
"normal"
, then calculate a confidence interval
by simulating B
random vectors
from the asymptotic multivariate normal distribution implied by the
maximum likelihood estimates (and covariance matrix) of the log
boot.msm
for more details.integrate
function to control the numerical
integration.totlos.msm
),
or expected number of visits (envisits.msm
), for each
transient state.The corresponding expected number of visits to state $j$ is $\sum_{i=j} T_i Q_{i,j}$ (excluding the stay in the current state at time 0).
More generally, suppose that $\pi_0$
is the vector of probabilities of being in each state at time 0,
supplied in start
, and we want the vector $\mathbf{x}$ giving the expected
lengths of stay in each state. The corresponding integral has the
following solution (van Loan 1978; van Rosmalen et al. 2013)
$$\mathbf{x} = \left[\begin{array}{ll}1 & \mathbf{0}_K \end{array}\right] Exp(t Q') \left[\begin{array}{ll} \mathbf{0}_K\I_K \end{array}\right]$$
where $$Q' = \left[\begin{array}{ll} 0 & \mathbf{\pi}_0\ \mathbf{0}_K & Q - rI_K\end{array}\right]$$
$\pi_0$ is the row vector of initial state probabilities
supplied in start
, $\mathbf{0}_K$ is
the row vector of K zeros, $r$ is the discount rate, $I_K$ is the K x K identity matrix, and
$Exp$ is the matrix exponential.
Alternatively, the integrals can be calculated numerically, using the
integrate
function. This may take a long time for
models with many states where $P(t)$ is expensive to calculate.
This is required where tot = Inf
, since the package author is
not aware of any analytic expression for the limit of the above
formula as $t$ goes to infinity.
With the argument num.integ=TRUE
, numerical integration is used
even where the analytic solution is available. This facility is just
provided for checking results against versions 1.2.4 and earlier, and
will be removed eventually. Please let the package maintainer know if
any results are different.
For a model where the individual has only one place to go from each state, and each state is visited only once, for example a progressive disease model with no recovery or death, these are equal to the mean sojourn time in each state. However, consider a three-state health-disease-death model with transitions from health to disease, health to death, and disease to death, where everybody starts healthy. In this case the mean sojourn time in the disease state will be greater than the expected length of stay in the disease state. This is because the mean sojourn time in a state is conditional on entering the state, whereas the expected total time diseased is a forecast for a healthy individual, who may die before getting the disease.
In the above formulae, $Q$ is assumed to be constant over time,
but the results generalise easily to piecewise-constant intensities.
This function automatically handles models fitted using the pci
option to msm
. For any other inhomogeneous models, the
user must specify piecewise.times
and
piecewise.covariates
arguments to totlos.msm
.
J. van Rosmalen, M. Toy and J.F. O'Mahony (2013). A mathematical approach for evaluating Markov models in continuous time without discrete-event simulation. Medical Decision Making 33:767-779.
sojourn.msm
, pmatrix.msm
, integrate
, boot.msm
.