I’m trying to make use of some of the suggestions from Gelman and colleagues in their paper ‘Improving multilevel regression and poststratification with structured priors’. The idea is that autocorrelation structures can be used to - for example - ensure that shrinkage does not just apply equally across all age categories. Instead, age 65+ would borrow more information from 45-64 than from 18-24, and so on.
I can’t work out how to implement this in brms at all - I’ve tried all sorts of things using the ar() function in brms which has been suggested by both a colleague and keeps being suggested by LLMs, but I can’t get any kind of syntax that works.
In the simple example to work with is the following setup:
test_data <-
tibble::tibble(age = sample(c("18-24", "25-44", "45-64", "65+"), size = 500, replace = TRUE),
region = sample(c("Dessert", "Jungle", "Grassland"), size = 500, replace = TRUE),
sex = sample(c(-.5, .5), size = 500, replace = TRUE),
outcome = sample(c(0, 1), size = 500, replace = TRUE)) %>%
dplyr::mutate(age = factor(age, levels = c("18-24", "25-44", "45-64", "65+"),
ordered = TRUE),
age_order = as.numeric(age))
test_form <-
outcome ~ sex + (1 | region) + (1 | age)
test_fit <-
brms::brm(formula = test_form,
family = bernoulli(),
data = test_data)
But how, rather than age being specified just as a general verying intercept (1 | age) can I make it so that there is some kind of autocorrelation, with levels borrowing more from closer categories?