In multilevel modeling there is a way to estimate a within-between estimator (in frequentist terms this would be estimating both fixed and random effects) for predictors (often time-varying covariates in the case of panel data). This entails including both the cluster mean, as well as the deviations from the cluster mean (i.e., the centered variable), as covariates.

It is currently possible to just use the observed cluster mean to run this model, but studies have suggested that doing so will produce bias. Using a latent mean (to account for unreliability of cluster means) to center the predictors produces better results (Hamaker and Muthen 2019, https://doi.org/10.1037/met0000239).

My question is: Is there a way to do this easily in brms?

This blog seems to show how to do this in Stan (https://quantscience.rbind.io/2017/08/01/bayesian-mlm-with-group-mean-centering/#group-mean-centering-with-lme4), but I was hoping there is already an easier way to do this using the brmsformula functions.

Please also provide the following information in addition to your question:

- Operating System: macOS Catalina 10.15.2
- brms Version: 2.10.0