我正在尝试使用 rjags 拟合以下模型,但出现尺寸不匹配错误。该模型在 WinBUGS 中运行良好,我不知道如何更改代码。提前感谢您的帮助。
数据:
dataset <- list(n1 = 462, n2 = 537,
y1 = structure(.Data = c(37, 55, 7, 363), .Dim = c(2, 2)),
y2 = structure(.Data = c(104, 26, 22, 385), .Dim = c(2, 2)),
Q = 2)
链的初始值
inits <- list(pi1 = 0.1, pi2 = 0.3, SeMAT = 0.80, SpMAT = 0.90,
SeCMB = 0.90, SpCMB = 0.9995)
模型
model <-
'model {
y1[1:Q, 1:Q] ~ dmulti(p1[1:Q, 1:Q], n1)
y2[1:Q, 1:Q] ~ dmulti(p2[1:Q, 1:Q], n2)
p1[1, 1] <- pi1 * SeMAT * SeCMB + (1 - pi1) * (1 - SpMAT) * (1 - SpCMB)
p1[1, 2] <- pi1 * SeMAT * (1 - SeCMB) + (1 - pi1) * (1 - SpMAT) * SpCMB
p1[2, 1] <- pi1 * (1 - SeMAT) * SeCMB + (1 - pi1) * SpMAT * (1 - SpCMB)
p1[2, 2] <- pi1 * (1 - SeMAT) * (1 - SeCMB) + (1 - pi1) * SpMAT * SpCMB
p2[1, 1] <- pi2 * SeMAT * SeCMB + (1 - pi2) * (1 - SpMAT) * (1 - SpCMB)
p2[1, 2] <- pi2 * SeMAT * (1 - SeCMB) + (1 - pi2) * (1 - SpMAT) * SpCMB
p2[2, 1] <- pi2 * (1 - SeMAT) * SeCMB + (1 - pi2) * SpMAT * (1 - SpCMB)
p2[2, 2] <- pi2 * (1 - SeMAT) * (1 - SeCMB) + (1 - pi2) * SpMAT * SpCMB
SeMAT ~ dbeta(1, 1)
SpMAT ~ dbeta(1, 1)
SeCMB ~ dbeta(1, 1)
SpCMB ~ dbeta(1, 1)
pi1~ dbeta(1, 1)
pi2 ~ dbeta(1, 1)
}'
writeLines(model, 'model.txt')
jags.mod <- jags.model(file = 'model.txt',
data = dataset,
inits = inits,
n.chains = 3)
错误
jags.model 中的错误(文件 =“model.txt”,数据 = 数据集,inits = inits,:运行时错误:无法将节点插入 y1[1:2,1:2]。尺寸不匹配