I am trying to implement a random intercept and slope with complex within error variability in WinBUGS. I was getting "expected multivariate node". Here is a sample code with the error message. Any help would be much appreciated. Please let me know if there is need for further clarification.
model {
for (i in 1:N) {
y[i,1:2] ~ dnorm(mu[i,1:2],prec[i,1:2])
mu[i,1] <- alpha[1] + beta[1]*(wave[i]-1) + b[id[i],1] + u[id[i],1]*(wave[i]-1)
mu[i,2] <- alpha[2] + beta[2]*(wave[i]-1) + b[id[i],2] + u[id[i],2]*(wave[i]-1)
prec[i,1] <- 1 / exp(delta1[1] + delta2[1] * (wave[i]-1) + b[id[i], 3])
prec[i,2] <- 1 / exp(delta1[2] + delta2[2] * (wave[i]-1) + b[id[i], 4])
}
alpha[1] ~ dnorm(0,0.000001)
alpha[2] ~ dnorm(0,0.000001)
beta[1] ~ dnorm(0,0.000001)
beta[2] ~ dnorm(0,0.000001)
delta1[1] ~ dnorm(0,0.000001)
delta1[2] ~ dnorm(0,0.000001)
delta2[1] ~ dnorm(0,0.000001)
delta2[2] ~ dnorm(0,0.000001)
for (i in 1:Nid) {
b[i,1:4] ~ dmnorm(m1[1:4], prec1[1:4,1:4])
u[i,1:2] ~ dmnorm(m2[1:2], prec2[1:2,1:2])
}
# Priors for random terms
prec1[1:4,1:4] ~ dwish(R1[1:4,1:4], 4)
sigma1[1:4,1:4] <- inverse(prec1[1:4,1:4])
R1[1,1] <- 0.00001
R1[2,2] <- 0.00001
R1[3,3] <- 0.00001
R1[4,4] <- 0.00001
R1[1,2] <- 0
R1[1,3] <- 0
R1[1,4] <- 0
R1[2,3] <- 0
R1[2,4] <- 0
R1[3,4] <- 0
S1[1:4,1:4] <- inverse(prec1[1:4,1:4])
prec2[1:2,1:2] ~ dwish(R1[1:2,1:2], 2)
sigma2[1:2,1:2] <- inverse(prec2[1:2,1:2])
R2[1,1] <- 0.0001
R2[2,2] <- 0.0001
R2[1,2] <- 0
R2[2,1] <- 0
S2[1:2,1:2] <- inverse(prec2[1:2,1:2])
}
}}
I think the problem is actually in the first line of the first for()
loop:
y[i,1:2] ~ dnorm(mu[i,1:2],prec[i,1:2])
You're saying here that the first two columns of the i
th row of y
have a distribution. The distribution would have to have as many dimensions as there are values, so WinBUGS is looking for a bivariate node here (~dmnorm(mu[i,1:2], prec[1:2,1:2])
). Alternatively, you could separate them:
y[i,1] ~ dnorm(mu[i,1], prec[i,1])
y[i,2] ~ dnorm(mu[i,2], prec[i,2])