Creates model code using the nimbleCode function.

get_discrete(
  type = "marked",
  dim_y = NULL,
  occ_specific = FALSE,
  enc_dist = "binomial",
  sex_sigma = FALSE,
  trapsClustered = FALSE
)

Arguments

type

Specifies the type of discrete model for either "marked" (the default) or "unmarked" data sources.

dim_y

Either NULL (the default) or an integer of either 2 or 3 that define the dimensional format the encounter history data are in. Note that this input is not used when type = "unmarked".

occ_specific

Logical. If FALSE, the encounter rate will not include an occasion-specific loop in the detection function; otherwise, the model will include a for loop for occasions (K) in the detection function. Default is FALSE. Only applied when type = "unmarked".

enc_dist

Either "binomial" or "poisson". Default is "binomial".

sex_sigma

A logical value indicating whether the scaling parameter ('sigma') is sex-specific

trapsClustered

A logical value indicating if traps are clustered in arrays across the sampling area.

Value

A nimbleCode object from the nimble package.

Details

This function provides templates that could be copied and easily modified to include further model complexity such as covariates explaining detection probability. These discrete models include different encounter probability distributions and sex-specific scaling parameters for marked and unmarked data sets.

Author

Daniel Eacker

Examples

# get discrete model for 2D marked encounter data, binomial encounter 
# distribution, non-sex-specific scaling parameter, and no clustering of traps
discrete_model_m = get_discrete(type="marked", dim_y = 2,enc_dist = "binomial",
                      sex_sigma = FALSE, trapsClustered = FALSE)

# inspect model
discrete_model_m
#> {
#>     for (j in 1:nPix) {
#>         probs[j] <- mu[j]/EN
#>         mu[j] <- exp(alpha0) * pixArea
#>     }
#>     alpha0 ~ dunif(-20, 20)
#>     EN <- sum(mu[1:nPix])
#>     psi <- EN/M
#>     p0 ~ dunif(0, 1)
#>     sigma ~ dunif(0, sigma_upper)
#>     for (i in 1:M) {
#>         z[i] ~ dbern(psi)
#>         s[i] ~ dcat(probs[1:nPix])
#>         x0g[i] <- grid[s[i], 1]
#>         y0g[i] <- grid[s[i], 2]
#>         dist[i, 1:J] <- sqrt((x0g[i] - X[1:J, 1])^2 + (y0g[i] - 
#>             X[1:J, 2])^2)
#>         p[i, 1:J] <- p0 * exp(-dist[i, 1:J]^2/(2 * sigma^2))
#>     }
#>     for (i in 1:n0) {
#>         for (j in 1:J) {
#>             y[i, j] ~ dbin(p[i, j], K)
#>         }
#>     }
#>     for (i in (n0 + 1):M) {
#>         zeros[i] ~ dbern((1 - prod(1 - p[i, 1:J])^K) * z[i])
#>     }
#>     N <- sum(z[1:M])
#>     D <- N/A
#> }

# get discrete model for unmarked encounter data, binomial encounter 
# distribution, non-sex-specific scaling parameter, and no clustering of traps
discrete_model_u = get_discrete(type="unmarked",occ_specific = FALSE,
           enc_dist = "binomial",sex_sigma = FALSE, trapsClustered = FALSE)

# inspect model
discrete_model_u
#> {
#>     for (j in 1:nPix) {
#>         probs[j] <- mu[j]/EN
#>         mu[j] <- exp(alpha0) * pixArea
#>     }
#>     alpha0 ~ dunif(-20, 20)
#>     EN <- sum(mu[1:nPix])
#>     psiu <- EN/m
#>     lam0 ~ dunif(0, lam0_upper)
#>     sigma ~ dunif(0, sigma_upper)
#>     for (i in 1:m) {
#>         zu[i] ~ dbern(psiu)
#>         su[i] ~ dcat(probs[1:nPix])
#>         x0gu[i] <- grid[su[i], 1]
#>         y0gu[i] <- grid[su[i], 2]
#>         distu[i, 1:J] <- sqrt((x0gu[i] - X[1:J, 1])^2 + (y0gu[i] - 
#>             X[1:J, 2])^2)
#>         lamu[i, 1:J] <- lam0 * exp(-distu[i, 1:J]^2/(2 * sigma^2)) * 
#>             zu[i]
#>     }
#>     for (j in 1:J) {
#>         bigLambda[j] <- sum(lamu[1:m, j])
#>         for (k in 1:K) {
#>             n[j, k] ~ dpois(bigLambda[j])
#>         }
#>     }
#>     N <- sum(zu[1:m])
#>     D <- N/A
#> }