# JAGS error in the estimation of a simple INAR model

I am having a hard time try to figure out how to translate a simple INAR(1) model in JAGS. $$$$Y_t = \alpha \circ Y_{t-1} + e_t$$$$ where $$\circ$$ is the binomial thinning operator and $$e$$ a Poisson noise. In simple words the binomial thinning operator is a random operator which avoids the so called "multiplication problem" in the context of count data and, loosely speaking, can be interpreted as:

$$$$\alpha \circ Y_{t-1} = Bin(Y_{t-1}, \alpha)$$$$

(the reason is that the expected value of the binomial is exactly $$Y_{t-1} \times \alpha$$ ) See for a quick intro: https://wires.onlinelibrary.wiley.com/doi/full/10.1002/wics.1502

Here is what I have tried:

model{
#INAR(1)

for (t in 2:T) {
e[t] ~ dpois(lambda_e)
P[t] ~  dbin(alpha, Y[t-1])
Y[t]  ~ dsum(P[t],e[t])
}

e[1] ~ dpois(lambda_e)
P[1] ~ dbin(alpha, Y[1])
Y[1]  ~ dsum(P[1],e[1])

#priors
alpha  ~ dunif(-1,1)
lambda_e  ~ dgamma(1, 0.001)
}
Error in jags.model(file = Model, data = dat, n.chains = N_chains, n.adapt = N_adapt) :
RUNTIME ERROR:
Possible directed cycle involving some or all
of the following nodes:
P[1]
P[2]
P[3]
P[4]
...



Does someone have any idea about how to solve this issue?

Another problematic part in your definition is that $$t$$ depends on $$t-1$$. JAGS is a declarative language, the for loop does not go sequentially through the steps, so it doesn't guarantee to do the $$t-1$$ computation before the $$t$$ step. If you need this, don't use JAGS.