For a given multi-state model, specified through a transition matrix,
paths
recursively finds all the possible trajectories or paths
through that multi-state starting from a specified state. DO NOT USE for
reversible or cyclic multi-state models.
paths(trans, start = 1)
trans | The transition matrix describing the multi-state model, see
|
---|---|
start | The starting state for the trajectories |
A matrix, each row of which specifies a possible path through the multi-state model.
The function is recursive. It starts in start
, looks at what states
can be visited from start
, and appends the results of the next call
to the current value (matrix). If the transition matrix contains loops, the
function will find infinitely many paths, so do not use paths
for
reversible or cyclic multi-state models. A warning is not yet incorporated!
Hein Putter <H.Putter@lumc.nl>
tmat <- matrix(NA,5,5) tmat[1,2:3] <- 1:2 tmat[1,5] <- 3 tmat[2,4:5] <- 4:5 tmat[3,4:5] <- 6:7 tmat[4,5] <- 8 paths(tmat)#> [,1] [,2] [,3] [,4] #> [1,] 1 NA NA NA #> [2,] 1 2 NA NA #> [3,] 1 2 4 NA #> [4,] 1 2 4 5 #> [5,] 1 2 5 NA #> [6,] 1 3 NA NA #> [7,] 1 3 4 NA #> [8,] 1 3 4 5 #> [9,] 1 3 5 NA #> [10,] 1 5 NA NApaths(tmat, start=3)#> [,1] [,2] [,3] #> [1,] 3 NA NA #> [2,] 3 4 NA #> [3,] 3 4 5 #> [4,] 3 5 NA