我知道在 R
中有一种快捷方式可以对像这样的数据框运行一个 lm()
回归:
reg<-lm(y~.,data=df)
使用 df 作为自变量 x1、x2、...、x5 的解释变量,所以这与写成以下形式相同:
With df having explanatory variables x1, x2, ... x5, so it is the same as writing
reg<-lm(y~x1+x2+x3+x4+x5,data=df)
但是这并不包括像x1:x2这样的交互项,...在R中有没有一种快捷方式可以在数据框的所有列上运行回归并包含交互作用? 我正在寻找两个快捷方式,其效果与...
reg<-lm(y~x1*x2,x1*x3,x1*x4,x1*x5,x2*x3,...)
reg<-lm(y~x1*x2*x3*x4*x5) # this one will have interactions between the 5 variables