Hi all,
When I ran the model code below for ten iterations, it appears the MCMC was stuck or in a never-ending loop. My machine's memory was also exhausted. I'm not sure what the real issue here, but I suspect it has to do with the line highlighted in red. Could you identify the problem? Also, if you ever come across the same problem, do share with me how you solved it—many thanks. Those objects in CAPS are the input data.
code <- nimbleCode({
# 1. SPECIFY PRIORS
nhS ~ dbeta(9, 1)
for (s in 1:sex) {
pie[s] ~ dbeta(1, 1)
}
for (y in 1:year) {
for (a in 1:age) {
for (s in 1:sex) {
hS[y,a,s] ~ dbeta(1, 1)
}
}
}
#size at y=1
n[1,1:3,1] <- c(50000, 30000, 10000)
n[1,1:3,2] <- c(50000, 30000, 10000)
#2. STATE PROCESS
for (y in 1:(year-1)) {
for (s in 1:sex) {
ns[y,1:3,s] <- n[y,1:3,s] * hS[y,1:3,s] * nhS
na[y,1,s] <- sum(ns[y,1,s] * c(1-pie[1], 0, 0))
na[y,2,s] <- sum(ns[y,2,s] * c(pie[1], 1-pie[2], 0))
na[y,3,s] <- sum(ns[y,3,s] * c(0, pie[2], 1))
nb[y,1,s] <- sum(na[y,1,s] * c(RHO[y,1], RHO[y,2], RHO[y,3]))
nb[y,2,s] <- sum(na[y,2,s] * c(0, 1, 0))
nb[y,3,s] <- sum(na[y,3,s] * c(0, 0, 1))
n[y+1,1:3,s] <- nb[y,1:3,s] * SEX[y,s]
}
}
#3. OBSERVATION PROCESS
for (y in 1:year) {
for (a in 1:age) {
for (s in 1:sex) {
CULL[y,a,s] <- n[y,a,s] * (1-hS[y,a,s])
}
}
}
#4. DERIVED PARAMETERS
for (y in 1:year) {
yearling[y] <- sum(n[y,1,1:2])
juvenile[y] <- sum(n[y,2,1:2])
adult[y] <- sum(n[y,3,1:2])
Total[y] <- sum(n[y,1:3,1:2])
}
})
Cheers,
Lukmann