Skip to contents

Construct an SPDE mesh for use with the gllvmTMB() spatial_*() keywords.

Usage

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

# S3 method for class 'sdmTMBmesh'
plot(x, ...)

Arguments

data

A data frame.

xy_cols

A character vector of x and y column names contained in data. These should likely be in an equal distance projection. For a helper function to convert to UTMs, see add_utm_columns().

type

Method to create the mesh. Also see mesh argument to supply your own mesh.

cutoff

An optional cutoff if type is "cutoff". The minimum allowed triangle edge length.

n_knots

The number of desired knots if type is not "cutoff".

seed

Random seed. Affects stats::kmeans() determination of knot locations if type = "kmeans".

mesh

An optional mesh created via fmesher instead of using the above convenience options.

fmesher_func

Which fmesher function to use. Options include fmesher::fm_rcdt_2d_inla() and fmesher::fm_mesh_2d_inla() along with version without the _inla on the end.

convex

If specified, passed to fmesher::fm_nonconvex_hull(). Distance to extend non-convex hull from data.

concave

If specified, passed to fmesher::fm_nonconvex_hull(). "Minimum allowed reentrant curvature". Defaults to convex.

...

Passed to graphics::plot().

x

Output from make_mesh().

Value

make_mesh(): A list of class sdmTMBmesh. The element mesh is the output from fmesher_func (default is fmesher::fm_mesh_2d_inla()). See mesh$mesh$n for the number of vertices.

plot.sdmTMBmesh(): A plot of the mesh and data points. To make your own ggplot2 version, pass your_mesh$mesh to inlabru::gg().

Examples

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