[英]How to automatically include all 2-way interactions in a glm model in R
Suppose you are using R
and have data stored in a data frame, M
. 假设您正在使用
R
并将数据存储在数据帧M
。 Then I know that 然后我就知道了
g <- glm(Y ~ ., data=M)
will automatically fit a model where Y
is the dependent variables and all other columns of M
are the predictors. 将自动拟合一个模型,其中
Y
是因变量, M
所有其他列都是预测变量。 Is there an analogously simple way to additionally include every two way interaction? 是否有类似的简单方法来额外包含每两种方式的交互?
You can do two-way interactions simply using .*.
您只需使用
.*.
即可进行双向交互.*.
and arbitrary n -way interactions writing .^n
. 和任意的n -way交互写作
.^n
。 formula(g)
will tell you the expanded version of the formula in each of these cases. formula(g)
将告诉你每种情况下公式的扩展版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.