使用msm包时,我目前收到错误:
*捕获了segfault * 地址0x7f875be5ff48,导致'内存未映射'
当我向我的模型介绍协变量时。以前,我通过将响应变量从因子转换为数字变量来解决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并且将censor(3&amp; 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))
感谢您的帮助
答案 0 :(得分:1)
在msm的1.5版本中,R代码中存在错误,该错误检测并丢弃数据中的NA。当存在协变量时会触发此操作,并且状态或时间变量包含NA。然后可以将这些NA传递给计算可能性的C代码,从而导致崩溃。我将为下一个版本修复此问题。在此期间,您可以通过在调用msm之前从数据中删除NA来解决此问题。