Reputation: 11
I'm encountering an issue when trying to use the elements of the matrix D[i] inside a for loop in my JAGS model. The matrix D[i] is derived from a Wishart distribution, and when I try to use it within the loop, I get an error related to the sampler.Here’s the relevant portion of my code:
{
for(i in 3:N){
for(j in 1:3){
mu[i,j] <- beta[j,1]+beta[j,2]*y[i-1,1]+beta[j,3]*y[i-1,2]+beta[j,4]*y[i-1,3]+
beta[j,5]*y[i-2,1]+beta[j,6]*y[i-2,2]+beta[j,7]*y[i-2,3]
}
mux[i,1] <- mu[i,1] +D[1]*theta_1[1]*Exp[i]
mux[i,2] <- mu[i,2] +D[2]*theta_1[2]*Exp[i]
mux[i,3] <- mu[i,3] +D[3]*theta_1[3]*Exp[i]
Exp[i]~ dexp(1)
##precision[i,1:3,1:3]<- 1/Exp[i]*theta_2_inv%*%zInvCovMat%*%theta_2_inv
##y[i,1:3] ~ dmnorm(mux[i,1:3], precision[i,1:3,1:3] )
y[i,1:3] ~ dmnorm(mux[i,1:3], zInvCovMat[1:3,1:3])
}
for (j in 1:3) {
for (k in 1:7) {
beta[j, k] ~ dnorm(0, 0.01)
}
theta_1[j]<-(1-2*q[j])/(q[j]*(1-q[j]))
}
zInvCovMat ~ dwish( zRmat[1:3,1:3] , zRscal)
D[1]<-sqrt(zInvCovMat[1,1])
D[2]<-sqrt( zInvCovMat[2,2])
D[3]<- sqrt(zInvCovMat[3,3])
theta_2_inv[1,1] <- sqrt((q[1]*(1-q[1]))/2)
theta_2_inv[2,2] <- sqrt((q[2]*(1-q[2]))/2)
theta_2_inv[3,3] <- sqrt((q[3]*(1-q[3]))/2)
theta_2_inv[1,2] <- 0
theta_2_inv[1,3] <- 0
theta_2_inv[2,1] <- 0
theta_2_inv[2,3] <- 0
theta_2_inv[3,1] <- 0
theta_2_inv[3,2] <- 0
}
The error I receive is:
Error in node zInvCovMat
Unable to find appropriate sampler.
I’m not sure why this error occurs only when I use the elements of D[i] inside the loop. When D[i] is used outside the loop, the model compiles without issues. Is there something specific about using D[i] within a loop that JAGS doesn't handle well?
Upvotes: 1
Views: 33