Hi,
I am running 2 different models with brms and have some difficulties with contrasts.
The first one is with age as a continuous variable, and 4 conditions that I want to compare. Similarly as in lme4 one condition is selected as a reference, but since I have 4 conditions I want the comparisons of all of them together.
Similarly, I have the same model but this time with age group (categorical). Let’s say I put as a reference the adults group, to see whether there is a difference with children for conditions. Can I get the difference between conditions within each group without rerunning the model with a different reference?
What would be the best way to check contrasts between levels of a factor that are not the reference level?
Thank you
Marie
I recognize that you’ve identified this as a multilevel model, but the way you’ve written your question, it seems like you’re treating age and condition as fixed effects. Below I give ideas presuming that’s the case. If I’ve misinterpreted your model, please flesh it out a bit more.
First example
A simple way is to suppress the default intercept, which will give separate intercepts for each of your conditions. Given a criterion y, your formula syntax might be y ~ 0 + condition + age
. When you extract the posterior samples with posterior_samples()
, four of the columns will be for the four categories of condition
. You can then compute the contrasts directly, subtracting one column from another as desired.
Second example
Unless you want to delve into the nonlinear syntax, this solution will be a more convoluted extension of the first. Here you might just use more conventional formula syntax like y ~ condition + age
. Say you name your posterior samples post
.
post <- posterior_samples(your_fit)
You can compute the estimates for the three non-reference age categories by adding their columns for their differences to the intercept. That’d look something like this.
post$age_2 <- post$b_Intercept + post$b_age_category_2
And now you can compute the contrasts by hand.
If you want to play around with it, you should also be able to solve both these issues with the fitted()
function and careful use of the newdata
argument.
Hey Solomon,
Apologies for not replying sooner!
You interpreted the model right, multilevel was a bad term. And the contrasts work the way you wrote them. I managed to have each comparison I needed.
Thank you very much for your help.
1 Like