I'm trying to make a bayesian mixture model using rjags. This is an attempt to map a dose-response relationship for experiments conducted in 19 labs. As such, the model that I produced has intercepts for all the labs. I want to cluster the lab effects using mixture modelling but my code does not work. Here is a copy of my model followed by the error :-
mod_string2 <- "
model{
# Likelihood
for(i in 1:n){
Y[i] ~ dnorm(mu[i],inv.var)
mu[i] <- a[lab[i]] + b[1]*ld1[i] + b[2]*ld2[i] + b[3]*sqld1[i] + b[4]*sqld2[i] + b[5]*lbody[i] + b[6]*B[i]*ld1[i] + b[7]*C[i]*ld1[i] + b[8]*D[i]*ld1[i] + b[9]*B[i]*ld2[i] + b[10]*C[i]*ld2[i] + b[11]*D[i]*ld2[i]
a[lab[i]] ~ dnorm(muOfClust[clust[lab[i]]], tau)
clust[i] ~ dcat( pClust[1:Nclust] )
}
# Prior for labs (intercepts)
for (clustIdx in 1: Nclust) {
muOfClust[clustIdx] ~ dnorm( 0 , 1/100000 )
}
pClust[1:Nclust] ~ ddirch(onesRepNclust) # so (pi1,pi2) follow Dir(1,1) which implies pi1 follows Beta(1,1)
tau ~ dgamma(0.01 , 0.01)
# Prior for beta
for(j in 1:11){
b[j] ~ dnorm(0,0.0001)
}
# Prior for the inverse variance
inv.var ~ dgamma(0.01, 0.01)
sigma <- 1/sqrt(inv.var)
}
"
My error is :-
Error in jags.model(textConnection(mod_string2), data = d2) : RUNTIME ERROR: Compilation error on line 7. Attempt to redefine node a[3]
What am I doing wrong?