How do I use the `conditions` argument for `conditional_effects()`?

I’m trying to generate marginal effects from a brms model using the conditional_effects() function but am having some trouble with a three-way interaction. I initially got a message that the conditions argument needs to be used for an interaction higher than order 2, but then I still get that same message even after including a conditions argument. Pseudo-code is below.

ce_1 <- conditional_effects(fit_1, 
                              conditions = make_conditions(fit_1, vars = c("var1", "var2", "var3")),
                              effects = "var1:var2:var3", 
                              resp = "resp1")

Again, code in the form above still generates a warning message that I need to use conditions.

Does anyone know what I’m doing wrong? My apologies in advance if I’m missing something obvious.

  • Operating System: Windows 11
  • brms Version: 2.16.3

I think the first argument of make_conditions needs to be the dataframe with the data, not the fitted model.

Thanks for chiming in! Sorry for not responding sooner. I’ve tried running the code with a data frame instead of a fitted model and still get the message that I need to use conditions.

In case these details matter, I’ll add that this model is a multivariate one with two response variables and also used a custom Stan function (for robit regression) for one of the response variables. I’m not sure if either of those features would matter. I get the same warning message for either response.

I see the other problem – you have specified a three-way interaction in the effects argument. You can only specify a 2-way interaction – e.g. effects = "var1:var2". The remaining variable in the interaction goes into conditions – e.g., conditions = make_conditions(fit_1, vars = c("var3")). Note that var1 will be plotted on the x-axis, var2 will be grouped (by colour), var3 will be plotted across different plots. If you change the placement of the three vars, you can get a total of 6 different ways of plotting the 3-way interaction. Hopefully this modification works and my answer makes sense!

1 Like

Ah, yes, that was my problem. Thanks!