
Simulate closure-unit detection data with known truth
Source:R/sim_closure_unit_data.R
sim_closure_unit_data.RdSimulates single-season data for the closure-unit families, occ()
and the nmix() variants. Each covariate recipe holds per-site
covariates for the latent state and per-visit covariates for
detection. data_train is the long frame mvgam() and jsdgam()
take. y_array is the four-dimensional layout of
pivot_detection_array(). truth holds every generative parameter
for recovery checks.
Arguments
- type
Integer in
1:2selecting the covariate recipe. See Details.- family
A closure-unit family:
occ()(the default),nmix()("poisson_binomial"),nmix("royle_nichols")ornmix("poisson_poisson").- n_species
Integer number of species. Defaults to
1L.- n_sites
Integer number of closure units per species. Defaults to
30L.- n_visits
Integer number of visits to every closure unit. Defaults to
4L.- n_lv
Integer number of latent factors shared by the species' state intercepts. Defaults to
0L, independent species. Requiresn_species > 1L. See Latent factors.- K_max
Integer cap on the latent abundance
Nof annmix()family. Defaults to30L.- seed
Optional integer seed. The session's random state is restored when the call returns.
- object
A
mvgam_sim_closure_unitobject.- ...
Unused. Anything passed here is refused.
- x
A
mvgam_sim_closure_unit_summaryobject.- digits
Integer number of significant digits. Defaults to 3.
Value
A list of class c("mvgam_sim_closure_unit", "mvgam_sim"):
data_trainLong
data.frame. Its columns areseries(the species),site,time(the site, which identifies the closure unit in a single season),visit,y, the site and visit covariates, thencap: 1 forocc(),K_maxfornmix().data_testNULL. Closure-unit data have no held-out times.y_arrayInteger array
[n_species, n_sites, 1, n_visits]forpivot_detection_array().family,typeThe family and recipe.
n_species,n_sites,n_visits,n_lvThe simulation dimensions.
truthThe generative parameters. See Truth bundle.
Details
type = 1State predictor
b0 + b1 * env, withenv ~ N(0, 1)per site. Detection predictorc0 + c1 * tod_c, withtod_c ~ U(-6, 6)per visit, a centred time of day.type = 2State predictor
b0 + b1 * env + b2 * elev, withenvandeleveachN(0, 1)per site. Detection predictorc0 + c1 * tod_c + c2 * effort, withtod_c ~ U(-6, 6)andeffort ~ U(0.5, 1.5)per visit.
Each predictor is on the scale of the family's own link. The state
predictor takes the logit for occ() and the log for every nmix()
variant, where it sets the Poisson abundance mean lambda. The
detection predictor takes the logit for occ(),
nmix("poisson_binomial") and nmix("royle_nichols"). It takes the
log for nmix("poisson_poisson"), whose encounter rate rho is
unbounded.
Each species draws an intercept from a normal with mean zero. Each covariate draws one community mean. Each species then draws its slope around that mean. The standard deviations are:
| Predictor | Intercept | Community mean | Species slope |
occ() state | 0.75 | 1.5 | 0.5 |
nmix() state | 0.5 | 0.4 | 0.3 |
| Detection | 0.5 | 0.2 | 0.15 |
The nmix() state scales keep lambda well below K_max. The
detection scales keep detection away from 0 and 1 across the range of
tod_c.
Latent factors
With n_lv > 0L, the state predictor of species k at site i
gains sum_l Z[k, l] * lv[i, l]. The [n_species x n_lv]
loadings Z are normal with standard deviation 0.7. The
[n_sites x n_lv] factor scores lv are standard normal.
truth$loadings and truth$lv return both for comparison with
jsdgam() estimates and ordinate().
Truth bundle
psi(occ) orlambda(nmix)[n_species x n_sites]matrix of occupancy probabilities or expected abundances.z(occ) orN(nmix)[n_species x n_sites]matrix of the realised latent states thatpredict(fit, type = "latent_state")estimates.p[n_species x n_sites x n_visits]array of the detection parameter thatpredict(fit, type = "detection")estimates: the detection probability, the per-individual probabilityrofnmix("royle_nichols")or the encounter raterhoofnmix("poisson_poisson").state_coefs,detection_coefsThe intercept and slopes of each predictor. A named vector for one species, an
[n_species x (1 + p)]matrix for several.loadings,lvZand the factor scores, whenn_lv > 0L.
summary() returns an mvgam_sim_closure_unit_summary list: the
dimensions, the recipe, the ranges of the true state and detection
parameters and the share of non-zero observations. A share of 0 or
1 marks data with no information on detection. print() shows it.
See also
sim_mvgam() simulates state-space time series.
sim_jsdgam() simulates site-by-species data without a detection
process. The
N-mixture article fits occupancy and
N-mixture models to data of this layout.
Other simulation:
sim_jsdgam(),
sim_mvgam()
Examples
# Four species with two site and two visit covariates
simdat <- sim_closure_unit_data(
family = occ(),
n_species = 4L,
n_sites = 50L,
n_visits = 4L,
type = 2L,
seed = 1L
)
head(simdat$data_train)
#> visit site series time y cap env elev tod_c effort
#> 1 1 1 sp_1 1 1 1 -0.6264538 0.3981059 -2.7899015 1.1588776
#> 2 2 1 sp_1 1 0 1 -0.6264538 0.3981059 3.1436863 1.4643170
#> 3 3 1 sp_1 1 1 1 -0.6264538 0.3981059 2.0845468 1.0541771
#> 4 4 1 sp_1 1 1 1 -0.6264538 0.3981059 -0.1662107 1.3708056
#> 5 1 2 sp_1 2 0 1 0.1836433 -0.6120264 -3.3762566 0.6850700
#> 6 2 2 sp_1 2 0 1 0.1836433 -0.6120264 5.1949179 0.9425101
summary(simdat)
#> Simulated closure-unit dataset (sim_closure_unit_data type 2)
#> Family : occ
#> Species : 4
#> Sites : 50
#> Visits/unit : 4
#>
#> True generative parameters
#> psi range: [0.000, 1.000]
#> Detection range: [0.039, 0.959]
#> Non-zero observation fraction: 0.330
# Next: fit these data with jsdgam(), as the shared_variation()
# example does