hputter / mstate

https://hputter.github.io/mstate/
7 stars 5 forks source link

Return of mssample for output='data' #13

Closed tobiasmuetze closed 3 months ago

tobiasmuetze commented 2 years ago

Dear Dr. Putter,

I have been running the examples from the help of function mssample:

library(mstate)

# 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)

set.seed(1234)
mssample(Haz=fit$Haz,trans=tmat,tvec=tv,M=100,output="data",do.trace=25)

The output of mssample does not show any rows. Furthermore, applying msdata2etm to the object returned by mssample results in the error Error in msdata[, c("status", "tostat")] : incorrect number of dimensions even though the return of mssample has class msdata. Is this a known issue?

edbonneville commented 3 months ago

@tobiasmuetze thanks for pointing this out and apologies for the (very) long delay in getting to this.. it is now fixed!