model { # Priors beta0 ~ dunif(-20,20) beta1 ~ dnorm(0,0.01) beta2 ~ dnorm(0,0.01) beta3 ~ dnorm(0,0.01) beta4 ~ dnorm(0,0.01) for (k in 1:n.year){
lam_tot[k] ~ dunif(1,50) eps[k] ~ dnorm(0,tau.p) for (i in 1:n.sec){ lam[i,k] ~ dgamma(5,1) } } tau.p <- pow(sd.p,-2) sd.p ~ dunif(0,5)
# Likelihood # Ecological model for (k in 1:n.year){ M[k] ~ dpois(lam_tot[k]) N.sec[1:n.sec,k] ~ dmulti(pi[1:n.sec,k],M[k]) # Abundance on each sector is a part of the total abundance pi[1:n.sec,k] <- lam[1:n.sec,k]/sum(lam[,k]) # definition of pi # Observation model for replicated counts for (i in 1:n.sec){ for (j in 1:(field[i,k])){ y[i,j,k] ~ dbin(z.sec[i,k]*p[i,j,k], N.sec[i,k]) # z.sec is used to force the detection to be 0 when no counts occured p[i,j,k] <- exp(lp[i,j,k])/(1+exp(lp[i,j,k])) lp[i,j,k] <- beta0 + beta1 * date[i,j,k] + beta2 * pow(date[i,j,k],2) + beta3 * pow(hour[i,j,k],2) + beta4 * hab[i,j,k] + eps[k] # several cov are used to fit the detection function
# # Assess model fit using Chi-squared discrepancy # I remove this part for the moment, as I would like to be able to get the model as least once ! # # Compute fit statistic E for observed data # eval[i,j,k] <- p[i,j,k] * N.sec[i,k] # Expected values # E[i,j,k] <- pow((y[i,j,k] - eval[i,j,k]),2) / (eval[i,j,k] + 0.5) # # Generate replicate data and compute fit stats for them # y.new[i,j,k] ~ dbin(p[i,j,k], N.sec[i,k]) # E.new[i,j,k] <- pow((y.new[i,j,k] - eval[i,j,k]),2) / (eval[i,j,k] + 0.5) # } #j # for (j in (field[i,k]+1):max(field)){ # eval[i,j,k] <- 0 # E[i,j,k] <- 0 # y.new[i,j,k] <- 0 # E.new[i,j,k] <- 0 } #j } #i } #k # # Derived and other quantities # # Total pop. size across all sectors from the site # # mean abundance on sector of each site # for (k in 1:n.year){ # M[k] <- sum(N.sec[,k]) # this is the standard way to get total abundance # } # fit <- sum(E[,,]) # fit.new <- sum(E.new[,,]) } Error: Error in node beta0Current value is inconsistent with datasink("Nmix_bin.txt")cat(" model { # Priors beta0 ~ dunif(-20,20) beta1 ~ dnorm(0,0.01) beta2 ~ dnorm(0,0.01) beta3 ~ dnorm(0,0.01) beta4 ~ dnorm(0,0.01) for (k in 1:n.year){ lam_tot[k] ~ dgamma(gam1,gam2) eps[k] ~ dnorm(0,tau.p) for (i in 1:n.sec){ lam[i,k] ~ dgamma(10,1) } } tau.p <- pow(sd.p,-2) sd.p ~ dunif(0,5) gam1~dunif(0,50) gam2~dunif(0,50) # Likelihood # Ecological model for true abundance with overdispersion in abundance for (k in 1:n.year){ # Loop over years M[k] ~ dpois(lam_tot[k]) N.sec[1,k] ~ dbin(pi[1,k],M[k]) N.sec[2,k] <- M[k] - N.sec[1,k] pi[1,k] <- lam[1,k]/sum(lam[,k]) # Observation model for replicated counts for (i in 1:n.sec){ for (j in 1:(field[i,k])){ # Loop over temporal reps y[i,j,k] ~ dbin(z.sec[i,k]*p[i,j,k], N.sec[i,k]) # Detection p[i,j,k] <- exp(lp[i,j,k])/(1+exp(lp[i,j,k])) lp[i,j,k] <- beta0 + beta1 * date[i,j,k] + beta2 * pow(date[i,j,k],2) + beta3 * pow(hour[i,j,k],2) + beta4 * hab[i,j,k] + eps[k] } #j } #i } #k
} ",fill = TRUE)sink()
N.sec[1] ~ dbin(pi[1],N)
N.sec[2] ~ dbin(pi[2]/(pi[1]+pi[2]),N-N.sec[1])
...
N.sec[n] ~ dbin(pi[n]/(pi[1]+pi[2]+...+pi[n-1]),N-N.sec[1]-...-N.sec[n-1])