Fits a Gaussian regression with a CAR/ICAR latent effect: \(y = X\beta + x + \epsilon\) with \(\epsilon \sim N(0,\sigma^2 I)\) and \(x \sim N(0, Q^{-1})\), where \(Q = \tau (D - \rho A)\) and \(D = diag(A 1)\). For ICAR, \(\rho = 1\).
fit_car(
y,
A,
X = NULL,
type = c("icar", "proper"),
rho = 0.99,
tau = 1,
n_iter = 2000,
burn_in = floor(n_iter/2),
thin = 1,
beta_init = NULL,
x_init = NULL,
sigma2_init = NULL,
b0 = NULL,
B0 = NULL,
a0 = 2,
b0_sigma = 1,
center_icar = TRUE,
verbose = FALSE
)A list of class "trafficCAR_fit" with elements:
drawsList with MCMC draws x, beta, sigma2.
keepIteration indices that were saved.
type, rho, tauModel hyperparameters used.
y = X beta + x + epsilon
Numeric response vector of length n.
Square n x n adjacency/weight matrix (base matrix or Matrix).
Diagonal entries are ignored.
Optional n x p design matrix. If NULL, no regression is fit.
Either "icar" or "proper".
Spatial dependence parameter for proper CAR. Ignored for ICAR.
Positive scalar precision multiplier.
Total MCMC iterations.
Number of initial iterations to discard.
Keep every thin-th draw after burn-in.
Optional initial \(\beta\) (length p).
Optional initial latent field \(x\) (length n).
Optional initial \(\sigma^2\) (positive scalar).
Prior mean for \(\beta\) (length p). Default is zero vector.
Prior covariance for \(\beta\) (p x p). Default is large diagonal.
Shape parameter for inverse-gamma prior on \(\sigma^2\).
Scale parameter for inverse-gamma prior on \(\sigma^2\).
Logical; if TRUE and type="icar", center \(x\)
to sum-to-zero within each connected component.
Logical; print coarse progress updates.
The sampler updates \(x\), \(\beta\) (if X is provided), and \(\sigma^2\)
using Gibbs steps.