Generate interaction terms for lm
formulas
intGen.Rd
Specify two-way or three-way interactions from a set of independent variables. The function might be useful, if the user has a regression model with more than two predictors and want to specify all main effects plus all two-way interaction effects but no higher-order interaction terms.
Examples
data(mtcars)
# relevant variables
vars <- c("cyl", "hp", "wt")
# cyl*hp*wt would specify two-way as well as three-way interactions
# generate formula snippet for two-way interactionn
frml <- intGen(vars = vars, upto = 2)
frml1<- as.formula(paste0("mpg ~ ", paste(vars, collapse=" + "), " + ",
paste(frml, collapse=" + ")))
mod <- lm(frml1, data = mtcars)