nimble.dynamic.occ: Estimation of Dynamic (MultiSeason) Single-Species Occupancy...

Description Usage Arguments Details Value Author(s) Examples

View source: R/nim_dynamic_occupancy.R

Description

nimble.dynamic.occ fits single species multi-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
6
nimble.dynamic.occ(psiformula = NULL, phiformula = NULL,
  gammaformula = NULL, pformula = NULL, y = NULL, site = NULL,
  site.season = NULL, site.season.survey = NULL, priors = c("Normal", "t",
  "Uniform", "Gamma"), dropbase = TRUE, droplast = TRUE, niter = 10000,
  burnin = 1000, initmcmc = c(0.5, 1, 5, 10), chains = 4,
  returncode = TRUE, returnsamp = TRUE, ...)

Arguments

psiformula

A linear model formula for first year occupancy: logit(ψ_{1}). 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).

phiformula

A linear model formula for survival probability: logit(φ_{i,k})

gammaformula

A linear model formula for the probability of colonization: logit(γ_{i,k}).

pformula

A linear model formula for the probability of detection: logit(p{i,j,k}).

y

A 3 dimensinoal array (site, survey, season) with binary values: 1 for detection, 0 otherwise.

site

A data frame or matrix. Rows are sites and columns (with variable names) are independent variables.

site.season

A named list (rows site, columns season) with each list element corresponding to an independent variable. Variables specified in the model must match the variable names in the list.

site.season.survey

A named list of arrays (site, survey, season) with each name corresponding to an independent variable. 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 = 1). 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 TRUE.

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 Multiseason Single Species Site Occupancy Models using a Bayeisan framework. The model structure is:

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

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

z_{k+1}|z_{k} ~ Bernoulli(z_{k} * φ_{i,k} + (1-z{k}) * γ_{i,k})

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

Where i indexing site, j indexes survey, and k indexes the season. z is a binary latent variable for the true observed state (occupied or not occupied). The parameter ψ_{1} (first year occupancy) can be modeled as a linear function of site covariates; φ_{i,k} (probability of local survial), and γ_{i,k} (colonization probabiliy) can be modeled as linear functions of site and site.season covariates; and p_{i,j,k} (detection probability) can be modeled as a linear function of site, site.season, or site.season.survey covariates. A logit link is used for all 3 models.

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 psiformula will start with "s.", variables in the phiformula will start with "phi.", variables from the gammaformula will start with "gam.", and variables from the pformula will start with "p.". Also, note parameters are on the transformed scale (logit). 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
18
# Simualte Data R <- 100 #Number of Sites J <- 3 #Number of Surveys K <- 10
#Number of Seasons psi1 <- 0.4 #First year occupancy probability psi <-
rep(NA, K) muZ <- z <- array(dim = c(R, K)) y <- array(NA, dim = c(R, J, K))
psi[1] <- psi1 p <- runif(n = K, min = 0.20, max = 0.40) phi <- runif(n =
K-1, min = 0.60, max = 0.80) gamma <- runif(n = K-1, min = 0, max = 0.10)

#Generate Occurance states z[,1] <- rbinom(R, 1, psi[1]) for (i in 1:R){ for
(k in 2:K){ muZ[k] <- z[i, k-1]*phi[k-1] + (1-z[i,k-1])*gamma[k-1] z[i,k] <-
rbinom(1,1,muZ[k]) } }

#Generate detection/nondetection data for (i in 1:R){ for(k in 1:K){ prob <-
z[i,k]*p[k] for (j in 1:J){ y[i,j,k] <- rbinom(1, 1, prob) } } }


#Fit Model
model <- nimble.dynamic.occ(psiformula = ~ 1, phiformula = ~ -1 +
Season, gammaformula = ~ -1 + Season, pformula = ~ -1 + Season, y = y,
initmcmc = 1, chains = 1, dropbase = FALSE)

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