Skip to contents

Construct a triangular mesh and the finite-element quantities used by the spatial_*() keywords. The helper uses the public fmesher API; the SPDE/GMRF construction follows Lindgren, Rue, and Lindstrom (2011). Scope: mesh/FEM construction and fit ingestion are covered by focused tests; evidence across the broader spatial-family surface remains partial; directional anisotropy, spatiotemporal fields, barriers, and likelihood changes are rejected from this helper contract.

Usage

make_mesh(
  data,
  xy_cols,
  type = c("cutoff", "kmeans", "cutoff_search"),
  cutoff,
  n_knots,
  seed = 42,
  mesh = NULL,
  fmesher_func = fmesher::fm_rcdt_2d_inla,
  convex = NULL,
  concave = convex,
  ...,
  id_col = NULL
)

Arguments

data

A data frame containing the coordinate columns.

xy_cols

Character names of exactly two finite numeric coordinate columns in data.

type

Mesh construction method: "cutoff", "kmeans", or "cutoff_search".

cutoff

Minimum vertex separation for type = "cutoff".

n_knots

Number of coordinate centres for "kmeans", or target number of mesh vertices for "cutoff_search". The latter returns the closest valid mesh when the exact target is unavailable.

seed

Seed used only while selecting k-means centres. The caller's RNG state is restored before this function returns.

mesh

Optional pre-built fmesher mesh.

fmesher_func

Mesh constructor from fmesher.

convex, concave

Optional non-convex-hull controls passed to fmesher::fm_nonconvex_hull().

...

Additional arguments passed to fmesher_func.

id_col

Optional name of a column containing one unique, non-missing label per projection row. The labels are retained for formula terms, such as spatial_slope(), that align mesh locations to response columns. The default NULL preserves the ordinary observation-aligned mesh contract.

Value

A gllvmTMBmesh object containing loc_xy, xy_cols, mesh, the finite-element matrices in spde, mesh centres in loc_centers, and the observation-to-mesh projection matrix A_st. When id_col is supplied, the object also contains id_col and row_labels.

References

Lindgren F, Rue H, Lindstrom J (2011). An explicit link between Gaussian fields and Gaussian Markov random fields: the SPDE approach. Journal of the Royal Statistical Society: Series B, 73, 423-498.

Examples

set.seed(1)
df <- data.frame(X = runif(40), Y = runif(40))
mesh <- make_mesh(df, c("X", "Y"), cutoff = 0.1)
plot(mesh)