bru_mapper.inla_rspde: rSPDE inlabru mapper

View source: R/inlabru_rspde.R

bru_mapper.inla_rspdeR Documentation

rSPDE inlabru mapper

Description

rSPDE inlabru mapper

Usage

bru_mapper.inla_rspde(model, ...)

ibm_n.bru_mapper_inla_rspde(mapper, ...)

ibm_values.bru_mapper_inla_rspde(mapper, ...)

ibm_amatrix.bru_mapper_inla_rspde(mapper, input, ...)

bru_get_mapper.inla_rspde(model, ...)

Arguments

model

An inla_rspde for which to construct or extract a mapper

...

Arguments passed on to other methods

mapper

A bru_mapper.inla_rspde object

input

The values for which to produce a mapping matrix

Examples

 #tryCatch version
tryCatch({
if (requireNamespace("INLA", quietly = TRUE) && 
     requireNamespace("inlabru", quietly = TRUE)){
library(INLA)
library(inlabru)

set.seed(123)
m <- 100
loc_2d_mesh <- matrix(runif(m * 2), m, 2)
mesh_2d <- inla.mesh.2d(
  loc = loc_2d_mesh,
  cutoff = 0.05,
  max.edge = c(0.1, 0.5)
)
sigma <- 0.01
range <- 0.2
nu <- 0.8
kappa <- sqrt(8 * nu) / range
op <- matern.operators(
  mesh = mesh_2d, nu = nu,
  kappa = kappa, sigma = sigma, m = 2
)
u <- simulate(op)
A <- inla.spde.make.A(
  mesh = mesh_2d,
  loc = loc_2d_mesh
)
sigma.e <- 0.1
y <- A %*% u + rnorm(m) * sigma.e
y <- as.vector(y)

data_df <- data.frame(y=y, x1 = loc_2d_mesh[,1],
                       x2 = loc_2d_mesh[,2])
coordinates(data_df) <- c("x1", "x2")
rspde_model <- rspde.matern(
  mesh = mesh_2d,
  nu_upper_bound = 2
)

# For inlabru version 2.5.3.9002 or above:
cmp <- y ~ Intercept(1) + 
           field(coordinates, model = rspde_model)

#For inlabru version 2.5.3:
cmp <- y ~ Intercept(1) + 
           field(coordinates, model = rspde_model,
             mapper = bru_mapper(rspde_model))

rspde_fit <- bru(cmp, data = data_df)
}
#stable.tryCatch
}, error = function(e){print("Could not run the example")})


rSPDE documentation built on Sept. 17, 2022, 1:05 a.m.