Skip to contents

car(M, gr = g, type = ) in a formula adds a conditional autoregressive (CAR) field over the locations an adjacency matrix names, with brms's spelling and its four types. It is a predictor term, not a bar term, and it is available once frmtmb.spatial is loaded: library(frmtmb.spatial). Without the package, frmtmb::frm() refuses the term and names this package.

Value

car() is a formula term, not a function: frmtmb::frm() reads it at parse time, and the value it contributes is a random-effect block of the model. This page documents the term and returns nothing.

Arguments of the term

M

A symmetric adjacency matrix whose dimnames (row names, column names, or both, which then have to agree) name the locations, with a row for every location the data hold. Entries must be present and non-negative; non-zero weights are read as 1, with a message. Put it in data2 = list(M = M).

gr

The grouping variable that maps observations onto locations. It must be named: brms's deprecated gr = NA is refused.

type

"escar" (the default) is the proper CAR, Q = tau (D - rho W), and needs every location to have a neighbor. "esicar" is the intrinsic CAR under an EXACT sum-to-zero constraint, "icar" the same field under brms's SOFT constraint at scale con_sd, and "bym2" the scaled mixture of a spatial and an unstructured part.

con_sd

The scale of the soft constraint, brms's 1e-3 by default. It changes nothing an "esicar" term reports.

What the fit reports

frmtmb::confint_varcorr() reports sd(car), the field scale, and for "escar" and "bym2" the mixing parameter on (0, 1) under brms's names car and rhocar. frmtmb::ranef() gives the field at each location; for "esicar" that is the centered field, with its conditional standard deviations. A location the fit did not see has no law of its own, so predict() with allow_new_levels = TRUE predicts it at the population level.

Every constrained type constrains each connected component of the graph, where brms constrains the global sum; on a connected graph the two are the same constraint.

See also

Examples

set.seed(4)
grid <- expand.grid(r = 1:4, c = 1:4)
n <- nrow(grid)
W <- outer(seq_len(n), seq_len(n), function(i, j) {
  as.numeric(abs(grid$r[i] - grid$r[j]) + abs(grid$c[i] - grid$c[j]) == 1)
})
dimnames(W) <- list(paste0("L", 1:n), paste0("L", 1:n))
d <- data.frame(loc = factor(rep(rownames(W), each = 6),
                             levels = rownames(W)))
d$y <- 1 + rnorm(n)[as.integer(d$loc)] + rnorm(nrow(d), 0, 0.5)
fit <- frm(bf(y ~ car(W, gr = loc, type = "icar")), family = gaussian(),
           data = d, data2 = list(W = W))
confint_varcorr(fit)
#>                             block    term type estimate       lwr      upr
#> 1 car(W, gr = loc, type = "icar") sd(car)   sd 1.254151 0.8533854 1.843123