Overview

To run an occupancy model with RPresence, there are two main functions to use:

Create presence-absence-object (pao) with createPao

To create input data for RPresence, we need at a minimum a detection-history matrix containing 0’s and 1’s (and possibly “-” for missing data), with sites as rows and surveys as columns of the matrix.

Here’s an example of detection data for 6 sites and 5 surveys:

##   day1 day2 day3 day4 day5
## 1    0    0    0    0   NA
## 2    0    0    0    0   NA
## 3    0    0    0    1   NA
## 4    0    0    0    0   NA
## 5    0    0    0    0   NA
## 6    0    0    0    0   NA

Usually, there will be covariates to be used with the data which may affect occupancy and/or detection in a model. Covariates which are constant over all surveys are “site” or “unit” covariates, and covariates which possibly change with each survey are “survey” covariates. The site covariate matrix should contain N rows and M columns, where N is the number of sites and M is the number of site-covariates. Here’s an example of a site-covariate matrix for 6 sites and 2 site-covariates:

##   Browsed Unbrowsed
## 1       1         0
## 2       1         0
## 3       1         0
## 4       0         1
## 5       1         0
## 6       0         1

Each survey covariate will need to be co-erced into a vector, then the vectors added to a data-frame. For example, if we have a N by M survey covariate named, “observer” and another N by M covariate named “surveyDate”, then we would convert each covariate to a vector, then create a data-frame with those two variables. Here’s a sample code snippet:

surveycov <- data.frame(
                obs=unlist(observer),
                sdate=unlist(surveyDate)
)

Here, we used the R function, unlist, to convert the two N by M matrices into vectors of length, N * M. With 6 sites and 5 surveys, each vector will be of length, 30, with the first 6 values corresponding to sites 1 to 6, survey 1, the next 6 sites corresponding to sites 1 to 6, survey 2,…etc.

So, here’s the code to read a csv file with the Weta data (included with RPresence), with 2 site covariates and 1 survey covariate:

csv <- read.csv( 
  system.file("extdata", "weta.csv", package="RPresence"), # Get file from RPresence package
  skip=1,                                                  #  Skip header line 1
  na.strings='-')                                          #  "-" in input means missing data

detectionData <- csv[,1:5]        # detection data in cols 1-5

unitcov <- csv[,7:8]              # site covariates in cols 7-8 (Browsed, Unbrowsed)

surveycov <- data.frame(          # survey covariate (observer) in cols 10-15
                obs=unlist(csv[,10:14])
)

myPao <- createPao(data=detectionData,   # create presence-absence-object w/ detection data,
                   unitcov=unitcov,      #  unitcov and survcov
                   survcov=surveycov)    #  see help(createPao) for other arguments

Running a model with occMod

With the presence-absence-object, myPao created, we can run a single-season model using the occMod function. There are many optional arguments to this function, so use the help function to see what they are: help(occMod).

To get started, you can run a model with occupancy and detection constant across all sites and surveys. The R-GLM formula notation for a model with a constant parameter is simply, parameter~1, where parameter is either “psi” for occupancy, or “p” for detection.

m1_psi_dot_p_dot <- occmod( # call occMod function 
  model=list(psi~1, p~1),   #  with constant occupancy (psi~1) and detection (p~1)
  data=myPao)               #  using presence-absence-object, myPao

Models with covariates

Occupancy may be modelled as a function of site covariates and detection (p) may be modelled as a function of site or survey covariates. To model occupancy as a function of the site-covariate, Browsed, simply include it in the model formula for occupancy, psi.

m2_psi_Browsed_p_dot <- occmod(
  model=list(psi~Browsed), p~1),
  data=myPao)

To model detection as a function of the Browsed covariate…

m3_psi_dot_p_Browsed <- occmod(
  model=list(psi~1), p~Browsed),
  data=myPao)

For all model-types, a built-in covariate named, SURVEY is created by the occMod function and may be used to model survey-specific detection. For example,

m4_psi_Browsed_p_SURVEY <- occmod(
  model=list(psi~Browsed), p~SURVEY),
  data=myPao)

The above model produces occupancy estimates for browsed and unbrowsed sites and detection estimates which (possibly) differ for each of the 5 surveys.