CAR model in brms getting error "no slot of name "i" for this object of class "ddiMatrix""

Hi! I’m attempting to fit a CAR model following the basic example found here. Below is some code for an attempt to do the same steps for a subset of my real spatial data. Columns X and Y are UTM coordinates. When trying to fit it, I get the error mentioned in the title, and I haven’t been able to figure out what it means. Thanks for your help!

library(brms)

# Read example data
d <- readr::read_csv("https://raw.githubusercontent.com/maxlindmark/spatial-metabolic-index/main/car_data.csv")

# set up distance and neighbourhood matrices
K <- nrow(d)

distance_grid <- d[, c("X", "Y")]

distance <- as.matrix(dist(distance_grid))
W <- array(0, c(K, K))
W[distance == 1] <- 1
d$grp <- 1:K
rownames(W) <- 1:K

bm <- brm(response ~ predictor + car(W, gr = grp),
          data = d,
          data2 = list(W = W))
  • Operating System: Mac OS Ventura 13.5.2 (22G91)
  • brms Version: brms_2.19.0

Perhaps because your W matrix consists of only 0 values?

1 Like

Ugh, I didn’t realise… expected many zeroes but not this many! Sorry, and thanks for your time!