我正在尝试在R中实现HMM。现在我的数据集中有18列。当我创建发射矩阵时,它会给出未定义列的错误,我不知道我在哪里做错了。
library(seqHMM)
emix <- matrix(NA, nrow = 3, ncol = 4)
emix[1,] <- seqstatf(exam_seq[, 1:5])[, 3] + 1
emix[2,] <- seqstatf(exam_seq[, 6:12])
emix[3,] <- seqstatf(exam_seq[, 13:18])
Error in \`[.data.frame`(seqstatf(exam_seq[, 1:5]), , 3) :
undefined columns selected
OP在评论中发布的数据。
structure(list(Freq = c(260, 262, 74, 1, 485, 106, 6,
219, 215, 1282, 80), Percent = c(8.69565217391304,
8.76254180602007, 2.47491638795987, 0.0334448160535117,
16.2207357859532, 3.54515050167224, 0.20066889632107,
7.32441471571906, 7.19063545150502, 42.876254180602,
2.67558528428094 )), class = "data.frame", row.names =
c("So", "Da", "UK", "Tw", "Al", "Ab", "D", "NA", "0", "1",
"2"))