Is there any way to incorporate a spatial weights (based on geographic coordinates) matrix into my regression modeling in BRMS? I’d like to test my results for spatial autocorrelation, then, if necessary, explicitly model location in my model…
cor_sar: I take a spatial weights object and simply select lag or error, then, plug the object in as a parameter in my brm function for the autocor parameter? Ditto for cor_car?
Is there another way to conceptualize the difference between the conditional (CAR) vs. simultaneous (SAR) autoregressive structure? I notice CAR permits grouping of spatial features…
where in the formula, I used fixed-term and correlated random term, and x and y are coordinates of the data, and in the model I put autocorrelation matrix W using cor_car.
However, the problem is when I try to fit the model or predict for a new data set, the function predict(mod.brm) itself works okay, but predict(mod.brm, newdata = newdata) returns the following error:
Error: Without a grouping factor, CAR models cannot handle newdata.
In addition: Warning message:
Using CAR terms without a grouping factor is deprecated. Please use argument ‘gr’ even if each observation represents its own location.
It is appreciated if you could help me on this issue.
Thank you.
The error message tells you that you need to specify the gr argument of cor_car, so that new data can be related to the original data, which is required for predictions of car models.
I am sorry. I overlooked that you use an old brms version with the old way of specifying autocor structures. You need to specify the grouping variable in the formula argument of cor_car as described in the documentation.
Hi Paul, thank you for the prompt response. I have updated the brms to version 2.12.8, and I missed that
the row names of W have to match the levels of the grouping factor
which is described in the cor_car document. I also missed the formula in cor_car function. Then I used cor_car(W,formula = ~ 1| gridId)
then the model works well.
Thank you very much for your help. I hope this post could help other users who might have similar problems.