how to include all polynomial and interaction terms

前端 未结 1 937
暗喜
暗喜 2021-01-24 15:24

I have 50 predictors in my dataset, I would like to get the second order terms and the second order interaction terms of these predictors.

Take the mtcars data set in R

相关标签:
1条回答
  • 2021-01-24 16:04

    This is almost surely a bad idea. Anyway, using the mtcars data set, after removing categorical variables

    mtcars=mtcars[,1:7]
    lm(as.formula(paste0("mpg~.^2+",paste0("poly(",colnames(mtcars),",2)",collapse="+")))
    ,data=mtcars)
    
    0 讨论(0)
提交回复
热议问题