
Per-trait spatial marginal field: spatial_indep(0 + trait | coords)
Source: R/brms-sugar.R
spatial_indep.RdCanonical name for T per-trait spatial fields coupled by the SPDE precision matrix \(\mathbf Q\); standalone = T univariate spatial fits stacked.
Arguments
- formula
0 + trait | coordsstyle formula (LHS is the trait factor0 + trait; RHS is thecoordsplaceholder symbol that points at themake_mesh()coordinate columns).- coords
Character; the column-name pair of spatial coordinates in
data(e.g.c("lon", "lat")). Resolved by the parser when supplied as keyword argument;NULLwhen the orientation expresses the coordinates via the formula RHS.- mesh
An
fmeshermesh object built viamake_mesh(). It may be supplied here or through the top-levelmesh =argument togllvmTMB(). The engine does not construct a mesh automatically fromcoords.- common
FALSE(default) for a separate spatial-field variance per trait;TRUEties all traits to one shared spatial variance (intercept-only).spatial_indep(0 + trait | coords, common = TRUE)is the canonical one-shared-variance spelling and fits the same model as the soft-deprecatedspatial_scalar().
Details
Each trait \(t\) gets its own variance \(\tau^2_t\) on a Matern \(\nu = 1\) GMRF, with a shared range parameter \(\kappa\).
Use spatial_indep() for an explicit marginal-only spatial fit (no
cross-trait spatial decomposition). Use spatial_latent() for
K shared spatial fields driving all T traits via a T x K loading
matrix.
Formula orientation
Same convention as the rest of the spatial_* keywords: the
canonical orientation is 0 + trait | coords (LHS = trait factor,
RHS = the coords placeholder). Spatial keywords adopted this
orientation at gllvmTMB 0.1.4; spatial_indep is born with it
(no legacy coords | trait orientation is accepted).
Mutual exclusion with spatial_latent()
Combining spatial_indep(0 + trait | coords) with
spatial_latent(0 + trait | coords, d = K) is over-parameterised
and the parser raises a cli::cli_abort().
Examples
if (FALSE) { # \dontrun{
sim <- simulate_site_trait(
n_sites = 20, n_species = 4, mean_species_per_site = 4,
spatial_range = 0.4, sigma2_spa = rep(0.3, 4), seed = 1
)
mesh <- make_mesh(sim$data, c("lon", "lat"), cutoff = 0.1)
fit <- gllvmTMB(
value ~ 0 + trait +
spatial_indep(0 + trait | site, mesh = mesh),
data = sim$data,
trait = "trait",
unit = "site"
)
} # }