core
must contain columns `x' and `y'; a traps
object is
suitable. For buffertype = "rect"
, animals are simulated in the
rectangular area obtained by extending the bounding box of core
by buffer
metres to top and bottom, left and right. This box has
area \(A\). If model2D = 'poisson'
the buffer type may also be `convex' (points within a buffered convex polygon) or `concave' (corresponding to a mask of type `trapbuffer'); these buffer types use bufferContour
.
Covariates may be specified in either of two ways. In the first, each element of covariates
defines a categorical (factor) covariate with the given probabilities of membership in each class. In the second, the 'covariates' argument is a function (or a character value naming a function) that takes a dataframe of x and y coordinates as its sole argument; the function should return a dataframe with the same number of rows that will be used as the covariates attribute (secr >= 4.6.7).
A notional random covariate `sex' is generated by default.
Ndist should usually be `poisson' or `fixed'. The number of individuals \(N\) has
expected value \(DA\). If \(DA\) is non-integer then Ndist = "fixed"
results in \(N \in \{ \mathrm{trunc}(DA), \mathrm{trunc}(DA)+1 \} \), with probabilities set to yield
\(DA\) individuals on average. The option `specified' is undocumented;
it is used in some open-population simulations.
If model2D = "cluster"
then the simulated population approximates a Neyman-Scott
clustered Poisson distribution. Ancillary parameters are passed as
components of details
: details$mu is the expected number of
individuals per cluster and details$hsigma is the spatial scale
(\(\sigma\)) of a 2-D kernel for location within each cluster.
The algorithm is
Determine the number of clusters (parents) as a random Poisson variate
with \(\lambda = DA/\mu\)
Locate each parent by drawing uniform random x- and y-coordinates
Determine number of offspring for each parent by drawing from a Poisson distribution with mean mu
Locate offspring by adding random normal error to each parent coordinate
Apply toroidal wrapping to ensure all offspring locations are
inside the buffered area
A special cluster option is selected if details$clone = "constant": then each parent is cloned exactly details$mu times.
Toroidal wrapping is a compromise. The result is more faithful to the
Neyman-Scott distribution if the buffer is large enough that only a
small proportion of the points are wrapped.
If model2D = "IHP"
then an inhomogeneous Poisson distribution is
simulated. core
should be a habitat mask and D
should be one of --
a vector of length equal to the number of cells (rows)
in core
,
the name of a covariate in core
that contains
cell-specific densities (animals / hectare),
a function to generate the intensity of the distribution at each mask point, or
a constant.
If a function, D
should take two arguments, a habitat mask and a list of
parameter values ('core' and 'details' are passed internally as these arguments).
A function may be given by name (i.e. as a character value); this is required
when nsessions>1.
The number
of individuals in each cell is either (i) Poisson-distributed with mean
\(DA\) where \(A\) is the cell area (an attribute of the mask)
(Ndist = "poisson"
) or (ii) multinomial with size \(DA\) and
relative cell probabilities given by D (Ndist =
"fixed"
). buffertype
and buffer
are ignored, as the
extent of the population is governed entirely by the mask in
core
.
If model2D = "linear"
then a linear population is simulated as
for model2D = "IHP"
, except that core
should be a
linearmask object from package secrlinear, and density (D) is
expressed in animals per km. The documentation of secrlinear
should be consulted for further detail (e.g. the wrapper function
sim.linearpopn
).
If model2D = "coastal"
then a form of inhomogeneous Poisson
distribution is simulated in which the x- and y-coordinates are drawn from
independent Beta distributions. Default parameters generate the
`coastal' distribution used by Fewster and Buckland (2004) for
simulations of line-transect distance sampling (x ~ Beta(1, 1.5), y ~
Beta(5, 1), which places 50% of the population in the `northern' 13%
of the rectangle). The four Beta parameters may be supplied in the
vector component Beta of the `details' list (see Examples). The Beta
parameters (1,1) give a uniform distribution. Coordinates are scaled to
fit the limits of a sampled rectangle, so this method assumes buffertype
= "rect".
If model2D = "hills"
then a form of inhomogeneous Poisson
distribution is simulated in which intensity is a sine curve in the x-
and y- directions (density varies symmetrically between 0 and 2 x D
along each axis). The number of hills in each direction (default 1) is
determined by the `hills' component of the `details' list (e.g. details
= list(hills=c(2,3)) for 6 hills). If either number is negative then
alternate rows will be offset by half a hill. Displacements of the
entire pattern to the right and top are indicated by further elements of
the `hills' component (e.g. details = list(hills=c(1,1,0.5,0.5)) for 1
hill shifted half a unit to the top right; coordinates are wrapped, so
the effect is to split the hill into the four corners). Negative
displacements are replaced by runif(1). Density is zero at the edge when
the displacement vector is (0,0) and rows are not offset.
If model2D = "even"
then the buffered area is divided into square cells with side sqrt(10000/D) and one animal is located at a random uniform location within each cell. If the height or width is not an exact multiple of the cell side then one whole extra row or column of cells is added; animals located at random in these cells are discarded if they fall outside the original area.
From secr 4.6.2, sim.popn
provides an interface to two simulation
functions from spatstat (Baddeley et al. 2015): rLGCP
and rThomas
.
If model2D = "rLGCP"
then a log-gaussian Cox process is simulated within
the buffered area. Function rLGCP
in recent versions of spatstat
uses internal code rather than Schlather et al. (2015) as previously.
The algorithm first constructs the log spatial intensity as a realisation of a
Gaussian random field; one realisation of an IHP with that intensity is then simulated.
The parameters for model2D = "rLGCP"
are the scalar density (D) and
the variance and spatial scale of the random field (passed as details arguments
`var' and `scale'). The variance is on the log scale; the mean on the log scale
is computed internally as mu = log(D) - var/2. var = 0 results in a random uniform
(Poisson) distribution. When details$saveLambda = TRUE, the discretized intensity
function is saved as the attribute "Lambda", a habitat mask with covariate
"Lambda" that may be used to construct further IHP realisations (see Examples).
If model2D = "rThomas"
then a Thomas process is simulated. This is a special
case of the Neyman-Scott process in which each parent gives rise to a Poisson number
of offspring (see Notes). The expected number of offspring per parent and the
spatial scatter about each parent are specified by the details arguments `mu'
and `scale'. Argument `kappa' of rThomas
(density of parent process) is
computed as D/mu/1e4. Other arguments remain at their defaults, including `expand'
(4 * scale). A dataframe of parent locations is saved in attribute `parents'.
The intensity surface for each realisation is saved in attribute 'Lambda' when
details$saveLambda = TRUE.
Clipping to a polygon (poly) is supported for both rLGCP and
rThomas in secr >= 5.2.2, but care is needed. The boundary coordinates must
be given anticlockwise and not include duplicates (even first and last).
Conditional simulation (Ndist = 'fixed') is supported for both rLGCP and
rThomas in secr >= 5.2.2. The n.cond argument of the respective spatstat
functions is set internally by `sim.popn`. The rejection algorithm may fail.
Set details$verbose = TRUE for detailed reporting.
If poly
is specified, points outside poly
are
dropped. poly
may be one of the types descrbed in
boundarytoSF
.
The subset
method is called internally when poly
is used;
the ... argument may be used to pass values for keep.poly
and
poly.habitat
.
Multi-session populations may be generated with nsessions > 1
.
Multi-session populations may be independent or generated by per capita
turnover from a starting population. In the `independent' case
(details$lambda
not specified) D or Nbuffer may be a vector of length equal to
nsessions
. Turnover is controlled by survival, growth rate and movement
parameters provided as components of details
and described in turnover.
The optional covariate 'age' is the number of sessions from the session of recruitment.
The random number seed is managed as in simulate.lm
.
Function tile
replicates a popn pattern by either reflecting or
copying and translating it to fill a 3 x 3 grid.