Dear all,
Here is a N-mixture model.
code <- nimbleCode({
# Priors
for (k in 1:2) {
beta[k] ~ dnorm(0, sd=10)
} # k
p ~ dunif(0, 1)
lambda[1:nsite] <- exp(x[1:nsite,1:2] %*% beta[1:2])
for(i in 1:nsite) {
N[i] ~ dpois(lambda[i])
y[i] ~ dbin(p, N[i])
} # i
}) # nimbleCode
The default sampler for the true abundance N is a slice sampler.
In the Hooten & Hefley "Bringing Bayesian Models to Life" book, they use a sampler that is written as following:
N_star <- rpois(nsite, N + 1)
mh1 <- apply(dbinom(y, N_star, p, log=T), 1, sum) +
dpois(N_star, lambda, log=T) +
dpois(N, N_star+1, log=T)
mh2 <- apply(dbinom(y, N , p, log=T), 1, sum) +
dpois(N , lambda, log=T) +
dpois(N_star, N+1, log=T)
mh <- exp(mh1 - mh2)
Nkeep <- ((mh > runif(nsite)) & (N_star >= ymax))
N[Nkeep] <- N_star[Nkeep]
I would assume this is different from a slice sampler and it is more efficient because it updates all N's simultaneously. Please let me know if I got it wrong.
Is this sampler implemented in Nimble? If yes, what is its name?
Any help will be greatly appreciated.
Best,
Qing