occupancy: fit occupancy-detection models

Description Usage Arguments Details Value Examples

Description

occupancy is a function to fit occupancy-detection models in JAGS from within R. Models are specified with a formula interface and are supported by methods to summarise, visualise, validate, and predict from fitted models.

occupancy lets you fit occupancy-detection models in JAGS without having to prepare JAGS code. Models are specified with a formula interface and can incorporate random effects. Models are supported by several methods to summarise, visualise, validate, and predict from fitted models.

Usage

1
2
occupancy(formula_occ, formula_detect, site_id, survey_id, data,
  jags_settings = list())

Arguments

formula_occ

model formula for occupancy component of the model. A two-sided formula with the response variable on the left of the ~ operator and the predictor variables on the right. Multiple predictor variables are separated by + operators. Random effects are included with vertical bars, using the notation (1 | group) to specify a random intercept for the variable group. More complex random structures (e.g., random slopes) are not supported.

formula_detect

model formula for detection component of the model. A one-sided formula with predictor variables on the right, formatted as for formula_occ.

site_id

the name of the column in data in which site identifiers are recorded.

survey_id

the name of the column in data in which survey identifiers are recorded.

data

a data.frame in long format containing data on all variables. Required variables include the response (detection-nondetection data), site and survey identifiers (see site_id and survey_id, above), and predictor variables. Column names must match the names used in formula_occ and formula_detect.

jags_settings

optional list of MCMC settings. Any or all items can be altered if needed. Options are:

n_iter

the total number of MCMC iterations (including burn-in)

n_burnin

the number of MCMC iterations to discard as a burn-in

n_chains

the number of MCMC chains

n_thin

thinning rate of MCMC samples

parallel

logical, should chains be run in parallel?

modules

JAGS modules to load

params

character vector of parameters to store

seed

seed used to initialise MCMC chains

Details

This function fits an occupancy-detection model in JAGS from two formulas: formula_occ and formula_detect. Occupancy-detection models separate the two processes of being present at a site and being detect given presence at a site. This requires data from repeated visits (surveys) to sites.

The occupancy component of the model (presence at a site) is defined at the site level. The detection component of the model (detections given presence) is defined at the survey level. The model assumes that associations between occupancy/detection and predictor variables are linear on a logit scale.

Value

occupancy_model - a list object that can be analysed using functions described in methods.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## Not run: 

# fit a model to simulated data
mod <- occupancy(response ~ occ_predictor1 + occ_predictor2 + 
                    (1 | occ_random1) + (1 | occ_random2),
                  ~ detect_predictor1 + detect_predictor2 + 
                   (1 | detect_random1),
               site_id = "site",
               survey_id = "survey",
               data = occupancy_data,
               jags_settings = list(n_iter = 1000, n_burnin = 500, n_thin = 2))
               
# plot the model coefficients
par(mfrow = c(2, 1))
plot(mod)

# extract the model coefficients
coef(mod)

# check model fit
calculate_metrics(mod)
     

## End(Not run)

## Not run: 
# a simple occupancy-detection model for artificial data

# build and sample

# plot coefficients

# validate


## End(Not run)

jdyen/occupancy documentation built on July 8, 2019, 3:33 a.m.