I fitted a regression model in a Bayesian approach via MCMC. The JAGS code for the model is

Code: 
model{
for(i in 1:n) {
y[i] ~ dbeta(alpha[i], beta[i])
alpha[i] <- mu[i] * phi[i]
beta[i]  <- (1-mu[i]) * phi[i]
log(phi[i])<- -inprod(X2[i,],delta[])
cloglog(mu[i]) <- inprod(X1[i,],B[])
}

for (j in 1:p){
B[j] ~ dnorm(0,.001)
}

for(k in 1:s){
delta[k] ~ dnorm(0,.001)
}
}"
I want to calculate the deviance residuals for this model and make simulated envelopes. The problem is that the deviance residuals involves the square root of each contribution in the likelihood and here in some cases the likelihood is positive and anothers negative.

Since that deviance is equal to sum of deviance residuals squared, and the deviance of my model is negative, I don't know what to do.

Any help?