Given cumulative transition hazards sample paths through the multi-state model.
Arguments
- Haz
Cumulative hazards to be sampled from. These should be given as a data frame with columns
time
,Haz
,trans
, for instance as theHaz
list element given bymsfit
.- trans
Transition matrix describing the multi-state model. See
trans
inmsprep
for more detailed information- history
A list with elements
state
, specifying the starting state(s),time
, the starting time(s), andtstate
, a numeric vector of length the number of states, specifying at what times states have been visited, if appropriate. The default oftstate
isNULL
; more information can be found under Details.The elements
state
andtime
may either be scalars or vectors, in which case different sampled paths may start from different states or at different times. By default, all sampled paths start from state 1 at time 0.- beta.state
A matrix of dimension (no states) x (no transitions) specifying estimated effects of times at which earlier states were reached on subsequent transitions. If these are not in the model, the value
NULL
(default) suffices; more information can be found under Details- clock
Character argument, either
"forward"
(default) or"reset"
, specifying whether the time-scale of the cumulative hazards is in forward time ("forward"
) or duration in the present state ("reset"
)- output
One of
"state"
,"path"
, or"data"
, specifying whether states, paths, or data should be output.- tvec
A numeric vector of time points at which the states or paths should be evaluated. Ignored if
output
="data"
- cens
An independent censoring distribution, given as a data frame with time and Haz
- M
The number of sampled trajectories through the multi-state model. The default is 10, since the procedure can become quite time-consuming
- do.trace
An integer, specifying that the replication number should be written to the console every
do.trace
replications. Default isNULL
in which case no output is written to the console during the simulation
Value
M simulated paths through the multi-state model given by
trans
and Haz
. It is either a data frame with columns
time
, pstate1
, ..., pstateS
for S states when
output="state"
, or with columns time
, ppath1
,...,
ppathP
for the P paths specified in paths
(trans) when
output="path"
. When output="data"
, the sampled paths are
stored in an "msdata"
object, a data frame in long format such as
that obtained by msprep
. This may be useful for
(semi-)parametric bootstrap procedures, in which case cens
may be
used as censoring distribution (assumed to be independent of all transition
times and independent of any covariates).
Details
The procedure is described in detail in Fiocco, Putter & van Houwelingen
(2008). The argument beta.state
and the element tstate
from
the argument history
are meant to incorporate situations where the
time at which some previous states were visited may affect future transition
rates. The relation between time of visit of state s
and transition
k
is assumed to be linear on the log-hazards; the corresponding
regression coefficient is to be supplied as the (s,k)-element of
beta.state
, which is 0 if no such effect has been included in the
model. If no such effects are present, then beta.state
=NULL
(default) suffices. In the tstate
element of history
, the
s
-th element is the time at which state s
was visited. This is
only relevant for states which have been visited prior to the beginning of
sampling, i.e. before the time
element of history
; the
elements of tstate
are internally updated when in the sampling
process new states are visited (only if beta.state
is not NULL
to avoid unnecessary computations).
References
Fiocco M, Putter H, van Houwelingen HC (2008). Reduced-rank proportional hazards regression and simulation-based prediction for multi-state models. Statistics in Medicine 27, 4340–4358.
Author
Marta Fiocco, Hein Putter H.Putter@lumc.nl
Examples
# transition matrix for illness-death model
tmat <- trans.illdeath()
# data in wide format, for transition 1 this is dataset E1 of
# Therneau & Grambsch (T&G)
tg <- data.frame(illt=c(1,1,6,6,8,9),ills=c(1,0,1,1,0,1),
dt=c(5,1,9,7,8,12),ds=c(1,1,1,1,1,1),
x1=c(1,1,1,0,0,0),x2=c(6:1))
# data in long format using msprep
tglong <- msprep(time=c(NA,"illt","dt"),status=c(NA,"ills","ds"),
data=tg,keep=c("x1","x2"),trans=tmat)
# expanded covariates
tglong <- expand.covs(tglong,c("x1","x2"))
# Cox model with different covariate
cx <- coxph(Surv(Tstart,Tstop,status)~x1.1+x2.2+strata(trans),
data=tglong,method="breslow")
# new data, to check whether results are the same for transition 1 as T&G
newdata <- data.frame(trans=1:3,x1.1=c(0,0,0),x2.2=c(0,1,0),strata=1:3)
fit <- msfit(cx,newdata,trans=tmat)
tv <- unique(fit$Haz$time)
# mssample
set.seed(1234)
mssample(Haz=fit$Haz,trans=tmat,tvec=tv,M=100)
#> time pstate1 pstate2 pstate3
#> 1 1 0.91 0.07 0.02
#> 2 5 0.91 0.00 0.09
#> 3 6 0.69 0.22 0.09
#> 4 7 0.69 0.11 0.20
#> 5 8 0.53 0.11 0.36
#> 6 9 0.00 0.53 0.47
#> 7 12 0.00 0.00 1.00
set.seed(1234)
paths(tmat)
#> [,1] [,2] [,3]
#> [1,] 1 NA NA
#> [2,] 1 2 NA
#> [3,] 1 2 3
#> [4,] 1 3 NA
mssample(Haz=fit$Haz,trans=tmat,tvec=tv,M=100,output="path")
#> time ppath1 ppath2 ppath3 ppath4
#> 1 1 0.91 0.07 0.00 0.02
#> 2 5 0.91 0.00 0.07 0.02
#> 3 6 0.69 0.22 0.07 0.02
#> 4 7 0.69 0.11 0.18 0.02
#> 5 8 0.53 0.11 0.18 0.18
#> 6 9 0.00 0.53 0.29 0.18
#> 7 12 0.00 0.00 0.82 0.18
set.seed(1234)
mssample(Haz=fit$Haz,trans=tmat,tvec=tv,M=100,output="data",do.trace=25)
#> Replication 25 finished at Fri Nov 29 16:41:23 2024
#> Replication 50 finished at Fri Nov 29 16:41:23 2024
#> Replication 75 finished at Fri Nov 29 16:41:23 2024
#> Replication 100 finished at Fri Nov 29 16:41:23 2024
#> An object of class 'msdata'
#>
#> Data:
#> id Tstart Tstop duration from to status trans
#> 1 1 0 9 9 1 2 1 1
#> 2 1 0 9 9 1 3 0 2
#> 3 1 9 12 3 2 3 1 3
#> 4 2 0 8 8 1 2 0 1
#> 5 2 0 8 8 1 3 1 2
#> 6 3 0 9 9 1 2 1 1
#> 7 3 0 9 9 1 3 0 2
#> 8 3 9 12 3 2 3 1 3
#> 9 4 0 6 6 1 2 1 1
#> 10 4 0 6 6 1 3 0 2
#> 11 4 6 7 1 2 3 1 3
#> 12 5 0 9 9 1 2 1 1
#> 13 5 0 9 9 1 3 0 2
#> 14 5 9 12 3 2 3 1 3
#> 15 6 0 9 9 1 2 1 1
#> 16 6 0 9 9 1 3 0 2
#> 17 6 9 12 3 2 3 1 3
#> 18 7 0 9 9 1 2 1 1
#> 19 7 0 9 9 1 3 0 2
#> 20 7 9 12 3 2 3 1 3
#> 21 8 0 6 6 1 2 1 1
#> 22 8 0 6 6 1 3 0 2
#> 23 8 6 9 3 2 3 1 3
#> 24 9 0 9 9 1 2 1 1
#> 25 9 0 9 9 1 3 0 2
#> 26 9 9 12 3 2 3 1 3
#> 27 10 0 9 9 1 2 1 1
#> 28 10 0 9 9 1 3 0 2
#> 29 10 9 12 3 2 3 1 3
#> 30 11 0 1 1 1 2 1 1
#> 31 11 0 1 1 1 3 0 2
#> 32 11 1 5 4 2 3 1 3
#> 33 12 0 9 9 1 2 1 1
#> 34 12 0 9 9 1 3 0 2
#> 35 12 9 12 3 2 3 1 3
#> 36 13 0 6 6 1 2 1 1
#> 37 13 0 6 6 1 3 0 2
#> 38 13 6 7 1 2 3 1 3
#> 39 14 0 9 9 1 2 1 1
#> 40 14 0 9 9 1 3 0 2
#> 41 14 9 12 3 2 3 1 3
#> 42 15 0 9 9 1 2 1 1
#> 43 15 0 9 9 1 3 0 2
#> 44 15 9 12 3 2 3 1 3
#> 45 16 0 9 9 1 2 1 1
#> 46 16 0 9 9 1 3 0 2
#> 47 16 9 12 3 2 3 1 3
#> 48 17 0 9 9 1 2 1 1
#> 49 17 0 9 9 1 3 0 2
#> 50 17 9 12 3 2 3 1 3
#> 51 18 0 9 9 1 2 1 1
#> 52 18 0 9 9 1 3 0 2
#> 53 18 9 12 3 2 3 1 3
#> 54 19 0 9 9 1 2 1 1
#> 55 19 0 9 9 1 3 0 2
#> 56 19 9 12 3 2 3 1 3
#> 57 20 0 9 9 1 2 1 1
#> 58 20 0 9 9 1 3 0 2
#> 59 20 9 12 3 2 3 1 3
#> 60 21 0 9 9 1 2 1 1
#> 61 21 0 9 9 1 3 0 2
#> 62 21 9 12 3 2 3 1 3
#> 63 22 0 9 9 1 2 1 1
#> 64 22 0 9 9 1 3 0 2
#> 65 22 9 12 3 2 3 1 3
#> 66 23 0 9 9 1 2 1 1
#> 67 23 0 9 9 1 3 0 2
#> 68 23 9 12 3 2 3 1 3
#> 69 24 0 9 9 1 2 1 1
#> 70 24 0 9 9 1 3 0 2
#> 71 24 9 12 3 2 3 1 3
#> 72 25 0 9 9 1 2 1 1
#> 73 25 0 9 9 1 3 0 2
#> 74 25 9 12 3 2 3 1 3
#> 75 26 0 9 9 1 2 1 1
#> 76 26 0 9 9 1 3 0 2
#> 77 26 9 12 3 2 3 1 3
#> 78 27 0 9 9 1 2 1 1
#> 79 27 0 9 9 1 3 0 2
#> 80 27 9 12 3 2 3 1 3
#> 81 28 0 9 9 1 2 1 1
#> 82 28 0 9 9 1 3 0 2
#> 83 28 9 12 3 2 3 1 3
#> 84 29 0 6 6 1 2 1 1
#> 85 29 0 6 6 1 3 0 2
#> 86 29 6 9 3 2 3 1 3
#> 87 30 0 9 9 1 2 1 1
#> 88 30 0 9 9 1 3 0 2
#> 89 30 9 12 3 2 3 1 3
#> 90 31 0 9 9 1 2 1 1
#> 91 31 0 9 9 1 3 0 2
#> 92 31 9 12 3 2 3 1 3
#> 93 32 0 1 1 1 2 0 1
#> 94 32 0 1 1 1 3 1 2
#> 95 33 0 6 6 1 2 1 1
#> 96 33 0 6 6 1 3 0 2
#> 97 33 6 7 1 2 3 1 3
#> 98 34 0 6 6 1 2 1 1
#> 99 34 0 6 6 1 3 0 2
#> 100 34 6 9 3 2 3 1 3
#> 101 35 0 9 9 1 2 1 1
#> 102 35 0 9 9 1 3 0 2
#> 103 35 9 12 3 2 3 1 3
#> 104 36 0 8 8 1 2 0 1
#> 105 36 0 8 8 1 3 1 2
#> 106 37 0 6 6 1 2 1 1
#> 107 37 0 6 6 1 3 0 2
#> 108 37 6 9 3 2 3 1 3
#> 109 38 0 9 9 1 2 1 1
#> 110 38 0 9 9 1 3 0 2
#> 111 38 9 12 3 2 3 1 3
#> 112 39 0 8 8 1 2 0 1
#> 113 39 0 8 8 1 3 1 2
#> 114 40 0 1 1 1 2 1 1
#> 115 40 0 1 1 1 3 0 2
#> 116 40 1 5 4 2 3 1 3
#> 117 41 0 9 9 1 2 1 1
#> 118 41 0 9 9 1 3 0 2
#> 119 41 9 12 3 2 3 1 3
#> 120 42 0 6 6 1 2 1 1
#> 121 42 0 6 6 1 3 0 2
#> 122 42 6 7 1 2 3 1 3
#> 123 43 0 9 9 1 2 1 1
#> 124 43 0 9 9 1 3 0 2
#> 125 43 9 12 3 2 3 1 3
#> 126 44 0 9 9 1 2 1 1
#> 127 44 0 9 9 1 3 0 2
#> 128 44 9 12 3 2 3 1 3
#> 129 45 0 8 8 1 2 0 1
#> 130 45 0 8 8 1 3 1 2
#> 131 46 0 8 8 1 2 0 1
#> 132 46 0 8 8 1 3 1 2
#> 133 47 0 6 6 1 2 1 1
#> 134 47 0 6 6 1 3 0 2
#> 135 47 6 7 1 2 3 1 3
#> 136 48 0 9 9 1 2 1 1
#> 137 48 0 9 9 1 3 0 2
#> 138 48 9 12 3 2 3 1 3
#> 139 49 0 6 6 1 2 1 1
#> 140 49 0 6 6 1 3 0 2
#> 141 49 6 9 3 2 3 1 3
#> 142 50 0 1 1 1 2 1 1
#> 143 50 0 1 1 1 3 0 2
#> 144 50 1 5 4 2 3 1 3
#> 145 51 0 9 9 1 2 1 1
#> 146 51 0 9 9 1 3 0 2
#> 147 51 9 12 3 2 3 1 3
#> 148 52 0 9 9 1 2 1 1
#> 149 52 0 9 9 1 3 0 2
#> 150 52 9 12 3 2 3 1 3
#> 151 53 0 8 8 1 2 0 1
#> 152 53 0 8 8 1 3 1 2
#> 153 54 0 1 1 1 2 1 1
#> 154 54 0 1 1 1 3 0 2
#> 155 54 1 5 4 2 3 1 3
#> 156 55 0 9 9 1 2 1 1
#> 157 55 0 9 9 1 3 0 2
#> 158 55 9 12 3 2 3 1 3
#> 159 56 0 9 9 1 2 1 1
#> 160 56 0 9 9 1 3 0 2
#> 161 56 9 12 3 2 3 1 3
#> 162 57 0 6 6 1 2 1 1
#> 163 57 0 6 6 1 3 0 2
#> 164 57 6 7 1 2 3 1 3
#> 165 58 0 6 6 1 2 1 1
#> 166 58 0 6 6 1 3 0 2
#> 167 58 6 9 3 2 3 1 3
#> 168 59 0 6 6 1 2 1 1
#> 169 59 0 6 6 1 3 0 2
#> 170 59 6 7 1 2 3 1 3
#> 171 60 0 9 9 1 2 1 1
#> 172 60 0 9 9 1 3 0 2
#> 173 60 9 12 3 2 3 1 3
#> 174 61 0 8 8 1 2 0 1
#> 175 61 0 8 8 1 3 1 2
#> 176 62 0 6 6 1 2 1 1
#> 177 62 0 6 6 1 3 0 2
#> 178 62 6 9 3 2 3 1 3
#> 179 63 0 9 9 1 2 1 1
#> 180 63 0 9 9 1 3 0 2
#> 181 63 9 12 3 2 3 1 3
#> 182 64 0 8 8 1 2 0 1
#> 183 64 0 8 8 1 3 1 2
#> 184 65 0 6 6 1 2 1 1
#> 185 65 0 6 6 1 3 0 2
#> 186 65 6 7 1 2 3 1 3
#> 187 66 0 9 9 1 2 1 1
#> 188 66 0 9 9 1 3 0 2
#> 189 66 9 12 3 2 3 1 3
#> 190 67 0 8 8 1 2 0 1
#> 191 67 0 8 8 1 3 1 2
#> 192 68 0 1 1 1 2 1 1
#> 193 68 0 1 1 1 3 0 2
#> 194 68 1 5 4 2 3 1 3
#> 195 69 0 9 9 1 2 1 1
#> 196 69 0 9 9 1 3 0 2
#> 197 69 9 12 3 2 3 1 3
#> 198 70 0 9 9 1 2 1 1
#> 199 70 0 9 9 1 3 0 2
#> 200 70 9 12 3 2 3 1 3
#> 201 71 0 8 8 1 2 0 1
#> 202 71 0 8 8 1 3 1 2
#> 203 72 0 6 6 1 2 1 1
#> 204 72 0 6 6 1 3 0 2
#> 205 72 6 7 1 2 3 1 3
#> 206 73 0 8 8 1 2 0 1
#> 207 73 0 8 8 1 3 1 2
#> 208 74 0 9 9 1 2 1 1
#> 209 74 0 9 9 1 3 0 2
#> 210 74 9 12 3 2 3 1 3
#> 211 75 0 9 9 1 2 1 1
#> 212 75 0 9 9 1 3 0 2
#> 213 75 9 12 3 2 3 1 3
#> 214 76 0 8 8 1 2 0 1
#> 215 76 0 8 8 1 3 1 2
#> 216 77 0 9 9 1 2 1 1
#> 217 77 0 9 9 1 3 0 2
#> 218 77 9 12 3 2 3 1 3
#> 219 78 0 8 8 1 2 0 1
#> 220 78 0 8 8 1 3 1 2
#> 221 79 0 8 8 1 2 0 1
#> 222 79 0 8 8 1 3 1 2
#> 223 80 0 9 9 1 2 1 1
#> 224 80 0 9 9 1 3 0 2
#> 225 80 9 12 3 2 3 1 3
#> 226 81 0 6 6 1 2 1 1
#> 227 81 0 6 6 1 3 0 2
#> 228 81 6 9 3 2 3 1 3
#> 229 82 0 6 6 1 2 1 1
#> 230 82 0 6 6 1 3 0 2
#> 231 82 6 9 3 2 3 1 3
#> 232 83 0 6 6 1 2 1 1
#> 233 83 0 6 6 1 3 0 2
#> 234 83 6 7 1 2 3 1 3
#> 235 84 0 6 6 1 2 1 1
#> 236 84 0 6 6 1 3 0 2
#> 237 84 6 9 3 2 3 1 3
#> 238 85 0 9 9 1 2 1 1
#> 239 85 0 9 9 1 3 0 2
#> 240 85 9 12 3 2 3 1 3
#> 241 86 0 8 8 1 2 0 1
#> 242 86 0 8 8 1 3 1 2
#> 243 87 0 9 9 1 2 1 1
#> 244 87 0 9 9 1 3 0 2
#> 245 87 9 12 3 2 3 1 3
#> 246 88 0 9 9 1 2 1 1
#> 247 88 0 9 9 1 3 0 2
#> 248 88 9 12 3 2 3 1 3
#> 249 89 0 9 9 1 2 1 1
#> 250 89 0 9 9 1 3 0 2
#> 251 89 9 12 3 2 3 1 3
#> 252 90 0 9 9 1 2 1 1
#> 253 90 0 9 9 1 3 0 2
#> 254 90 9 12 3 2 3 1 3
#> 255 91 0 6 6 1 2 1 1
#> 256 91 0 6 6 1 3 0 2
#> 257 91 6 9 3 2 3 1 3
#> 258 92 0 1 1 1 2 1 1
#> 259 92 0 1 1 1 3 0 2
#> 260 92 1 5 4 2 3 1 3
#> 261 93 0 9 9 1 2 1 1
#> 262 93 0 9 9 1 3 0 2
#> 263 93 9 12 3 2 3 1 3
#> 264 94 0 1 1 1 2 1 1
#> 265 94 0 1 1 1 3 0 2
#> 266 94 1 5 4 2 3 1 3
#> 267 95 0 9 9 1 2 1 1
#> 268 95 0 9 9 1 3 0 2
#> 269 95 9 12 3 2 3 1 3
#> 270 96 0 8 8 1 2 0 1
#> 271 96 0 8 8 1 3 1 2
#> 272 97 0 9 9 1 2 1 1
#> 273 97 0 9 9 1 3 0 2
#> 274 97 9 12 3 2 3 1 3
#> 275 98 0 1 1 1 2 0 1
#> 276 98 0 1 1 1 3 1 2
#> 277 99 0 6 6 1 2 1 1
#> 278 99 0 6 6 1 3 0 2
#> 279 99 6 7 1 2 3 1 3
#> 280 100 0 9 9 1 2 1 1
#> 281 100 0 9 9 1 3 0 2
#> 282 100 9 12 3 2 3 1 3