How to automatically include all 2-way interactions in a glm model in R

Solution 1:

You can do two-way interactions simply using .*. and arbitrary n-way interactions writing .^n. formula(g) will tell you the expanded version of the formula in each of these cases.