I am now working on using a mixture model including two components: normal and lognormal to fit a vector. I tried using JAGS, here is the code:
model {
for(i in 1:N) {
y[i] <- latent[i,index[i]+1]
index[i] ~dbern(pi)
latent[i,1]~ dlnorm(mu1,tau1)
latent[i,2]~ dnorm(mu2,tau2)}
pi ~ dbeta(0.5,0.5)
mu1 ~ dnorm(0.4,0.000001)
tau1~ dgamma(0.001,0.001)
mu2 ~ dnorm(4,0.000001)
tau2~ dgamma(0.001,0.001)
}
However, it does not work with an error message "y[1] is a logical node and cannot be observed". I also tried
y[i] <- pi*z1+(1-pi)*z2
z1 ~ dnorm(mu1,tau1)
z2 ~ dlnorm(mu2,tau2)
...
But it gave the same error message. It seems I have to assign a distribution to y[i]. Could anyone help to overcome this problem? or other approaches for solving such a mixture model would be appreciated too!