ipm3 <- nimbleCode({
# Priors and linear models for population dynamics
sig.ystar ~ dunif(0, 10000)
sig2.ystar <- pow(sig.ystar, 2)
tau.ystar <- pow(sig.ystar, -2)
# Prior for Survival
mean.sj ~ dunif(0, 1)
mean.sa ~ dunif(0, 1)
# Priors for Fecundity
for(t in 1:nyear){
mean.f[1,t] ~ dunif(0, 1)
mean.f[2,t] ~ dunif(0, 4)
mean.f[3,t] ~ dunif(0, 4)
}
# Likelihood
# Model for the initial population size: uniform priors
for(a in 1:ageclass){
N[a,1] ~ dunif(100, 2000) # All 3 age classes
}
# Process Model
for(t in 2:nyear){
N[1,t] ~ dpois(round(((N[1,t-1] - Hf[t-1]) * mean.f[1,t-1] / 2 *
mean.sj) +
(N[2,t-1] * mean.f[2,t-1] / 2 *
mean.sa) +
(N[3,t-1] * mean.f[3,t-1] / 2 *
mean.sa)))
N[2,t] ~ dbinom(
mean.sj, round(N[1,t-1] - Hf[t-1]))
N[3,t] ~ dbinom(
mean.sa, round(N[2,t-1]- Hyrl[t-1] + N[3,t-1]- Had[t-1]))
}
# Observation process for the abundance estimates with their SEs
for(t in 1:nyear){
Nhat[t] ~ dnorm(ystar[t],
tau.se[t])
tau.se[t] <- 1/var.Nhat[t] # Assumed known and given by variance of Nhat
ystar[t] ~ dnorm(N[1,t]+N[2,t]+N[3,t], tau.ystar)
}
# Recruitment
for(i in 1:nind){
J[i] ~ dpois(mean.f[age[i], year[i]])
}
# Derived parameters
# Annual population growth rate
for (t in 1:(nyear-1)){
ann.growth.rate[t] <- (N[1,t+1] + N[2,t+1] + N[3,t+1]) / (N[1,t] + N[2,t] + N[3,t])
}
# Total population size
for (t in 1:nyear){
Ntot[t] <- N[1,t] + N[2,t] + N[3,t]
}
})
nimdata = list(J = f$Fetus.Count, Nhat = D$abundace, var.Nhat = D$var,
Hf = c(rep(0, times = 17), hcopy$n[which(hcopy$ageclass == 1)]),
Hyrl = c(rep(0, times = 17), hcopy$n[which(hcopy$ageclass == 2)]),
Had = c(rep(0, times = 17), hcopy$n[which(hcopy$ageclass == 3)]))
params = c("mean.f", "sig2.ystar", "sig.ystar", "ystar", "
mean.sj", "
mean.sa",
"N", "ann.growth.rate", "Ntot")
nimconsts = list(nyear = length(D$abundace),
nind = length(f$Fetus.Count),
year = f$Year-1998,
age = f$ageclass,
ageclass = length(unique(f$ageclass)))
niminits = list(
mean.sj = runif(1, 0, 1),
mean.sa = runif(1, 0, 1),
mean.f = matrix(rep(c(runif(1,0,1),runif(1,0,4)), times = c(25,50)),
nrow = 3, ncol = 25, byrow = T))