Simulate from a spatial/spatiotemporal model

sdmTMB_sim(
mesh,
x,
y,
range,
time_steps = 1L,
X = NULL,
betas = NULL,
rho = 0,
sigma_O = 0.1,
sigma_E = 0,
sigma_V = rep(0, length(betas)),
phi = 0.01,
thetaf = 1.5,
df = 3,
seed = sample.int(1e+06, 1),
list = FALSE,
size = NULL
)

## Arguments

mesh Output from make_mesh() or a mesh directly from INLA. A vector of x coordinates. Should match mesh. A vector of y coordinates. Should match mesh. Parameter that controls the decay of spatial correlation. The number of time steps. An optional covariate design matrix formatted as a list with each element of the list representing a slice in time. If ommitted and betas is not NULL, will be set to standard normal. A vector of beta values (design-matrix fixed-effect coefficient values). If a random walk (sigma_V > 0), these are the starting values. Family as in sdmTMB(). Spatiotemporal correlation between years; should be between -1 and 1. SD of spatial process (Omega). SD of spatiotemporal process (Epsilon). Can be scalar or vector for time-varying model. A vector of standard deviations of time-varying random walk on parameters. Set to 0 for parameters that should not vary through time. Observation error scale parameter. Tweedie p (power) parameter; between 1 and 2. Student-t degrees of freedom. A value with which to set the random seed. Logical for whether output is in list format. If TRUE, data is in list element 1 and input values in element 2. Specific for the binomial family, vector representing binomial N. If not included, defaults to 1 (bernoulli)

## Value

A data frame where:

• omega_s represents the simulated spatial random effects.

• epsilon_st represents the simulated spatiotemporal random effects.

• 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.

• b_... contain the beta values for each covariate used to simulate each time slice.

• cov_... covariate values for each observation.

## Examples

# \donttest{
set.seed(42)
x <- runif(50, -1, 1)
y <- runif(50, -1, 1)
N <- length(x)
time_steps <- 6
X <- model.matrix(~ x1, data.frame(x1 = rnorm(N * time_steps)))
loc <- data.frame(x = x, y = y)
mesh <- make_mesh(loc, xy_cols = c("x", "y"), cutoff = 0.1)
s <- sdmTMB_sim(
x = x, y = y, mesh = mesh, X = X,
betas = c(0.5, 0.7), time_steps = time_steps, rho = 0.5,
phi = 0.2, range = 0.8, sigma_O = 0, sigma_E = 0.3,
seed = 123, family = gaussian()
)

mesh <- make_mesh(s, xy_cols = c("x", "y"), cutoff = 0.1)
m <- sdmTMB(
data = s, formula = observed ~ x1,
time = "time", spde = mesh,
ar1_fields = TRUE, include_spatial = FALSE
)
tidy(m, conf.int = TRUE)
#>          term  estimate  std.error  conf.low conf.high
#> 1 (Intercept) 0.4150763 0.06837053 0.2810725 0.5490801
#> 2          x1 0.6948517 0.01776395 0.6600350 0.7296684tidy(m, "ran_pars", conf.int = TRUE)
#>      term  estimate std.error  conf.low conf.high
#> 1   range 0.6200721        NA 0.3784356 1.0159968
#> 2     phi 0.2111023        NA 0.1766060 0.2523366
#> 3 sigma_E 0.3096089        NA 0.2566540 0.3734900
#> 4     rho 0.4973067        NA 0.2313428 0.6941057# }