spatial_spde_custom: SPDE spatial field from custom matrices

View source: R/spatial_rsr_spde.R

spatial_spde_customR Documentation

SPDE spatial field from custom matrices

Description

Specify a continuous Matern spatial field using externally-provided FEM matrices. Use this with meshes from fmesher, rSPDE, or any other source.

Usage

spatial_spde_custom(
  C,
  G,
  A,
  nu = 1,
  prior_range = NULL,
  prior_sigma = NULL,
  coords = NULL
)

Arguments

C

Mass matrix (n_mesh x n_mesh sparse matrix, e.g. from fmesher::fm_fem()$c0).

G

Stiffness matrix (n_mesh x n_mesh sparse matrix, e.g. from fmesher::fm_fem()$g1).

A

Projection matrix (n_obs x n_mesh sparse matrix, e.g. from fmesher::fm_basis()).

nu

Matern smoothness parameter. A positive number; integer values give the exact FEM construction, fractional values the BRASIL rational SPDE approximation (supported by fit_spde();). Default 1.

prior_range

PC prior on the spatial range, c(U, alpha) with P(range < U) = alpha. NULL (the default) anchors it on coords as spatial_spde() does, and needs them.

prior_sigma

PC prior on the marginal standard deviation, c(U, alpha) with P(sigma > U) = alpha. NULL (the default) is c(3, 0.01).

coords

Observation coordinates (an ⁠n_obs x 2⁠ matrix), read only to anchor the default range prior. Not needed when prior_range is given.

Value

A tulpa_spatial object with type "spde".

Examples

# FEM matrices of a 6-node 1-D chain mesh, observed at the nodes:
n <- 6L
C <- Matrix::Diagonal(n)
G <- Matrix::bandSparse(n, k = c(-1, 0, 1),
                        diagonals = list(rep(-1, n - 1), c(1, rep(2, n - 2), 1),
                                         rep(-1, n - 1)))
A <- Matrix::Diagonal(n)
sp <- spatial_spde_custom(C, G, A, prior_range = c(1, 0.5),
                          prior_sigma = c(1, 0.01))
sp$type

tulpa documentation built on Oct. 19, 2026, 5:09 p.m.