JonJup
JonJup

Reputation: 44

Sparse adjacency matrix for conditional autoregressive model in brms

I want to fit a model in the R package brms. My data consists of spatial polygons and I want to use conditional autoregression to account for autocorrelation. This is possible in brms but requires a spatial adjacency matrix M. My issue is that I have too many polygons and my M does not fit into memory.

Is there a way to use a sparse matrix representation in brms?

My code:

fit <- brms::brm(
        formula = eco_stat_2 ~
                shannon + LoadTPArea + LoadTN_Are +
                lu_r_urb + lu_r_agr + hy_maf_abs + hy_bfi_abs +
                msPAFP5EC5 + car(M = neighbors, type = "escar"),
        data = data,
        data2 = list(neighbors = neighbors2),
        family = cumulative("logit"),
        cores = 6
)

I have already tried to create a sparse M with shape2mat() from geostan, which creates a ngCMatrix version of M. Running the model above with this M returned the error:

Error in validate_car_matrix(get_from_data2(M, data2)) : 
  no slot of namen "x" for this object of class "ngCMatrix"

Upvotes: 0

Views: 20

Answers (0)

Related Questions