Skip to contents

Generates a list of named index vectors for an rSPDE model.

Usage

rspde.make.index(
  name,
  n.spde = NULL,
  n.group = 1,
  n.repl = 1,
  mesh = NULL,
  rspde_order = 2,
  nu = NULL,
  dim = NULL
)

Arguments

name

A character string with the base name of the effect.

n.spde

The number of basis functions in the mesh model.

n.group

The size of the group model.

n.repl

The total number of replicates.

mesh

An inla.mesh, an inla.mesh.1d object or a metric_graph object.

rspde_order

The order of the rational approximation

nu

If NULL, then the model will assume that nu will be estimated. If nu is fixed, you should provide the value of nu.

dim

the dimension of the domain. Should only be provided if mesh is not provided.

Value

A list of named index vectors.

name

Indices into the vector of latent variables

name.group

'group' indices

name.repl

Indices for replicates

Examples

 #devel version
if (requireNamespace("INLA", quietly = TRUE)){
library(INLA)

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
Abar <- rspde.make.A(mesh = mesh_2d, loc = loc_2d_mesh)
mesh.index <- rspde.make.index(name = "field", mesh = mesh_2d)
st.dat <- inla.stack(
  data = list(y = as.vector(y)),
  A = Abar,
  effects = mesh.index
)
rspde_model <- rspde.matern(
  mesh = mesh_2d,
  nu_upper_bound = 2
)
f <- y ~ -1 + f(field, model = rspde_model)
rspde_fit <- inla(f,
  data = inla.stack.data(st.dat),
  family = "gaussian",
  control.predictor =
    list(A = inla.stack.A(st.dat)),
           inla.mode = "experimental"
)
result <- rspde.result(rspde_fit, "field", rspde_model)
plot(result)
}
#> Error in inla.inlaprogram.has.crashed() : 
#>   The inla-program exited with an error. Unless you interupted it yourself, please rerun with verbose=TRUE and check the output carefully.
#>   If this does not help, please contact the developers at <help@r-inla.org>.
#> 
#>  *** inla.core.safe:  inla.program has crashed: rerun to get better initial values. try=1/2 
#> Error in inla.inlaprogram.has.crashed() : 
#>   The inla-program exited with an error. Unless you interupted it yourself, please rerun with verbose=TRUE and check the output carefully.
#>   If this does not help, please contact the developers at <help@r-inla.org>.
#> 
#>  *** inla.core.safe:  inla.program has crashed: rerun to get better initial values. try=2/2 
#> 
#>  *** inla.core.safe:  rerun with improved initial values 



#devel.tag