Is extracting random coefficients so hard?

Hello all,

I’m currently self-learning the path of Bayes, and been trying to fit this model. The DV is a neural measure (continuous). Main predictor is Age (2 factors Young/Old). Each DV is also measured from different brain regions (ROI, 4 levels). Both categorical.

The main questions are

  1. Does Age play a role in the DV ? (population level effect inference)
  2. What are the effects in each ROI ? i.e in the data Old ROI values are lower than Young ROI, then who’s contribution to the decrease is most ? (group level effect inference)

The HADS variables are anxiety/depression scores. AGE:ROI I added as a main effect (should I have not ?).

Major questions

  1. Is the specification correct ? (1+ROI|AGE). What I had in mind was the ROI levels would take the cell mean and compare effects of AGE levels within them.

  2. I can’t for my life extract the individual ROI-AGE coefficient values. How do I manually get the coefficient values off the intercept (which has one ROI level as reference) for all ROI levels separately, so as to plot them all individually?

I tried ranef as well as coef, but they did not have these individually…

The second question is much much more dire so if anyone can help me on this/ share a link or code to do via tidy that would be greatly appreciated.


  • Operating System: Windows 10
  • brms Version: 2.14.4

Don’t forget to add relevant tags to your topic (top right of this form) especially for application area. Delete this text before posting your question :-) Thx!

Looking forward to your topic!


This means that you want to model each level of AGE as completely arbitritrary in their label, with each level having both a unique intercept (deviation from the population grand mean) and a unique set of ROI effects, with estimation of correlations among these quantities across the levels of AGE. Now, if “AGE” truly means age as in a measure of life duration, then this makes no sense whatsoever. Things that are measured meaningfully should never appear on the right side of a | in a mixed effects model, always on the left.

Possibly this is a typo, and you meant (1+AGE|ROI), which might make more sense if ROI is an unordered categorical variable the levels of which you want to model as exchangeable replicates from a particular population distribution. BUT you also have the term AGE:ROI which cannot be combined with (1+AGE|ROI). (Also, the inclusion of AGE:ROI with no main effect of ROI is odd, which suggests to me that you don’t actually want AGE:ROI in there and instead really want (1+AGE|ROI))

1 Like

Hi Mike,

Thank you for the reply.

AGE here is a categorical variable of YOUNG and OLD (not continuous variable). That being said, the effect I was looking for is how say, ROI1 of YOUNG compares to ROI1 to OLD, given that ROI’s mean. Say if grand mean is 0.35, and Mean of YOUNG is 0.47 and OLD is 0.23, how much is the effect of ROI1 on YOUNG compared to mean of that ROI (and not the mean of YOUNG).

When I did (1+AGE|ROI) before it seemed to me it was averaging across the AGE means since some values of ROI in OLD was higher than YOUNG (which shouldn’t be since OLD has all ROI values lower than YOUNG).

I’m still not able to figure out how to extract individual coefficients (as separate, not as deviations off intercept)…neither for the population effects nor group level affects. Can someone share some insight on how to do this by hand (including the intervals).

Even if you have binarized age (which is usually a bad idea btw), it still does not make sense to put it on the right side of the | (indeed, with only two levels, it especially doesn’t make sense)

What I suspect you want is:

formula = BOLD ~ 

(The * is R formula syntax that is equivalent to AGE + ROI + AGE:ROI).

From there, see brms::conditional_effects().

1 Like

You’re right. AGE would be better off as continuous variable (centered) than in binary level.

I’ve been specifying a model as you said above, but in addition I added (1+AGE|ROI) instead, which seems to be consistent. I do have a doubt on that though ; All the mean (descriptive) values of OLD AGE on every ROI is lower (individually) than YOUNG AGE of those ROI. But in the group level effects of the model, one of them has more effect size (posterior mean) than YOUNG. Is this normal in such models or just the frequentist ghost inside me screaming?

Also. I can’t get a hold of the individual group level values (each AGE/ROI value) off conditional effects (which plots the effects excellently). Should I have to wrangle manually or is there a function for that? (coef gives intercept inclusive one)

You cannot have ROI both as a fixed effect and as a random effect. You have to choose one or the other.

1 Like