贝叶斯空间状态模型存在问题

时间:2019-12-08 21:01:03

标签: r rjags

我在输入代码时遇到麻烦。我是贝叶斯分析的新手,我找不到错误。我正在尝试为动物密度的短时间序列编写一个空间状态模型,但是我收到此警告消息“第11行出现编译错误。未知变量X为该变量提供数据或在左侧定义它,关系的另一面”。欢迎任何帮助。我正在编译下面的错误代码。

y<-c(22.77619, 19.07782, 22.08817, 16.32168, 32.57081, 10.48027, 15.93440, 27.54557, 33.39933)
pop.din = "
+ model{
+ #### Data Model
+ for(i in 1:n){
+   y[i] ~ dlnorm ((t[i]),tau_obs)
+ }
+ 
+ #### Process Model
+ for(i in 2:n){
+     x[i]<-t[i-1]+r*t[i-1]*(1-t[i-1]/k)
+     t[i]~dlnorm(X[i],tau_proc)
+     y[i]~dlnorm(t[i],tau_obs)
+      
+ }
+ #### Priors
+ t[1] ~ dgamma(x_ic,tau_ic)
+ r ~ dnorm(mu_r,tau_r)
+ k ~ dlnorm(mu_k,tau_k)
+ tau_obs ~ dgamma(a_obs,b_obs)
+ tau_proc ~ dgamma(a_proc,b_proc)
+ }
+ "
> data <- list(y=(y),n=length(y),x_ic=10,tau_ic=0.0001,a_obs=1,b_obs=1,a_proc=1,b_proc=1,
+              mu_r=0,tau_r=0.00001,mu_k=0,tau_k=0.00001)
> nchain = 3
> init <- list()
> for(i in 1:nchain){
+   y.samp = sample(y,length(y),replace=TRUE)
+   init[[i]] <- list(tau_proc=1/var(log(y.samp)),tau_obs=1/var(diff(log(y))))
+ }
> library(rjags)
> j.model   <- jags.model (file = textConnection(pop.din), data = data,
+                              inits = init,
+                              n.chains = 3)
Compiling model graph
   Resolving undeclared variables
   Allocating nodes
Deleting model

Error in jags.model(file = textConnection(pop.din), data = data, inits = init,  : 
  RUNTIME ERROR:
Compilation error on line 11.
Unknown variable X
Either supply values for this variable with the data
or define it  on the left hand side of a relation.
```
Regards
Antonela

0 个答案:

没有答案