Expected time until first reaching a particular state or set of states in a Markov model.
1 2 3 
x 
A fitted multistate model, as returned by

qmatrix 
Instead of 
tostate 
State, or set of states supplied as a vector, for which to estimate the first passage time into. Can be integer, or character matched to the row names of the Q matrix. 
start 
Starting state (integer). By default ( Alternatively, this can be used to obtain the expected first passage
time from a set of states, rather than single states. To
achieve this, 
covariates 
Covariate values defining the intensity matrix for
the fitted model 
ci 
If If If 
cl 
Width of the symmetric confidence interval, relative to 1. 
B 
Number of bootstrap replicates. 
cores 
Number of cores to use for bootstrapping using parallel
processing. See 
... 
Arguments to pass to 
The expected first passage times from each of a set of states i to to the remaining set of states ibar in the state space, for a model with transition intensity matrix Q, are
Q_{i,i}^{1} 1
where 1 is a vector of ones, and Q_{i,i} is the square subset of Q pertaining to states i.
It is equal to the sum of mean sojourn times for all states
between the "from" and "to" states in a unidirectional model.
If there is nonzero chance of reaching an absorbing state
before reaching tostate
, then it is infinite. It is
trivially zero if the "from" state equals tostate
.
This function currently only handles timehomogeneous Markov models. For timeinhomogeneous models it will assume that Q equals the average intensity matrix over all times and observed covariates. Simulation might be used to handle time dependence.
Note this is the expectation of first passage time, and the
confidence intervals are CIs for this mean, not predictive intervals
for the first passage time. The full distribution of the first
passage time to a set of states can be obtained by setting the rows of
the intensity matrix Q corresponding to that set of states to
zero to make a model where those states are absorbing. The
corresponding transition probability matrix Exp(Qt) then gives
the probabilities of having hit or passed that state by a time t
(see the example below). This is implemented in
ppass.msm
.
A vector of expected first passage times, or "hitting times", from each state to the desired state.
C. H. Jackson chris.jackson@mrcbsu.cam.ac.uk
Norris, J. R. (1997) Markov Chains. Cambridge University Press.
sojourn.msm
, totlos.msm
, boot.msm
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  twoway4.q < rbind(c(0.5, 0.25, 0, 0.25), c(0.166, 0.498, 0.166, 0.166),
c(0, 0.25, 0.5, 0.25), c(0, 0, 0, 0))
efpt.msm(qmatrix=twoway4.q, tostate=3)
# given in state 1, expected time to reaching state 3 is infinite
# since may die (state 4) before entering state 3
# If we remove the death state from the model, EFPTs become finite
Q < twoway4.q[1:3,1:3]; diag(Q) < 0; diag(Q) < rowSums(Q)
efpt.msm(qmatrix=Q, tostate=3)
# Suppose we cannot die or regress while in state 2, can only go to state 3
Q < twoway4.q; Q[2,4] < Q[2,1] < 0; diag(Q) < 0; diag(Q) < rowSums(Q)
efpt.msm(qmatrix=Q, tostate=3)
# The expected time from 2 to 3 now equals the mean sojourn time in 2.
1/Q[2,2]
# Calculate cumulative distribution of the first passage time
# into state 3 for the following threestate model
Q < twoway4.q[1:3,1:3]; diag(Q) < 0; diag(Q) < rowSums(Q)
# Firstly form a model where the desired hitting state is absorbing
Q[3,] < 0
MatrixExp(Q, t=10)[,3]
ppass.msm(qmatrix=Q, tot=10)
# Given in state 1 at time 0, P(hit 3 by time 10) = 0.479
MatrixExp(Q, t=50)[,3] # P(hit 3 by time 50) = 0.98
ppass.msm(qmatrix=Q, tot=50)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
All documentation is copyright its authors; we didn't write any of that.