Centering predictors in Bayesian multilevel models

Someone who goes by the name John Snow writes:

I’ve been moving into Bayesian modeling and working to translate my understanding and approach to a probabilistic framework. This is a general question about using mean centering to handle time-varying predictors in hierarchical Bayesian models for longitudinal data.

To motivate this question, imagine I have a dataset where a group of people rated their sleep quality and recorded the number of alcoholic drinks they had the day before for 30 days. I want to estimate the relationship between alcohol consumption and sleep quality over time. I land on a multilevel model with random intercepts and slopes; time points are at level 1 and people are at level 2. Pretty straightforward.

One recommendation for handling a time-varying predictor like alcohol consumption would be to create two versions using mean centering: one version is person-centered, where you subtract a person’s mean alcohol consumption from all their values (Xi – X_bar); the other is grand mean-centered, where you take the person’s mean alcohol consumption and subtract the grand mean of alcohol consumption (X_bar – X_gm). (As I understand it the subtracted value could actually be any constant but it seems like the grand mean is used for convenience most of the time). You would then enter the person-centered version as a level 1 predictor and use the grand-mean centered version to explain random intercept and slope variance. The idea is that person-centering isolates the within-person variation and grand mean centering isolates between-person variation. If instead you entered alcohol consumption into the model as a level 1 fixed effect without mean centering, the resulting estimate would capture a mixture of within person and between person variance. Lesa Hoffman has called this a “smushed” effect.

A lot has been written about mean centering in the frequentist MLM literature, and there is a lot of debate and argument about when and how to use mean centering for substantive reasons beyond just making the intercept interpretable. However, I’ve not seen any discussion of this topic in books on the subject or seen it used in code examples (I’m primarily using Pymc). I can’t help but wonder why that is. Is it because mean centering isn’t really needed in a Bayesian MLM? Or, is it just a function of the way people think about and approach MLMs in Bayesian stats?

My reply:

Yes, this topic has come up from time to time, for example:

from 2006: Fitting multilevel models when predictors and group effects correlate

from 2008: “Beyond ‘Fixed Versus Random Effects’”

from 2015: Another example of why centering predictors can be good idea

from 2017: Fitting multilevel models when predictors and group effects correlate

6 thoughts on “Centering predictors in Bayesian multilevel models

  1. Centering also plays a central role (no pun intended) in contrast coding, a topic that remains underexplored in data analysis:

    Daniel J. Schad, Shravan Vasishth, Sven Hohenstein, and Reinhold Kliegl. How to capitalize on a priori contrasts in linear (mixed) models: A tutorial. Journal of Memory and Language, 110, 2020.

    The paper and code are open access so I don’t link to it here as Andrew’s blog always flags my posts for moderation if I post a link.

  2. In general, the recommendation is to within-subject center for separating within from between-subject variance, and to do this with latent centering (centering inside the model, such that the (random) means and centered scores are estimated together), which prevents various issues. Some relevant refs (of which most are in the context of Bayesian stats, which makes the latent centering bit easier):
    Asparouhov, T., Hamaker, E. L., & Muthén, B. (2018). Dynamic structural equation models. Structural Equation Modeling: A Multidisciplinary Journal, 25(3), 359-388.
    Hamaker, E. L., & Muthén, B. (2020). The fixed versus random effects debate and how it relates to centering in multilevel modeling. Psychological methods, 25(3), 365.
    Hamaker, E. L., & Grasman, R. P. (2015). To center or not to center? Investigating inertia with a multilevel autoregressive model. Frontiers in psychology, 5, 1492.

  3. The topic of centering gets quite a bit of attention in psychology, where we usually are uniquely interested in (causal) processes within individuals. To do so, it is standard practice to person-mean (aka cluster-, or group-mean) center your predictors. A canonical citation could be Tofighi and Enders 2007 “Centering predictor variables in cross-sectional multilevel models: A new look at an old issue.”

    An issue with person-mean centering that’s getting a bit more attention is that person-means are estimated from data with uncertainty. Using the observed means to center the variables can then cause some freaky biases in the resulting parameters. A solution to this is so-called latent-person-mean centering, where the person-means are estimated in the model along with the other parameters.

    We recently had a lively discussion about this over at the Stan forums (I can’t seem to put links here, shame), where we were figuring out how to specify such latent-mean models with brms. (I freaking love brms.) We actually ended up finding a solution that is pretty straightforward, and doesn’t require fiddling around with the underlying Stan code.

    John Snow, it is generally recommended to person-mean center your variables in situations like the one you describe. Whether you estimate the model with hamiltonian monte carlo or maximum likelihood doesn’t really make a difference with respect to centering. Since you have 30 observations per person, using observed means for centering is probably just fine (ymmv). ymmv even more as your sample size per person gets smaller. However, if you feel adventurous, you could take a look at the latent mean centering stuff as well. Good luck with the modelling!

  4. This is a really interesting topic. My understaning is that Andrew Gelman suggests to use the individual predictor (as it is, with no centering) and add up a its group-level average. For instance, in a multilevel model of longitudinal data, we would have the time predictors, plus a raw time-varying predictor (X), which captures the within-person effect, plus its person-level average (X_mean), which captures the between-person effect. In lme4 the R code for a simple randomm-intercept model could be something like this:

    model_interaction <- lmer(y ~ x * time + x_mean * time + (1 | id), data = data)

    Just a final question to Andrew Gelman: would this be what you suggested, or something different (or would you rather go for a latent centering verson?

    Thanks!
    Hugo

Leave a Reply

Your email address will not be published. Required fields are marked *