Setting up correct model formula for interaction between boolean and continuous variable

I would like to set up a brms formula that includes two variables, say A and B, where A is boolean (true/false) and B continuous. The formula should consider A by default, and B only if A is true (since B has no physical meaning if A is false). Is this possible to express in a brms formula? I had a hard time finding related examples so my problem might be ill-posed.

One approach that gives reasonable parameter estimates is to convert A from TRUE/FALSE to 1/0 and then include B with an interaction:

formula = A + B:A

Is this a valid solution? It feels like this is not a “standard” way to include an interaction term as B is not included as a main effect.

  • Operating System: Windows 10
  • brms Version: 2.14.4

This is how I would do it. Sure, it’s not standard. But you don’t have a standard model and your justification seemed sensible.

1 Like

Thanks again for your view on this.

Sorry, I got a late follow-up question. I can also open a new thread but I thought this fits better here. Since I have other continuous variables in the model that I would like to compare parameter coefficients across after fitting, I standardize all variables before fitting in brms. Do you have any idea on how to do that for variable B in the example above? Since B only makes sense when A is true (or equal to 1), I should actually replace all values of B with NA’s wherever A is false. But that would cause the interaction B:A to become NA as well, while it should remain zero, possibly causing issues for the fitting.