I am experiencing issues with running the following time-series JAGS model in R:
data(lynx)
y <- as.vector(lynx)
y
x <- 1:length(y)
library(rjags)
mod <- "model {
alpha ~ dnorm(0, 0.0001)
beta ~ dnorm(0, 0.0001)
lambda ~ dgamma(1, 1)
for (i in 2:length(y)) {
y[i] ~ dpois(lambda[i])
lambda[i] <- alpha + beta * x[i - 1]
}
}"
mod <- textConnection(mod)
samples <- jags.model(mod, data = list('x' = x, 'y' = y), n.chains = 3) #
# Error in jags.model(mod, data = list(x = x, y = y), n.chains = 3) :
# RUNTIME ERROR:
# Cannot insert node into lambda[1:114]. Dimension mismatch
Is someone able to explain what the above error is referring to and how to fix it?