Construct an SPDE mesh for use with sdmTMB.

make_mesh(
  data,
  xy_cols,
  type = c("kmeans", "cutoff", "cutoff_search"),
  cutoff,
  n_knots,
  seed = 42,
  refine = list(min.angle = 21, max.edge = Inf, max.n.strict = -1, max.n = 1000),
  mesh = NULL
)

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

Arguments

data

A data frame.

xy_cols

A character vector of x and y column names contained in data.

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 distance between points in the mesh". See INLA::inla.mesh.create(). Smaller values create meshes with more knots. Points further apart than this value will receive a separate vertex in the mesh before any mesh refinement.

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

refine

Logical or list to pass to INLA::inla.mesh.create().

mesh

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

x

Output from make_mesh().

...

Passed to graphics::plot().

Value

make_mesh(): A list of class sdmTMBmesh

plot.sdmTMB(): A plot

Examples

if (inla_installed()) { sp <- make_mesh(pcod, c("X", "Y"), cutoff = 30, type = "cutoff") plot(sp) sp <- make_mesh(pcod, c("X", "Y"), cutoff = 5, type = "cutoff") plot(sp) sp <- make_mesh(pcod, c("X", "Y"), n_knots = 50, type = "cutoff_search") plot(sp) sp <- make_mesh(pcod, c("X", "Y"), n_knots = 50, type = "kmeans") plot(sp) # \donttest{ # Defining a mesh directly with INLA: bnd <- INLA::inla.nonconvex.hull(cbind(pcod$X, pcod$Y), convex = -0.05) mesh <- INLA::inla.mesh.2d( boundary = bnd, max.edge = c(20, 50), offset = -0.05, cutoff = c(2, 5), min.angle = 10 ) sp2 <- make_mesh(pcod, c("X", "Y"), mesh = mesh) plot(sp2) # } }
#> cutoff = 1.00 | knots = 2640 | ↓ #> cutoff = 100.00 | knots = 26 | ↑ #> cutoff = 10.00 | knots = 205 | ↓ #> cutoff = 31.62 | knots = 49 | ↑ #> cutoff = 17.78 | knots = 89 | ↓ #> cutoff = 23.71 | knots = 61 | ↓ #> cutoff = 27.38 | knots = 53 | ↓ #> cutoff = 29.43 | knots = 50 | ✔