我正在尝试拟合空间状态模型,并且收到此错误消息:
Error in jags.model(file = model.file, data = data, inits = inits, n.chains = n.chains, :
RUNTIME ERROR:
Possible directed cycle involving some or all
of the following nodes:
t[2]
t[3]
t[4]
t[5]
t[6]
t[7]
t[8]
t[9]
v[2]
v[3]
v[4]
v[5]
v[6]
v[7]
v[8]
v[9]
我在这里发现JAGS error - Possible directed cycle involving some or all of the following nodes可能是由于方程t[i]
在等式的两边,但我之前在其他空间状态模型中都这样做过,对此我也没有任何问题什么会导致此问题???这是模型:
o<-c(22.77619, 19.07782, 22.08817, 16.32168, 32.57081, 10.48027, 15.93440, 27.54557, 33.39933)
cat(file="pop.din","
model {
t[1] <- n0
o[1] ~ dlnorm(log(t[1]),tau.obs)
for (i in 2:9) {
v[i] <- lambda*t[i] #valor esperado
t[i] ~ dpois(v[i]) #t valor verdadero
o[i] ~ dlnorm(log(t[i]),tau.obs)
}
lambda ~ dunif(0.1,0.00001)
tau.obs ~ dgamma(1,10)
n0 ~ dlnorm(1,0.0001)
}")
pop.din.data<-c("o")
#initial values for the parameters stored as a list
inits<-function()list(lambda=runif(0.01,1),tau.obs=rlnorm(1,1,1),n0=rlnorm(1,1,1))
params<- c("lambda","n0","tau.obs")
ni <- 10000
nt <- 1
nb <- 5000
nc <- 3
library(jagsUI)
j.model <- jags (model.file = "pop.din", data = pop.din.data,parameters.to.save = params,
inits=inits, n.burnin=nb,n.chains = nc,n.iter = ni)
print(j.model)
问候
这是我的问题的解决方案:在这种情况下,空间状态模型将变量的值与其前一次的值相关联,因此应编写过程模型:
cat(file="pop.din","
model{
#### Data Model
for(i in 1:n){
o[i] ~ dlnorm(x[i],tau_obs)
}
#### Process Model
for(i in 2:n){
v[i]<-lambda*x[i-1] ###not x[i]
x[i]~dpois(x[i-1])
}
#### Priors
x[1] ~ dlnorm(x_ic,tau_ic)
lambda ~dunif(mu,tau_lambda)
tau_obs ~ dgamma(1,1)
}")
问候