# How do I use the \`conditions\` argument for \`conditional\_effects()\`?

**URL:** <https://discourse.mc-stan.org/t/how-do-i-use-the-conditions-argument-for-conditional-effects/26884>\
**Category:** brms\
**Created:** [March 21, 2022, 1:15pm UTC](https://discourse.mc-stan.org/t/how-do-i-use-the-conditions-argument-for-conditional-effects/26884 "2022-03-21T13:15:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh\_fiechter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/josh_fiechter/32/6031_2.png) [@josh\_fiechter](https://discourse.mc-stan.org/u/josh_fiechter)\
**Post date:** [March 21, 2022, 1:15pm UTC](https://discourse.mc-stan.org/t/how-do-i-use-the-conditions-argument-for-conditional-effects/26884/1 "2022-03-21T13:15:54Z")

</div>

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.

```nohighlight
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

---

<div class="post-metadata">

**Author:** ![andymilne](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andymilne/32/21046_2.png) [@andymilne](https://discourse.mc-stan.org/u/andymilne)\
**Post date:** [March 23, 2022, 1:28am UTC](https://discourse.mc-stan.org/t/how-do-i-use-the-conditions-argument-for-conditional-effects/26884/2 "2022-03-23T01:28:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![josh\_fiechter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/josh_fiechter/32/6031_2.png) [@josh\_fiechter](https://discourse.mc-stan.org/u/josh_fiechter)\
**Post date:** [March 23, 2022, 2:47pm UTC](https://discourse.mc-stan.org/t/how-do-i-use-the-conditions-argument-for-conditional-effects/26884/3 "2022-03-23T14:47:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andymilne](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andymilne/32/21046_2.png) [@andymilne](https://discourse.mc-stan.org/u/andymilne)\
**Post date:** [March 23, 2022, 8:36pm UTC](https://discourse.mc-stan.org/t/how-do-i-use-the-conditions-argument-for-conditional-effects/26884/4 "2022-03-23T20:36:35Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![josh\_fiechter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/josh_fiechter/32/6031_2.png) [@josh\_fiechter](https://discourse.mc-stan.org/u/josh_fiechter)\
**Post date:** [March 24, 2022, 6:49pm UTC](https://discourse.mc-stan.org/t/how-do-i-use-the-conditions-argument-for-conditional-effects/26884/5 "2022-03-24T18:49:05Z")

</div>

Ah, yes, that was my problem. Thanks!
