Converts multi-state data back and forth between etm and msdata formats. Covariates have to be dealt with separately.

etm2msdata(etmdata, id, tra, covs)

Arguments

etmdata

Multi-state data in etm format

id

Column name identifying the subject id

tra

Transition matrix in etm format

covs

Vector of column names containing covariates to be included

Details

msdata2etm will convert from msdata format to etm format; etm2msdata will convert from etm format to msdata format. Both msdata2etm and etm2msdata work with basic time-fixed covariates. Time-dependent covariates are not supported. The function msdata2etm will work for transition-specific covariates, but the result does not really make much sense when used in etm.

Author

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(id=1:6,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, id="id") # Same thing in etm format tra <- trans2tra(tmat) tgetm <- msdata2etm(tglong, id="id") tgetm <- msdata2etm(tglong, id="id", covs=c("x1", "x2")) # with covariates # And back etm2msdata(tgetm, id="id", tra=tra)
#> An object of class 'msdata' #> #> Data: #> id from to trans Tstart Tstop time status #> 1 1 1 2 1 0 1 1 1 #> 2 1 1 3 2 0 1 1 0 #> 3 1 2 3 3 1 5 4 1 #> 4 2 1 2 1 0 1 1 0 #> 5 2 1 3 2 0 1 1 1 #> 6 3 1 2 1 0 6 6 1 #> 7 3 1 3 2 0 6 6 0 #> 8 3 2 3 3 6 9 3 1 #> 9 4 1 2 1 0 6 6 1 #> 10 4 1 3 2 0 6 6 0 #> 11 4 2 3 3 6 7 1 1 #> 12 5 1 2 1 0 8 8 0 #> 13 5 1 3 2 0 8 8 1 #> 14 6 1 2 1 0 9 9 1 #> 15 6 1 3 2 0 9 9 0 #> 16 6 2 3 3 9 12 3 1
etm2msdata(tgetm, id="id", tra=tra, covs=c("x1", "x2")) # with covariates
#> An object of class 'msdata' #> #> Data: #> id from to trans Tstart Tstop time status x1 x2 #> 1 1 1 2 1 0 1 1 1 1 6 #> 2 1 1 3 2 0 1 1 0 1 6 #> 3 1 2 3 3 1 5 4 1 1 6 #> 4 2 1 2 1 0 1 1 0 1 5 #> 5 2 1 3 2 0 1 1 1 1 5 #> 6 3 1 2 1 0 6 6 1 1 4 #> 7 3 1 3 2 0 6 6 0 1 4 #> 8 3 2 3 3 6 9 3 1 1 4 #> 9 4 1 2 1 0 6 6 1 0 3 #> 10 4 1 3 2 0 6 6 0 0 3 #> 11 4 2 3 3 6 7 1 1 0 3 #> 12 5 1 2 1 0 8 8 0 0 2 #> 13 5 1 3 2 0 8 8 1 0 2 #> 14 6 1 2 1 0 9 9 1 0 1 #> 15 6 1 3 2 0 9 9 0 0 1 #> 16 6 2 3 3 9 12 3 1 0 1