nimble.occ: Estimation of Single-Season Occupancy Models

Description Usage Arguments Details Value Author(s) Examples

View source: R/nim_occupancy.R

Description

nimble.occ is used to fit single species single-season occupancy models using Bayesian estimation. The function returns model summary statistics, posterior draws, and the BUGS code used to estimate the model.

Usage

1
2
3
4
5
nimble.occ(siteformula = NULL, obsformula = NULL, y = NULL,
  sitevars = NULL, obsvars = NULL, priors = c("Normal", "t", "Uniform",
  "Gamma"), dropbase = TRUE, droplast = FALSE, niter = 10000,
  burnin = 1000, initmcmc = c(0.5, 1, 5, 10), chains = 4,
  returncode = TRUE, returnsamp = TRUE, ...)

Arguments

siteformula

A linear model formula for the latent state: log(λ_{i}). Formula must start with a tilde (~). Add -1 to remove intercept. Random effects are specified with a pipe (see lmer). If model contains an intercept random effects will be centered at 0. Interactions can be specified with * (e.g., x*y).

obsformula

A linear model formula for the observation process: logit(p_{i,j}).

y

Detection and non detection data. Must be provided as either a matrix or dataframe. Rows are sites and columns are replicates. 1 is detection and 0 is non detection.

sitevars

A dataframe of site-specific covariates. Must be a dataframe with named columns corresponding to variables. Number of rows should equal the number of sites.

obsvars

A named list with site and survey specific covariates. Each list element is a matrix with rows corresponding to site and columns to replicate. Variables specified in the model must match the variable names in the list.

priors

One prior is specified for all model parameters in the siteformula and obsformula model statements. The default prior is a Normal(mu = 0, sd = 1000). Other options are t(mu = 0, tau = 1000, df = 5), Uniform(0, 1000), and Gamma(shape = .001, rate = .001).

dropbase

Drops the first level of a factor variable. Default is TRUE.

droplast

Drops the last level of a factor variable. Default is FALSE.

niter

Number of iterations to run the MCMC. Default is 10,000 iterations.

burnin

Number of burnin iterations for MCMC. Default is 1000 iterations.

initmcmc

Vector of initial values for MCMC. Length of vector must equal the number of chains. The same initial values are used for all parameters. Default is c(1, 5, 10, 15)

chains

Number of MCMC chains to run. Default is 4.

returncode

Option to return the BUGS code passed to NIMBLE. Default is TRUE.

returnsamp

Option to return all posterior draws. Default is TRUE

...

Additional arguments can be passed to specify different parameters for the priors. Options are location, scale, lb, ub, df, shape, and rate.

Details

This is a function for fitting Single Season-Occupany Models using a Bayeisan framework. The model structure is:

z_{i} ~ Bernoulli(ψ_{i})

y_{i,j} | z_{i} ~ Bernoulli(z_{i} * p_{i,j})

Where i is the number of sites and j the number of temporal replicates. z is a binary latent variable for the true observed state (occupied or not occupied). Both ψ and p can be modeled as a linear function of covariates via a linked GLM. The link for ψ and p is the logit link. Estimation is performed using NIMBLE. In addition to fitting the model, generated BUGS code for the full model, as well as posterior draws, are returned.

Value

Output is a named list with the following elements: Summary, BUGScode, and Samples. In the Summary statement, variables from the siteformula will start with "s.", and variables in the obsformula will start with "o." Note: parameters are on the transformed scale (log for siteformula variables; logit for obsformula variables). In addition to quantiles, the effective sample size effectiveSize and Gelman Rubin diagnoistic gelman.diag are provided from the coda package.

Author(s)

Colin Lewis-Beck

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Simualte Occupancy Data
R <- 200
T <- 3
X <- sort(runif(n = R, min = -1, max = 1))
Y <- sort(rgamma(n = R, shape = 1, rate = 1))
sim.covariates <- data.frame("X" = X, "Y" = Y)
psi <- plogis(-1 + 2*X)
p <- plogis(1 - 3*X + 4*Y + 4*X*Y)
z <- rbinom(n = R, size = 1, prob = psi)
y <- matrix(NA, nrow = R, ncol = T)
for (i in 1:T){y[,i] <- rbinom(n = R, size = 1, prob = z*p)}


#Fit Model
model <- nimble.occ(siteformula = ~ 1 + X, obsformula = ~ 1 + X +
Y + X*Y, y = y, sitevars = sim.covariates, priors = "t", initmcmc = c(.5,
1.5, 3, 5), chains = 4)

clewisbe/nimbleEco documentation built on May 27, 2019, 7:25 a.m.