2

我对 JAGS 比较陌生。我的数据包括 15 周内 5 个流的幼虫计数(两个观察/周和流)。为此,我使用一个包含 150 行、2 列和 15 个条目 (y) 的数组。我的目标是在一个开放的 N 混合模型的帮助下估计每周的欧米茄。我也尝试使用未标记的包,但无法弄清楚这将如何与 pcountopen() 一起使用。

sink("model1.txt") 
cat("
model {
# Priors
  lambda ~ dunif(0, 5)
  omega ~ dunif(0, 1)
  p ~ dunif(0, 1)
# Likelihood
  # Biological (ecological) model for true abundance (State model)
  for (i in 1:R) {                  #loop over R sites (150)
  N[i,1] ~ dpois(lambda)            #Abundance
  for (k in 2:15) {                 #loop over weeks (15)
   N[i,k] ~ dpois(omega[k] * N[i, k-1])
   # Observation model for replicated counts
   for (j in 1:T){                  #loop over temporal reps (2)
     y[i,j,k-1] ~ dbin(p, N[i,k-1]) #Detection
     } #j
   } #k
 } #i
}
",fill = TRUE)
sink()

# Bundle and summarize data set 
R = nrow(y) #sites = 150
T = ncol(y) #replications per observation day = 2
win.data <- list(y = y, R = R, T = T)

# Initial values 
Nst <- apply(y, c(1,3), max) +1
inits <- function() {list(N = Nst)}

# Parameters monitored
params1 <- c("omega", "lambda", "p")

# MCMC settings 
ni <- 20 ; nt <- 1 ; nb <- 0 ; nc <- 8

# Call JAGS (ART 1 min) and summarize posteriors 
library(jagsUI)
fm1 <- jags(win.data, inits, params1, 
            "model1.txt", 
            n.chains = nc, n.thin = nt, n.iter = ni, n.burnin = nb)

这给了我以下错误: jags.model 中的错误(file = model.file, data = data, inits = inits, n.chains = n.chains, : RUNTIME ERROR: Compilation error on line 12. Index out of rangetaking欧米茄的子集

谢谢你的帮助!

4

0 回答 0