Learn R Programming

trafficCAR (version 0.1.0)

car_precision: CAR precision matrix from an adjacency matrix

Description

Constructs the precision matrix for an intrinsic CAR (ICAR) or proper CAR model: $$Q = \tau (D - \rho A), \quad D = \mathrm{diag}(A \mathbf{1}).$$

Usage

car_precision(
  A,
  type = c("icar", "proper"),
  rho = 0.99,
  tau = 1,
  symmetrize = FALSE,
  check = TRUE
)

Value

A symmetric sparse precision matrix `Q` (class `"dsCMatrix"`).

Arguments

A

Square adjacency/weight matrix (base matrix or a `Matrix` sparse type). Diagonal entries are ignored (set to 0).

type

Either `"icar"` or `"proper"`.

rho

Spatial dependence parameter for proper CAR. Ignored for ICAR.

tau

Positive scalar precision multiplier.

symmetrize

If `TRUE`, replaces `A` by `(A + t(A))/2` before construction.

check

If `TRUE`, performs basic validation and warnings.

Details

For ICAR, set `type = "icar"` (internally uses \(\rho=1\)). For proper CAR, set `type = "proper"` and choose `rho` so that \(D - \rho A\) is positive definite (no automatic spectral checks are performed).

Examples

Run this code
A <- matrix(0, 4, 4)
A[1,2] <- A[2,1] <- 1
A[2,3] <- A[3,2] <- 1
A[3,4] <- A[4,3] <- 1
Q_icar <- car_precision(A, type = "icar", tau = 1)
Q_prop <- car_precision(A, type = "proper", rho = 0.9, tau = 2)

Run the code above in your browser using DataLab