#' # Population Models #' #' This file contains JAGS code for fitting each of the different populations models. The models and priors #' are specified exactly as in the PVAClone package. The PVAClone package, however, does not allow one to specify the number #' of clones =1, as done here (i.e., PVAClone does not allow one to fit models under a Bayesian framework). #' #' #--------------------------------------------------------------------------------------- #' ## Density Independent Models #' #' #' ### Density-Independent Model Without Observation Error di.noerror<-function(){ N[1] <- exp(x[1]) for (j in 2:T) { x[j] ~ dnorm(mu[j], prcx) mu[j] <- a + x[j-1] N[j] <- min(exp(x[j]), 10000) } a ~ dnorm(1, 0.01) sigma <- exp(lnsigma) lnsigma ~ dnorm(0, 1) prcx <- 1/sigma^2 } #' ### Density-Independent Model with Poisson Observation Error #' di.Poisson<-function() { N[1] <- O[1] x[1] <- log(O[1]) for (j in 2:T) { x[j] ~ dnorm(mu[j], prcx) mu[j] <- a + x[j-1] N[j] <- min(exp(x[j]), 10000) O[j] ~ dpois(N[j]) } a ~ dnorm(1, 0.01) sigma <- exp(lnsigma) lnsigma ~ dnorm(0, 1) prcx <- 1/sigma^2 } #' ### Density-Independent Model with Log-Normal Observation Error #' di.LogN<-function(){ N[1] <- exp(y[1]) x[1] <- y[1] for (j in 2:T) { x[j] ~ dnorm(mu[j], prcx) mu[j] <- a + x[j-1] N[j] <- min(exp(x[j]), 10000) y[j] ~ dnorm(x[j], prcy) } sigma <- exp(lnsigma) tau <- exp(lntau) lnsigma ~ dnorm(0, 1) lntau ~ dnorm(0, 1) a ~ dnorm(0, 0.01) prcx <- 1/sigma^2 prcy <- 1/tau^2 } #--------------------------------------------------------------------------------------- #' ## Ricker models #' #' ### Ricker model without observation error #' Ricker.noerror<-function() { N[1] <- exp(x[1]) for (j in 2:T) { x[j] ~ dnorm(mu[j], prcx) mu[j] <- a + b * N[j-1] + x[j-1] N[j] <- min(exp(x[j]), 10000) } a ~ dnorm(1, 0.01) b ~ dnorm(0, 10) sigma <- exp(lnsigma) lnsigma ~ dnorm(0, 1) prcx <- 1/sigma^2 } #' ### Ricker model with Poisson observation error #' Ricker.Poisson<-function() { N[1] <- O[1] x[1] <- log(O[1]) for (j in 2:T) { x[j] ~ dnorm(mu[j], prcx) mu[j] <- a + b * N[j-1] + x[j-1] N[j] <- min(exp(x[j]), 10000) O[j] ~ dpois(N[j]) } a ~ dnorm(1, 0.01) b ~ dnorm(0, 10) sigma <- exp(lnsigma) lnsigma ~ dnorm(0, 1) prcx <- 1/sigma^2 } #' ### Ricker model with Log-Normal observation error #' Ricker.LogN<-function(){ N[1] <- exp(y[1]) x[1] <- y[1] for (j in 2:T) { x[j] ~ dnorm(mu[j], prcx) mu[j] <- a + b * N[j-1] + x[j-1] N[j] <- min(exp(x[j]), 10000) y[j] ~ dnorm(x[j], prcy) } sigma <- exp(lnsigma) tau <- exp(lntau) lnsigma ~ dnorm(0, 1) lntau ~ dnorm(0, 1) a ~ dnorm(0, 0.01) b ~ dnorm(0, 10) prcx <- 1/sigma^2 prcy <- 1/tau^2 }