您如何生成要在 GLM 中使用的所有可能的重要交互作用项的列表?

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

是否有命令可以 return R 中所有重要的交互项?

例如:

输入=c(年龄、性别、国籍)

输出 = 重要交互列表 = c(年龄*性别,性别*国籍,年龄*国籍*性别)

试试 broom 包:

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

这给你:

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

这是你想要的吗?

(假设p值是显着性指标。)