Never mind, I figured out what was wrong. The gr has to be in the data to map it to the adjacency matrix.
On a separate note, I just fit a CAR model that had one cell (grid location) for which there was no data, and I wanted to see if there was a way to make predictions for the “missing” cell (using posterior_epred). I would have thought that if I provided the location information for the missing cell (in the original adjacency matrix that was used to fit the model), and set allow_new_levels to TRUE, that this would be enough to estimate these cells. However, I got an error message:
Error: Cannot handle new locations in CAR models.
Is this a feature that can be added or is there a conceptual reason why this is not possible that I am missing?
Here is the code that I used to fit the model (based on the example under ?car):
As a workaround, could one use the brms weight argument to add one made-up datapoint (i.e., population mean) per new location, and then apply zero weights to said datapoints? This could be very wrong, but it feels so right.
Right that is actually a good idea. One could add a data point which is has a missing value in its response and then handle it via the mi() addition term.
Using the example above, we can set the value of the outcome at index 25 to be NA.
dat_miss2 <- dat_complete
dat_miss2$y[25] <- NA
Can you clarify how to specify the model? I’m new to the mi syntax and the only examples I see are for missing values in the predictor. I attempted the following but it didn’t work:
fit_miss2 <- brm(mi(y) | trials(size) ~ x1 + x2 + car(W, gr = grp),
data = dat_miss2, data2 = list(W = W),
family = binomial(),
iter = 5000)
Ok it would have worked for continues but not for discrete outcomes so it won’t for your case. The weight = 0 approach should still work though but don’t use NA in this case to avoid having this observation removed.
I get a bunch of uninterpretable compilation errors:
Compiling Stan program...
running command 'C:/PROGRA~1/MICROS~3/ROPEN~1/R-35~1.1/bin/x64/R CMD SHLIB file1f8c71486e.cpp 2> file1f8c71486e.cpp.err.txt' had status 1Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! g++.exe: error: Files/Microsoft/R: No such file or directory
Hi @franzsf , @jgellar and @paul.buerkner. Thank you for your examples. There is something that is not clear for me. I understand that the weights argument and “wt” variable allow me to fit the model without considering that especific observation, but if that observation has an NA as response, the fitted function result in the same error:
Error: Cannot handle new locations in CAR models.
If I use any value insted of NA, still I will be restricted by the size argument, right?
Even without this problems, do you think that this method can be use to execute a K-fold cross-validation like in this vignette?