View source: R/spatial_field.R
| spatial | R Documentation |
Declare one or more areal (CAR / Besag) fields over a graph from an lme4-style bar formula. The bar's left-hand side lists the coefficients that vary smoothly over the graph; the right-hand side names the graph-node index. Each coefficient becomes an independent CAR field, entering the linear predictor scaled by that coefficient's per-observation design value:
\eta_i = \ldots + \sum_c X_{ic}\, z^{(c)}_{g_i},
where g_i is the graph node of observation i, z^{(c)} is
the CAR field for design column c, and X_{ic} is that column's
value at observation i. The intercept column is all ones, so
~ 1 || cell is the ordinary spatial intercept field; a covariate column
(e.g. time) gives a spatially varying slope on that covariate (a
per-region trend).
Use it inline in a tulpa() model formula, the same way a random-effect
bar is written:
y ~ time + spatial(graph = adj, formula = ~ 1 + time || cell) + (1 | site)
spatial(graph, formula, proper = FALSE, shared = NULL, by = NULL)
## S3 method for class 'tulpa_spatial_field_fit'
print(x, ...)
## S3 method for class 'tulpa_spatial_field'
print(x, ...)
graph |
Symmetric adjacency matrix of the spatial graph
( |
formula |
One-sided formula carrying a grouping bar, e.g.
|
proper |
Logical; |
shared |
Optional shared-effect handle, passed through to the field
blocks (see the model docs). Default |
by |
Optional replicated-CAR factor: a bare column name (or a string)
naming a factor in the model data. With |
x |
A |
... |
Ignored. |
Each field is independent (its own precision), matching INLA's two
separate f(cell, model = "besag") and f(cell.slope, time, model = "besag") fields. Nesting (a / b), interaction, or expression
grouping is rejected: the grouping must be a single graph node. Add
ordinary nested random effects, e.g. (1 | site), as separate terms.
A tulpa_spatial_field object describing the field(s). It is
expanded into one CAR block per design column at fit time, when the data
is available.
spatial_car() for a single areal field passed via the
spatial = argument, spatial_svc() for the coordinate-based
(Gaussian-process) spatially varying coefficient.
# Chain graph over 10 cells
adj <- matrix(0, 10, 10)
for (i in 1:9) adj[i, i + 1] <- adj[i + 1, i] <- 1
# Spatial intercept plus a spatially varying time slope
f <- spatial(graph = adj, formula = ~ 1 + time || cell)
print(f)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.