Brms hypothesis test for term in interaction by condition

Probably a basic question, but say I have a model Y ~ X1*X2 and both X1 and X2 are continuous. How would I do a directional hypothesis test for the effect of X1, conditioned on the predictor X2 being some arbitrary value, e.g., X2 = 2?

Just plug in 2 for X2 (or whatever value) when computing your predictions.

Using the predict function? If so, how do I then test the hypothesis (e.g., that the effect of X1 > 0)?

If X2 = 2:

hypothesis(<model>, "X1 + X1:X2 * 2 > 0")

Of course, that’s beautiful and simple! Thank you.

What if he were to just test for the interaction effect? would the following server the purpose paul.buerkner?

hypothesis( , “X1:X2 > 0”)

1 Like

Yes, this would be sufficient.

So say both predictors are categorical and both have two levels, sum coded to +1 and -1. Could I find the effect of X1 at each level of X2 like this:

hypothesis(, “X1 + X1:X2 * 1 > 0”)
hypothesis(, “X1 + X1:X2 * -1 > 0”)



1 Like

Hi Paul, may I know how to plug in values in models with category specific predictors?

I have


Y is a three-level ordinal variable (incorrect, partial, correct), X1 to X4 are binary variables.
I would like to test when X1=1, whether the probability of Y=partial (compared to Y=correct) will be greater for X4=1 (compared to X4=0)
I tried the hypothesis function in brms:

print(hypothesis(model, hp, class = NULL),digits=3)

and found:

Error: Some parameters cannot be found in the model: 
'X2', 'X3', 'X2:X3'

May I know whether the expressions in plogis() are correct and how to plug in X1=1 in this model? Thank you.

you need to set class = “bcs” to target cs() parameters in hypothesis.

@paul.buerkner Thanks for your reply. I tried to change class=NULL to class=“bcs”, it seems that the class=“b” parameters can not be identified

Error: Some parameters cannot be found in the model: 
'bcs_Intercept[2]', 'bcs_X1'...

If I specified the full name of the parameters (e.g., b_X1, bcs_X4) and use class=NULL without plugging in values, the hypothesis function works well.

print(hypothesis(model, hp1, class = NULL),digits=3)

Is it possible to plug in X1=1? It seems that there is something wrong with the interaction terms (e.g. X1*1:X2) when plugging in values. Thank you.

Set class = NULL and add class prefixes (b_ etc.) to the parameter names in the hypothesis.

I have a three-way interaction term X1:X2:X3 in the model. I set class=NULL and plugged in X1=1


but this didn’t work

Error: Some parameters cannot be found in the model: 
'X2', 'X3', 'X2:X3'

It seems that only the last variable in the interaction term can be plugged in a value in this way (e.g. X1:X2:X3*1 works well). Is it possible to plug in X1=1? Thank you.