Simulate a spatially distributed population, sample from that population with an array of detectors, and optionally fit an SECR model to the simulated data.
1 2 3 4 5 6 7 8 9 10
## S3 method for class 'secr' simulate(object, nsim = 1, seed = NULL, maxperpoly = 100, chat = 1, ...) sim.secr(object, nsim = 1, extractfn = function(x) c(deviance = deviance(x), df = df.residual(x)), seed = NULL, maxperpoly = 100, data = NULL, tracelevel = 1, hessian = c("none", "auto", "fdHess"), start = object$fit$par, ncores = NULL) sim.detect(object, popnlist, maxperpoly = 100, renumber = TRUE)
a fitted secr model
integer number of replicates
either NULL or an integer that will be used in a call to
integer maximum number of detections of an individual in one polygon or transect on any occasion
real value for overdispersion parameter
integer number of threads used by
function to extract output values from fitted model
optional list of simulated data saved from previous call to
integer for level of detail in reporting (0,1,2)
character or logical controlling the computation of the Hessian matrix
vector of starting ‘beta’ values for
other arguments (not used)
list of popn objects
logical; if TRUE then
For each replicate,
generate session- and group-specific realizations of the (possibly
inhomogeneous) 2-D Poisson distribution fitted in
the habitat mask(s) in
object. Group subpopulations are combined
rbind.popn within each session; information to
reconstruct groups is retained in the individual-level factor
covariate(s) of the resulting
popn object (corresponding to
object$groups). Each population is then sampled using the fitted
detection model and detector (trap) array(s) in
The random number seed is managed as in
Certain model types are not supported by
include models fitted using conditional likelihood (
TRUE), telemetry models and exotic behavioural response models.
Detector type is determined by
sim.secr is a wrapper function. If
data = NULL (the
default) then it calls
simulate.secr to generate
nsim new datasets. If
data is provided then
nsim is taken to be
secr.fit is called to fit the original model
to each new dataset. Results are summarized according to the
extractfn. The default
returns the deviance and its degrees of freedom; a NULL value for
extractfn returns the fitted secr objects after
trimming to reduce bulk. Simulation uses the detector type
of the data, even when another likelihood is fitted (this is the case
with single-catch data, for which a multi-catch likelihood is fitted).
Warning messages from
secr.fit are suppressed.
extractfn should be a function that takes an
as its only argument.
tracelevel=0 suppresses most messages;
tracelevel=1 gives a
terse message at the start of each fit;
tracelevel=2 also sets
‘details$trace = TRUE’ for
secr.fit, causing each likelihood
evaluation to be reported.
hessian controls computation of the Hessian matrix from which
variances and covariances are obtained.
hessian replaces the
object\$details. Options are "none" (no variances),
"auto" (the default) or "fdhess" (see
secr.fit). It is OK
(and faster) to use
variances or covariances. Logical TRUE and FALSE are interpreted by
secr.fit as "auto" and "none".
ncores = NULL then the existing value from the environment variable
RCPP_PARALLEL_NUM_THREADS is used (see
sim.capthist is a more direct way to simulate data from a null
model (i.e. one with constant parameters for density and detection), or
from a time-varying model.
sim.detect is a function used internally that will not usually be
simulate.secr, a list of data sets (‘capthist’ objects). This
list has class
c("secrdata", "list"); the initial state of the random
number generator (roughly, the value of .Random.seed) is stored as the
The value from
sim.secr depends on
extractfn: if that
returns a numeric vector of length
n.extract then the value is a
dim = c(nsim, n.extract) (i.e., the matrix has one
row per replicate and one column for each extracted value). Otherwise,
the value returned by
sim.secr is a list with one component per
replicate (strictly, an object of class =
c("secrlist", "list")). Each
simulated fit may be retrieved in toto by specifying
extractfn = identity, or slimmed down by specifying
extractfn = NULL or
extractfn = trim, which are
For either form of output from
sim.secr the initial state of the
random number generator is stored as the attribute ‘seed’.
sim.detect a list of ‘capthist’ objects.
The value returned by
simulate.secr is a list of ‘capthist’
objects; if there is more than one session, each ‘capthist’ is itself a
sort of list .
The classes ‘secrdata’ and ‘secrlist’ are used only to override the ugly
and usually unwanted printing of the seed attribute. However, a few
other methods are available for ‘secrlist’ objects
The default value for
sim.secr is the previously
fitted parameter vector. Alternatives are NULL or
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
## Not run: ## previously fitted model simulate(secrdemo.0, nsim = 2) ## The following has been superceded by secr.test() ## this would take a long time... sims <- sim.secr(secrdemo.0, nsim = 99) deviance(secrdemo.0) devs <- c(deviance(secrdemo.0),sims$deviance) quantile(devs, probs=c(0.95)) rank(devs) / length(devs) ## to assess bias and CI coverage extrfn <- function (object) unlist(predict(object)["D",-1]) sims <- sim.secr(secrdemo.0, nsim = 50, hessian = "auto", extractfn = extrfn) sims ## with a larger sample, could get parametric bootstrap CI quantile(sims[,1], c(0.025, 0.975)) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.