sdmTMB_simulate | R Documentation |
sdmTMB_simulate()
uses TMB to simulate new data given specified parameter
values. simulate.sdmTMB()
, on the other hand, takes an existing model fit
and simulates new observations and optionally new random effects.
sdmTMB_simulate(
formula,
data,
mesh,
family = gaussian(link = "identity"),
time = NULL,
B = NULL,
range = NULL,
rho = NULL,
sigma_O = NULL,
sigma_E = NULL,
sigma_Z = NULL,
phi = NULL,
tweedie_p = NULL,
df = NULL,
threshold_coefs = NULL,
fixed_re = list(omega_s = NULL, epsilon_st = NULL, zeta_s = NULL),
previous_fit = NULL,
seed = sample.int(1e+06, 1),
...
)
formula |
A one-sided formula describing the fixed-effect structure.
Random intercepts are not (yet) supported. Fixed effects should match
the corresponding |
data |
A data frame containing the predictors described in |
mesh |
Output from |
family |
Family as in |
time |
The time column name. |
B |
A vector of beta values (fixed-effect coefficient values). |
range |
Parameter that controls the decay of spatial correlation. If a
vector of length 2, |
rho |
Spatiotemporal correlation between years; should be between -1 and 1. |
sigma_O |
SD of spatial process (Omega). |
sigma_E |
SD of spatiotemporal process (Epsilon). |
sigma_Z |
SD of spatially varying coefficient field (Zeta). |
phi |
Observation error scale parameter (e.g., SD in Gaussian). |
tweedie_p |
Tweedie p (power) parameter; between 1 and 2. |
df |
Student-t degrees of freedom. |
threshold_coefs |
An optional vector of threshold coefficient values
if the |
fixed_re |
A list of optional random effects to fix at specified
(e.g., previously estimated) values. Values of |
previous_fit |
(Deprecated; please use |
seed |
Seed number. |
... |
Any other arguments to pass to |
A data frame where:
The 1st column is the time variable (if present).
The 2nd and 3rd columns are the spatial coordinates.
omega_s
represents the simulated spatial random effects (only if present).
zeta_s
represents the simulated spatial varying covariate field (only if present).
epsilon_st
represents the simulated spatiotemporal random effects (only if present).
eta
is the true value in link space
mu
is the true value in inverse link space.
observed
represents the simulated process with observation error.
The remaining columns are the fixed-effect model matrix.
simulate.sdmTMB()
set.seed(123)
# make fake predictor(s) (a1) and sampling locations:
predictor_dat <- data.frame(
X = runif(300), Y = runif(300),
a1 = rnorm(300), year = rep(1:6, each = 50)
)
mesh <- make_mesh(predictor_dat, xy_cols = c("X", "Y"), cutoff = 0.1)
sim_dat <- sdmTMB_simulate(
formula = ~ 1 + a1,
data = predictor_dat,
time = "year",
mesh = mesh,
family = gaussian(),
range = 0.5,
sigma_E = 0.1,
phi = 0.1,
sigma_O = 0.2,
seed = 42,
B = c(0.2, -0.4) # B0 = intercept, B1 = a1 slope
)
head(sim_dat)
if (require("ggplot2", quietly = TRUE)) {
ggplot(sim_dat, aes(X, Y, colour = observed)) +
geom_point() +
facet_wrap(~year) +
scale_color_gradient2()
}
# fit to the simulated data:
fit <- sdmTMB(observed ~ a1, data = sim_dat, mesh = mesh, time = "year")
fit
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.