I am trying to fit the model below using rjags but I get a dimension mismatch error. The model runs well in WinBUGS and I can't figure out how to change the code. Thanks in advance for any help.
Data:
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)
Initial values for chains
inits <- list(pi1 = 0.1, pi2 = 0.3, SeMAT = 0.80, SpMAT = 0.90,
SeCMB = 0.90, SpCMB = 0.9995)
Model
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)
Error
Error in jags.model(file = "model.txt", data = dataset, inits = inits, : RUNTIME ERROR: Cannot insert node into y1[1:2,1:2]. Dimension mismatch