Possible directed cycle error in JAGS

瘦欲@ 提交于 2019-12-12 03:59:09

问题


I'm trying to fit a simplex model with poisson trick, the likelihood is Likelihood Simplex. The code is below

model{
  for (i in 1:n){
    y[i] ~ dpois(lambda[i])
    lambda[i] <- 0.5*log(phi[i]*(y[i]*(1-y[i]))^3) + 0.5*(1/phi[i])*d[i]
    d[i] <- ((y[i]-mu[i])^2)/(y[i]*(1-y[i])*mu[i]^2*(1-mu[i])^2)
    mu[i] <- beta0+beta1*income[i] + beta2*person[i]
    log(phi[i]) <- -delta0
  }
  beta0 ~ dnorm(0,.001)
  beta1 ~ dnorm(0,.001)
  beta2 ~ dnorm(0,.001)
  delta0 ~ dnorm(0,.001)
}"

When I try to run the code with JAGS in R, I get the following error

 RUNTIME ERROR:
Possible directed cycle involving some or all
of the following nodes:

Then it shows all d[], y[] and lambda[]

I found that someone have a similar problem JAGS error, but looks like that I'm not doing the same mistake.

Any help?

EDIT:

Second attempt

regmodel = "
data{
  for(i in 1:n) {
    zeros[i] <- 0
  }
}
model{
  C <- 1000
  for (i in 1:n){
    zeros[i] ~ dpois(lambda[i])
    lambda[i] <- -l[i] + C
    l[i] <- 
      0.5*log(phi[i]*(y[i]*(1-y[i]))^3) + 
      0.5*(1/phi[i])*((y[i]-mu[i])^2)/(y[i]*(1-y[i])*mu[i]^2*(1-mu[i])^2)
    mu[i]<- beta0 + beta1*income[i] + beta2*person[i]
    log(phi[i]) <- -delta0
  }
  beta0 ~ dnorm(0,.001)
  beta1 ~ dnorm(0,.001)
  beta2 ~ dnorm(0,.001)
  delta0 ~ dnorm(0,.001)
}"

But the error now is

Error in jags.model(file = "ModeloSimplex.txt", data = reg.dat, n.chains = 3,  : 
  Error in node (a(a0.5*(a1/phi[1])*(a(ay[1]-mu[1])^2))/(ay[1]*(a1-y[1])*(amu[1]^2)*(a(a1-mu[1])^2)))
Invalid parent values

来源:https://stackoverflow.com/questions/43428255/possible-directed-cycle-error-in-jags

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!