Working from the example code associated with the function make.detectability, I wanted to simulate a study with multiple strata and multiple species within each stratum.
The make.detectability example works, as far as it goes, but I added to the example, a survey design and a simulation to actually simulate a survey.
No replicate from the simulation produced results, because no animals were detected.
Digging into the code, I discovered the following via debug():
My first stop in debugging was simulate.detections that generated the error messages.
simulate.detections
determines what animals are detected
uses poss.distances
how is that constructed
because scale.param within poss.distances is NA
However, the problem did not arise in simulate.detections, but rather in calculate.scale.param
calculate.scale.param
does what it is named
creates scale parameter value for each animal
problems when there are factor covariates
logic doesn't work when creating factor.cols (lines 61-82)
result is that sum.of.factors (line 80) is filled with NA
When I remove the factor covariate (sex) and work only with the continuous covariate (size), no problems arise
Therefore the solution to the problem of using factor covariates in the detection function lays within the portion of code following this line
Working from the example code associated with the function
make.detectability
, I wanted to simulate a study with multiple strata and multiple species within each stratum.The
make.detectability
example works, as far as it goes, but I added to the example, a survey design and a simulation to actually simulate a survey.Minimum reproducable example
No replicate from the simulation produced results, because no animals were detected.
Digging into the code, I discovered the following via
debug()
:My first stop in debugging was
simulate.detections
that generated the error messages.simulate.detections
poss.distances
scale.param
withinposs.distances
is NAHowever, the problem did not arise in
simulate.detections
, but rather incalculate.scale.param
calculate.scale.param
factor.cols
(lines 61-82)sum.of.factors
(line 80) is filled with NA When I remove the factor covariate (sex) and work only with the continuous covariate (size), no problems ariseTherefore the solution to the problem of using factor covariates in the detection function lays within the portion of code following this line