Draws one realisation of the latent surface on a frame and time frame,
then binomial surveys at randomly chosen area-time cells (one survey per
cell). The logit prevalence is the fixed effects set by formula (by
default an intercept and a linear trend running from -1 at the first
time step to 1 at the last) + a spatial x AR1 field (the spatial prior
set by spatial, as in fit_areal()), with a cell-level nugget added at
each surveyed cell.
Usage
simulate_areal(
frame,
time,
formula = ~trend(),
covariates = NULL,
scale_covariates = TRUE,
beta = c(-1, 1),
sigma = 1,
rho_s = 0.9,
rho_t = 0.9,
sigma_n = 0.3,
n_cells = 100,
k = 50,
seed = NULL,
cells = NULL,
spatial = "leroux",
main = "none",
interaction = "IV",
temporal = "ar1",
sigma_space = 0.5,
rho_space = 0.9,
sigma_time = 0.5,
rho_time = 0.9
)Arguments
- frame
- time
A
time_frame().- formula, covariates, scale_covariates
The fixed effects, as in
fit_areal(). Simulating and fitting with the same settings gives effects on the same scale.- beta
Fixed effects on the logit scale: one per design column, in order (intercept,
trendif in the formula, then the covariates; seeareal_priors()), or named by design column.- sigma
Scale of the field. For
"leroux"and"car", the standard deviation issigmatimes a factor set by the graph (\(\tau = 1/\sigma^2\)); for"bym2", roughly the marginal standard deviation.- rho_s
Spatial dependence, between 0 and 1 (below 1 for
"car"; at 0 the areas are independent, at 1 the Leroux prior is the ICAR).- rho_t
Lag-one temporal correlation of the AR1, at least 0 and below 1.
- sigma_n
Standard deviation of the cell-level nugget (0 for none).
- n_cells
Number of distinct area-time cells surveyed, chosen at random.
- k
Number tested per survey: one number, or one per cell.
- seed
Random seed. If given, the caller's random-number stream is left untouched.
- cells
Instead of
n_cellsrandom cells: the cells to survey, as a data frame with an areaidcolumn, at(step number) ortime(label) column, and optionallyk(number tested). The$cellsof anareal_data()object qualifies, so a simulation can copy a real survey design: its areas, time steps and sample sizes.- spatial
The spatial prior:
"leroux","bym2"or"car"(see "Spatial priors" infit_areal()).- main, interaction, temporal
The components of the field, as in
fit_areal(): main effects in space and/or time ("none","space","time","both"), the type of space-time interaction ("IV","I","II","III","none"), and the prior of the time main effect ("ar1","rw1","rw2"). The defaults give the separable field described above.sigma,rho_sandrho_tbelong to the interaction (each only where its type has it).- sigma_space, rho_space
Scale and spatial dependence of the space main effect (under the prior
spatial).- sigma_time, rho_time
Scale of the time main effect (for a random walk, roughly its marginal standard deviation) and, for
"ar1", its lag-one correlation.
Value
A areal_data() object (stareal_data), ready for
fit_areal(), with $truth: spatial, theta (natural scale; for a
model with main effects or another interaction type, only the
hyperparameters it has), beta (named
by design column), logit and prevalence (areas x time steps
matrices of the surface without the nugget; prevalence in percent),
x (the logit at each surveyed cell with its nugget, in the order of
$cells: what a fit
estimates for the observed cells) and design. $surveys has columns
id, t, time, date (calendar frames), y, k. A simulation
with main effects or another interaction type also has, in $truth,
main, interaction, temporal, space (the space main effect, one
value per area, or NULL) and time (the time main effect, one value
per step, or NULL).
Examples
fr <- areal_lattice(6, 6)
tf <- time_frame(2001, 2020, "year")
sim <- simulate_areal(fr, tf, n_cells = 60, seed = 1)
sim
#> <stareal_data> 60 of 60 surveys used, pooled into 60 cells (simulated)
#> 29 of 36 units and 20 of 20 time steps have data (8.33% of the 720 area-time cells)
#> tested per cell: median 50, range 50-50; total 3,000 tested, 714 positive
#> truth: sigma 1, rho_s 0.9, rho_t 0.9, sigma_n 0.3; intercept -1, trend 1
