Ali Turab Lotia Ali Turab Lotia - 4 months ago 16
R Question

How can you generate a list of all possible significant interaction terms to be used in a GLM?

Is there a command that can return all significant interaction terms in R?

For example:

Input = c(age, gender,nationality)

output = list of significant interactions =
c(age * gender, gender * nationality, age * nationality * gender)


Try the broom package:

m = lm(mpg ~ am * hp * disp, data = mtcars)
tidy.m = tidy(m)
tidy.m$term[tidy.m$p.value < 0.05]

Which gives you:

[1] "(Intercept)" "am"          "am:disp"     "am:hp:disp" 

Is that what you want?

(This is assuming that the p value is the indicator of significance.)