Is there a way to get marginal mean predictions for certain levels of grouping terms with brms and emmeans? Using conditional_effects()
I understand this is possible as following:
library(dplyr)
library(brms)
data("rent99", package = "gamlss.data")
m <- brm(rentsqm ~ area + yearc + (1|district), data = rent99)
# Get predictions for specific levels
conditions <- data.frame(district = unique(rent99$district))
preds <- conditional_effects(m, effects = "yearc",
conditions = conditions, re_formula = NULL) %>%
.[[1]] %>% as.data.frame
preds %>%
filter(district %in% c("1235", "611"),
yearc > 1956, yearc < 1957) %>%
select(yearc, district, estimate__)
#> yearc district estimate__
#> 1 1956.303 611 7.058089
#> 2 1956.303 1235 7.592747
Nonetheless, in emmeans the grouping variable is not part of the reference grid. So, as far as I know, it is not possible:
library(emmeans)
emmeans(m, ~ yearc)
#> yearc emmean lower.HPD upper.HPD
#> 1956 7.17 7.05 7.28
#>
#> Point estimate displayed: median
#> HPD interval probability: 0.95
emmeans(m, ~ yearc, at = list(district = c("1235", "611")))
#> yearc emmean lower.HPD upper.HPD
#> 1956 7.17 7.05 7.28
#>
#> Point estimate displayed: median
#> HPD interval probability: 0.95