Plotting model effects with brms

Hi, I’m running a multinomial regression model with brms. I would like to plot my model effects in the same way as using the famous effects::allEffects() function. I’ve tried the conditional_effects function but I’ve read some post about the fact that the effects package do some different things compared to conditional_effects.
How can I plot my model effects in the same way as effects? My model is:

fit <- brm(emotion ~ mimicry + (1|subject),
           data = qualia,
           cores = n_cores,
           family = categorical,
           sample_prior = TRUE,
           iter = 6000)

And for plotting I use:

conditional_effects(fit, categorical = TRUE)

This is my session info:

> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Thanks!

I’m quite familiar with brms but not with 'effects::allEffects(). Could you just describe precisely what you are hoping to plot vs. what you are actually getting from brms? How many different plots and for what effects are you hoping to get out?

Thanks for your response! sorry for have taken for granted the effects package. Basically when you have a fitted model you can easily plot all effects computing marginal means and confidence intervals. I have read that the deprecated marginal_effects() now conditional_effects() do some different stuffs (no marginalization) so I’m wondering if there is a way to easily plot your brms model effect in the same way.

What type of variable is mimicry - is that continuous or a categorical predictor? And secondly what sort of response format is emotion -what values can it take? I’m just trying to get a sense of what you want to plot. I might be able to help more if you can describe what marginalised plot you want specifically.

Your effect of mimicry will be ‘marginalised’ over the subject effect, in the sense that the different subject intercepts cancel out to 0 when you look at the effect of mimicry. So if mimicry were categorical and had 3 possibilities, I think the conditional_effects plot would simply show estimated emotion scores and the 95% central posterior interval for each level of mimicry, for the ‘average’ subject in your experiment.

mimicry is a 2 level factor that represents 2 condition (within subject) of the experiment. Emotion is a 3 level factor that i would like to model as a function of mimicry. The idea is simply to have the fitted mean (in this case probability) with 95% CI for each level so 3 emotion times 2 mimicry level -> 6 means.

Okay. And just to check - is emotion ordered (like low, medium, high) or just unordered categories (like happy, angry, sad)? If ordered, you might consider a cumulative model like probit, and in that case I think the plot already would kind of come out like you are hoping for. Sorry for all the questions but could you share the output you get for fit, and also a screenshot of what the plot looks like right now for conditional effects? That will just help to understand what the model is trying to do and perhaps how it could be adapted to get what you want.

1 Like

Thank you! no I fitted a multinomial model given that i’ve an unordered factor. this is the model output:

> summary(fit)
 Family: categorical 
  Links: mumixed = logit; muneutral = logit 
Formula: emotion ~ mimicry + (1 | subject) 
   Data: qualia (Number of observations: 757) 
Samples: 6 chains, each with iter = 4000; warmup = 2000; thin = 1;
         total post-warmup samples = 12000

Group-Level Effects: 
~subject (Number of levels: 32) 
                        Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(mumixed_Intercept)       0.60      0.16     0.32     0.94 1.00     4182     5215
sd(muneutral_Intercept)     1.44      0.30     0.95     2.12 1.00     3111     5733

Population-Level Effects: 
                         Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
mumixed_Intercept           -0.77      0.17    -1.13    -0.44 1.00     6413     8050
muneutral_Intercept         -1.41      0.33    -2.10    -0.80 1.00     2953     4818
mumixed_mimicryblocked       0.07      0.18    -0.27     0.42 1.00    14841     8569
muneutral_mimicryblocked     0.05      0.20    -0.35     0.45 1.00    16030     8892

Samples were drawn using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).

and this is the plot: conditional_effects(fit, categorical = TRUE)

I think the plot is giving you pretty much what you want? - those probability estimates will be reflecting the average predicted probability over the participants under each condition. The central point is most likely the mean of the posterior distribution estimate, and the lines are like a confidence interval - in this case I think they reflect the middle 95% of estimates from the posterior distribution.

The only thing I note in your model that you may have a preference for changing is that right now ‘happy’ and ‘free’ appear to be used as your reference level/intercept - so the model is estimating the probabilities of mixed and neutral as deflections from happy, and blocked as deflections from free. Just depending on how you think of your outcomes and experimental manipulation, you might want to choose a difference level as the reference point or intercept. E.g., imagining you had neutral, angry, and happy, you might want to make neutral the reference point to make it easier to understand your model as angry and happy having probabilities in relation to neutral as an anchor point. I think it is just choosing the reference point alphabetically, so in your case happy comes before mixed and neutral. If you did want to change it (and there is no necessity to if it is not your preference) you could name your variables like 0neutral, 1happy, 2mixed or whatever.

But I think you can consider your plot to be a reflection of the fitted mean estimates.

You could also just check if the model performs any differently/if the output looks any difference if you make your intercept explicit in the formula:

emotion ~ 1 + mimicry + (1 | subject)