make_Q: Generate CAR precision matrix

View source: R/make_Q.R

make_QR Documentation

Generate CAR precision matrix

Description

A function for setting up a conditional autoregressive (CAR) or simultaneous autoregressive (SAR) precision matrix for use as a prior in Bayesian models

Usage

make_Q(n_dims, phi, use_spam = TRUE, prec_model = "CAR")

Arguments

n_dims

is a vector of length M that are the dimensions of the CAR/SAR matrix at each resolution

phi

is a vector of length M with each element between -1 and 1 that defines the strength of the autoregressive process. Typically this will be set to 1 for use as a prior in penalized Bayesian models

use_spam

is a boolean flag to determine whether the output is a list of spam matrix objects (use_spam = TRUE) or a an n x n sparse Matrix of class "dgCMatrix" use_spam = FALSE(see Matrix package for details)

prec_model

is a string that takes the values "CAR" or "SAR" and defines the graphical structure for the precision matrix.

Value

a list of n x n sparse spam matrices or Matrix matrices of class "dgCMatrix" (see Matrix package for details)

Examples

n_dims <- c(4, 8)
phi <- c(0.8, 0.9)
Q <- make_Q(n_dims, phi)
## plot the precision matrix structure at each resolution
layout(matrix(1:2, 1, 2))
spam::display(Q[[1]])
spam::display(Q[[2]])


jtipton25/sgMRA documentation built on Feb. 9, 2023, 4:53 a.m.