包msm:引入协变量时的分段错误

Package msm: segmentation-fault when introducing covariates

在使用包 msm 时,我目前遇到错误:

* 捕获段错误 * 地址 0x7f875be5ff48,导致 'memory not mapped'

当我向我的模型引入协变量时。以前,我通过将我的响应变量从一个因子转换为一个数字变量来解决 similar error。然而,这并不能解决我当前的问题。

数据 <- https://www.dropbox.com/s/wx6s4liofaxur0v/data_msm.txt?dl=0

library(msm)

#number of transitions between states
#1: healthy; 2: ill; 3: dead; 4: censor
statetable.msm(state_2, id, data=dat.long)

#setting initial values
q <- rbind(c(0, 0.25, 0.25), c(0.25, 0, 0.25), c(0, 0, 0))
crudeinits <- crudeinits.msm(state_2 ~ time, subject=id, data=dat.long, qmatrix=q, censor = 4, censor.states = c(1,2))

#running model without covariates
(fm1.msm <- msm(state_2 ~ time, subject = id, qmatrix = crudeinits, data = dat.long, death = 3, censor = 4, censor.states = c(1,2)))

#running model with covariates
(fm2.msm <- msm(state_2 ~ time, subject = id, qmatrix = crudeinits, data = dat.long, covariates = ~ gender, death = 3, censor = 4, censor.states = c(1,2)))

或者,如果我将状态值设置为 dead 并将检查器 (3 & 4) 设置为 missing,我可以 运行 具有协变量的模型。

#set death and censor to missing    
dat.long$state_2[dat.long$state_2 %in% c(3,4)] <- NA
statetable.msm(state_2, id, data=dat.long)

#setting initial values
q <- rbind(c(0, 0.5), c(0.5, 0))
crudeinits <- crudeinits.msm(state_2 ~ time, subject=id, data=dat.long, qmatrix=q)

#running models with covariates
(fm3.msm <- msm(state_2 ~ time, subject = id, qmatrix = crudeinits, data = dat.long, covariates = ~ gender))
(fm4.msm <- msm(state_2 ~ time, subject = id, qmatrix = crudeinits, data = dat.long, covariates = ~ covar))

感谢您的帮助

在 1.5 版的 msm 中,检测和删除数据中的 NA 的 R 代码中存在错误。当存在协变量并且状态或时间变量包含 NA 时会触发此事件。然后可以将这些 NA 传递给计算可能性的 C 代码,从而导致崩溃。我会在下一个版本中解决这个问题。同时,您可以通过在调用 msm 之前从数据中删除 NA 来解决这个问题。