model{
  # Likelihood
  for(j in 1:J) {
    for (i in 1:N) {
      y[i,j] ~ dnorm(inprod(p*q[,j], s_mean[,j]+c_mean[,j]) / inprod(p,q[,j]), 1/var_y[j])
    }
    var_y[j] <- inprod(pow(p*q[,j],2),pow(s_sd[,j],2)+pow(c_sd[,j],2))/pow(inprod(p,q[,j]),2) + pow(sigma[j],2)
  }
  

  # Prior on sigma
  for(j in 1:J) { 
    sigma_raw[j] ~ dgamma(sigma_shape[j], sigma_rate[j])
    sigma[j] <- 0.001 + not_solo * sigma_raw[j]
  }

  # CLR prior on p
  p[1:K] <- expf/sum(expf)
  for(k in 1:K) {
    expf[k] <- exp(f[k])
    f[k] ~ dnorm(mu_f_mean[k],1/pow(sigma_f_sd[k],2))
  }
}