How to automatically enable all two-way interactions in the glm model in R

Suppose you are using R and have data stored in a data frame, M Then I know that

 g <- glm(Y ~ ., data=M) 

will automatically correspond to the model, where Y are dependent variables, and all other columns of M are predictors. Is there a similarly simple way to additionally include each two-way interaction?

+51
r
Jul 24 2018-12-24T00:
source share
1 answer

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

+68
Jul 24 2018-12-14T00:
source share



All Articles