我正试图在r中使用'semimarkov'软件包来拟合多态模型。
以下是我的代码摘录结果和错误。
id state.h state.j time1 LOC sex
102 1 2 4.000000 0 0
102 2 3 5.850000 0 0
104 1 2 4.991781 0 0
104 2 3 6.021918 0 0
112 1 2 5.983562 0 0
12 2 3 7.016438 0 0
table.state(myuse,states=c("1","2","3"))
# $table.state
# 1 2 3
# 1 0 176 146
# 2 40 0 69
# 3 0 0 0
# $Ncens
# [1] 0
states_1 <- c("1","2","3")
mtrans_1 <- matrix(FALSE, nrow = 3, ncol = 3)
mtrans_1[1, 2:3] <- TRUE
mtrans_1[2, c(1,3)] <- c("E","E")
mtrans_1[3, c(1,2)]<-FALSE
LOC<-as.data.frame(myuse$LOC)
fit <- semiMarkov(data=myuse, states=states_1, mtrans=mtrans_1, cov=LOC)
# Iter: 1 fn: 1422.0248 Pars: 6.14509 3.14830 6.92670 7.09842 2.07645 0.80075 0.54658 0.36697 -0.45446 -0.62291 -0.02601 -0.21957
# Iter: 2 fn: 1422.0248 Pars: 6.14506 3.14823 6.92674 7.09846 2.07645 0.80074 0.54658 0.36697 -0.45447 -0.62292 -0.02598 -0.21955
# solnp--> Completed in 2 iterations
# Error in data.frame(Index = c(1:nprob, rep("-", s)), Transition = transitionsP, :
arguments imply differing number of rows: 5, 4
如果有人能向我解释为什么错误以及如何最好地解决错误,我将不胜感激。感谢
答案 0 :(得分:0)
我有几点建议: -仔细查看semiMarkov()函数所需的数据输入,并且不要忘记查看所需的类和列的顺序,因为这只能是一种格式 -查看mtrans分布矩阵,仅使用“ FALSE”,“ E”或“ W”而不是TRUE -首先拟合没有协变量的Semimarkov模型,直到可行