I had a question regarding the composition of coefficents of a linear model in R.

Let's say my model is as follows, with three columns/independent variables: X, Y, and Z.

And my model is: (X * Z) + (Y * Z).

Is this comparable to performing the transformation X * Z, Y * Z before modeling ? I.e. mutate() creating new columns 'XZ' and 'YZ', thus my new formula is just XZ + YZ ?

In my intuition, I want to say 'no', because when you're running the model, it is holding all other variables constant.

I just ask because if it were possible, this would greatly simplify my analysis -- plus, having the multiplication in the equation makes it unbearably slow in R (like, days), and provided the limited computing resources I have access to, restricts me to processing incredibly small sample data sets.

However, I know this equation is the result I am after.

Any advice would be appreciated.


1 Answer 1


thus my new formula is just XZ + YZ ?

No, the * operator in R expands into all lower-order terms.

terms(~(X * Z) + (Y * Z))

Simply adding a product term to a formula can be accomplished with the : operator (not that I assume you want to do this, but it can be useful to know).

terms(~ X:Z + Y:Z)

See the ?formula help page for details.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.