I'm rather new to JAGS. My data consists of larval counts of 5 streams during 15 weeks (two observations / week and stream). For this I work with an array with 150 rows, 2 columns and 15 entries (y). My goal is to estimate omega for each week with help of an open N-mixture model. I also tried it with the unmarked package but could not figure it out how this would work with 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)
This gives me the following error: Error in jags.model(file = model.file, data = data, inits = inits, n.chains = n.chains, : RUNTIME ERROR: Compilation error on line 12. Index out of range taking subset of omega
Thanks for any help!