简体   繁体   中英

Bayesian Beta regression Model — Error in jags: Invalid parent value

I'm trying to run a Bayesian pooled model in jags through R and getting an error message

I found from people who have encountered similar problems that it could be triggered by values of the priors, negative value, log of negative, syntax errors etc. I have eliminated all of these but the error persists.

## just for the prediction
pred.jac <- seq(min(test.bayes$Latitude), max(test.bayes$Latitude), 10)

data = list(
  jac = test.bayes$Jaccard,
  lat = test.bayes$Latitude,
  pred.jac = pred.jac)


inits = list(
  list(alpha = 1, beta = 2.5, sigma = 50),
  list(alpha = 2, beta = 1.5, sigma = 20),
  list(alpha = 3, beta = 0.75, sigma = 10))



{
  sink("BetaPooledJAGS.R")
  cat("
      model{

      # priors
      alpha ~ dnorm(0, 0.0001)
      beta ~ dnorm(0, 0.0001)
      sigma ~ dunif(0, 10)


      # likelihood


      for (i in 1:length(jac)) {
      mu[i] <- alpha + beta * lat[i]
      a[i] <- ((1 - mu[i]) / (sigma^2) - 1 / mu[i]) * mu[i]^2
      b[i] <- alpha * (1 / mu[i] - 1)
      jac[i] ~ dbeta(a[i], b[i])


      }

      # predicted jaccard as derived quantities
      for (i in 1:length(pred.jac)) {
      mu_pred[i] <- alpha + beta * lat[i]
      mu_pred1[i] <- exp(mu_pred[i])
      }

      }

      ",fill = TRUE)
  sink()
}


n.adapt = 3000
n.update = 5000
n.iter = 5000
jm.pooled = jags.model(file="BetaPooledJAGS.R", data = data, n.adapt = n.adapt, inits = inits, n.chains = length(inits))

When I run the code, I get the error below:

Error in jags.model(file = "BetaPooledJAGS.R", data = data, n.adapt = n.adapt, : Error in node jac[1] Invalid parent values

Here's the link to a subset of my data.

https://fil.email/IuwgYhKs

You're getting negative values for b with those initials if lat is positive, and b must be > 0 in a beta distribution, in JAGS, and more generally.

Eg using initials from inits[[1]] :

mu = 1 + 2.5*lat assuming lat is positive, then mu > 1

b = 1 * (1/mu-1) And 1/mu < 1 if mu>1 , so 1/mu - 1 < 0 .

Therefore b = 1*-ve so b<0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM