I am trying to fit a simple Dirichlet regression using rjags with a parametrization in terms of the mean and the precision. The model is written as follows:

model { # (0) priors for (i in 1:(k-1)) { beta0[i] ~ dnorm(0,1); } theta1 ~ dnorm(0, 4)

# (1) likelihood 
for (j in 1:n){
  p1[j,] ~ ddirch(a1[]);

# Parametrization in terms of the mean and the precision
for (i in 1:(k-1))
  a1[i] <- mu1[i]*phi1
  mu1[i] <- exp(beta0[i])/(1+ exp(beta0[i]))
a1[k] <- (1 - sum(mu1[1:(k-1)]))*phi1
phi1 <- exp(theta1)


I continuously get the same error:

Error in node p1[1,1:4] Invalid parent values

I think that it is due to the substraction (1 - sum(mu1[1:(k-1)])), which is giving negative values. Any ideas of how can I solve that?