How to write interactions in regressions in R?
问题 DF <- data.frame(factor1=rep(1:4,1000), factor2 = rep(1:4,each=1000),base = rnorm(4000,0,1),dep=rnorm(4000,400,5)) DF$f1_1 = DF$factor1 == 1 DF$f1_2 = DF$factor1 == 2 DF$f1_3 = DF$factor1 == 3 DF$f1_4 = DF$factor1 == 4 DF$f2_1 = DF$factor2 == 1 DF$f2_2 = DF$factor2 == 2 DF$f2_3 = DF$factor2 == 3 DF$f2_4 = DF$factor2 == 4 I want to run the following regression: Dep = (f1_1 + f1_2 + f1_3 + f1_4)*(f2_1 + f2_2 + f2_3 + f2_4)*(base+base^2+base^3+base^4+base^5) Is there a smarter way to do it? 回答1: