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 user-defined
distributions for NIMBLE's extension of the BUGS model language. More
information can be found in the NIMBLE User Manual at
https://r-nimble.org.
When using these distributions in a nimble
model, the left-hand 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 time-dependent, use:
detections[i, 1:T] ~ dOcc_v(occupancyProbability,
detectionProbability[1:T], len = T)