Description Usage Arguments Details Value Author(s) See Also Examples
dOcc_*
and rOcc_*
provide occupancy model
distributions that can be used directly from R or in nimble
models.
1 2 3 4 5 6 7 
x 
detection/nondetection vector of 0s (not detected) and 1s (detected). 
probOcc 
occupancy probability (scalar). 
probDetect 
detection probability (scalar for 
len 
length of detection/nondetection vector (see below). 
log 
TRUE or 1 to return log probability. FALSE or 0 to return probability. 
n 
number of random draws, each returning a vector of length

These nimbleFunctions provide distributions that can be used directly in R or
in nimble
hierarchical models (via nimbleCode
and nimbleModel
).
The probability of observation vector x
depends on
occupancy probability, probOcc
, and detection probability,
probDetect
or probDetect[1:T]
.
The letter following the 'dOcc_' indicates whether detection probability is
scalar (s, meaning probDetect
is detection probability for every
x[t]
) or vector (v, meaning probDetect[t]
is detection
probability for x[t]
).
When used directly from R, the len
argument to dOcc_*
is not
necessary. It will default to the length of x
. When used in
nimble
model code (via nimbleCode
), len
must be provided
(even though it may seem redundant).
For more explanation, see package vignette
(vignette("Introduction_to_nimbleEcology")
).
Compared to writing nimble
models with a discrete latent state for
true occupancy status and a separate scalar datum for each observation, use
of these distributions allows one to directly sum (marginalize) over the
discrete latent state and calculate the probability of all observations from
one site jointly.
These are nimbleFunction
s written in the format of userdefined
distributions for NIMBLE's extension of the BUGS model language. More
information can be found in the NIMBLE User Manual at
https://rnimble.org.
When using these distributions in a nimble
model, the lefthand side
will be used as x
, and the user should not provide the log
argument.
For example, in nimble
model code,
detections[i, 1:T] ~ dOcc_s(occupancyProbability,
detectionProbability, T)
declares that detections[i, 1:T]
(detection history at site i
,
for example) follows an occupancy distribution with parameters as indicated,
assuming all the parameters have been declared elsewhere in the model. This
will invoke (something like) the following call to dOcc_s
when
nimble
uses the model such as for MCMC:
dOcc_s(detections[i, 1:T], occupancyProbability,
detectionProbability, len = T, log = TRUE)
If an algorithm using a nimble
model with this declaration
needs to generate a random draw for detections[i, 1:T]
, it
will make a similar invocation of rOcc_s
, with n = 1
.
If the detection probabilities are timedependent, use:
detections[i, 1:T] ~ dOcc_v(occupancyProbability,
detectionProbability[1:T], len = T)
For dOcc_*
: the probability (or likelihood) or log probability of observation vector x
.
For rOcc_*
: a simulated detection history, x
.
Ben Goldstein, Perry de Valpine, and Lauren Ponisio
For dynamic occupancy models, see documentation for
dDynOcc
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  # Set up constants and initial values for defining the model
dat < c(1,1,0,0) # A vector of observations
probOcc < 0.6
probDetect < 0.4
# Define code for a nimbleModel
nc < nimbleCode({
x[1:4] ~ dOcc_s(probOcc, probDetect, len = 4)
probOcc ~ dunif(0,1)
probDetect ~ dunif(0,1)
})
# Build the model, providing data and initial values
Occ_model < nimbleModel(nc, data = list(x = dat),
inits = list(probOcc = probOcc,
probDetect = probDetect))
# Calculate log probability of data from the model
Occ_model$calculate()
# Use the model for a variety of other purposes...

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.