gmrfs

Adaptive GMRF models for R-INLA via the cgeneric interface. Bundles four latent models:

wrapper C entry point
fbesag() inla_cgeneric_fbesag
cblocks() inla_cgeneric_cblocks
pblocks() inla_cgeneric_pblocks
sblocks() inla_cgeneric_sblocks

Install

# INLA (if not already installed)
install.packages("INLA",
                 repos = c(getOption("repos"),
                           INLA = "https://inla.r-inla-download.org/R/stable"),
                 dep = TRUE)

# devtools / remotes
install.packages("remotes")
remotes::install_github("esmail-abdulfattah/gmrfs")

The user’s R will compile src/*.c at install time. A working gcc (with OpenMP) plus BLAS/LAPACK is required, same toolchain expectations as any package with C in src/.

Quick start (collapsed)

library(INLA); library(gmrfs)
# G_list: list of p covariance matrices, each n x n.
cm  <- cblocks(n = n, p = p, G_list = G_list, tau0 = 1.0)
fit <- inla(y ~ 1 + f(idx, model = cm),
            data = data.frame(y = y, idx = ind))

tau0 is a horseshoe-style global scale on each block’s standard deviation: larger -> looser prior, smaller -> more aggressive shrinkage of inactive blocks. A common heuristic is tau0 = s / p where s is the prior guess at how many blocks are active.

See inst/examples/fit_collapsed.R for a self-contained simulated example, and the gmrfs_test/ companion repo for the three formulations side-by-side.

Try it (smoke tests)

Each model ships a tiny demo (< 3 s) that builds the cgeneric, runs INLA end-to-end, and verifies m$ok:

library(gmrfs)
demo(package = "gmrfs")            # list available demos
demo("fbesag",  package = "gmrfs") # 5-node partitioned Besag
demo("cblocks", package = "gmrfs") # collapsed blocks
demo("pblocks", package = "gmrfs") # partial blocks
demo("sblocks", package = "gmrfs") # stacked blocks

A green [OK] ... ran successfully. line at the end of each confirms the wrapper -> shlib -> C symbol -> INLA path is wired correctly.

Models, input contracts

All three block models take a length-p list of per-block matrices at the R layer; the wrappers handle stacking and any required factorisation.

License

GPL (>= 2). Includes src/cgeneric.h from R-INLA.