Error incorrect number of dimensions in msprep for multi-state modelling in R

41 views Asked by At

I am trying to fit a multi-state model in R using mstate. When I try to convert the wide data to a long format using msprep, however, I get the following error: Error in time[, -startings] : incorrect number of dimensions.

This is the code I tried:

x <- msprep(time = c(NA, "F0A1_time",  "F0A2_time", "F0A3_time", "F0A4_time", 
                         "F1A0_time", "F1A1_time", "F1A2_time", "F1A3_time", "F1A4_time", "death_time"),
                status = c(NA, "F0A1_status",  "F0A2_status", "F0A3_status", "F0A4_status", 
                           "F1A0_status", "F1A1_status", "F1A2_status", "F1A3_status", "F1A4_status", "death_status"),
                data = d, id = "subject", trans = tmat, keep = c("AGE_JR", "ckd"))

I checked that d is a data.frame that has rows x columns dimensions, all variables are spelled correctly, in the numerical format and present in the data.frame d. I double checked the specification of tmat: all the states and transitions are specified correctly:

tmat <- transMat(x = list( c(2, 6, 11), c(3, 7, 11), c(4, 8, 11), c(5, 9, 11), c(10, 11),
                           c(7, 11 ), c(8, 11), c(9, 11), c(10, 11), c(11), c()),
                 names = c("F0A0", "F0A1", "F0A2", "F0A3", "F0A4", "F1A0", "F1A1", "F1A2", "F1A3", "F1A4", "Death"))

What am I doing wrong?

0

There are 0 answers