Learn R Programming

INLAtools (version 0.0.8)

multi_generic_model: Combine two or more cgeneric or rgeneric models

Description

Constructs a multiple kronecker product model from a list of model objects. The resulting model contains a corresponding inlabru::bm_multi() mapper. This can be used as an alternative to a binary tree of kronecker product models.

Usage

multi_generic_model(models, ...)

multi_generic_model_mapper(models)

Value

A 'cgeneric' or 'rgeneric' model object, containing a multi-kronecker product model, with a corresponding inlabru::bm_multi()

mapper.

Arguments

models

A list of cgeneric or rgeneric models, optionally with names

...

Arguments passed on to every kronecker() call.

Functions

  • multi_generic_model_mapper(): Buidl the bm_multi mapper for a list of models

Details

The last model in the list has the slowest index variation, and the first model has the fastest index variation. This matches the latent variable ordering of standard INLA:f() model components with (main, group, replicate).

Examples

Run this code
library(INLAtools)
R1 <- Matrix(crossprod(diff(diag(4))))
R1
m1 <- cgeneric("generic0", R = R1, param = c(1, NA),
  scale = FALSE, useINLAprecomp = FALSE)
R2 <- Matrix(crossprod(diff(diag(3))))
R2
m2 <- cgeneric("generic0", R = R2, param = c(1, NA),
  scale = FALSE, useINLAprecomp = FALSE)
m3 <- cgeneric("iid", n = 2, param = c(1, 0.5),
  useINLAprecomp = FALSE)
prec(m3, theta = 0.0)
multi123 <- multi_generic_model(
  list(m1 = m1, m2 = m2, m3 = m3),
  useINLAprecomp = FALSE
)
R321 <- Sparse(kronecker(kronecker(Diagonal(2),R2),R1))
R321
all.equal(R321, Sparse(prec(multi123, theta = 0.0)))
if(!is.na(packageCheck("inlabru", "2.13.0.9005"))) {
  print(multi123$mapper)
}

Run the code above in your browser using DataLab