Search code examples
rlinear-regression

Multiple regression leave out one variable (column)


Where there are many columns in data frame and you want to just leave out one or two columns and include everything else in the multiple regression, How can we accomplish that without writing out a large formula?

for example to include all:

lm(y ~., data=myFrame)

Then if you want to handpick one by one

lm(y ~ x1 + x2 + x3)

but if you have 50 variables but want to leave out few what's the best way? Because I want to leave out two or three, include all the rest,and then do forward and backward selection.


Solution

  • Use the . operator for "everything in the data frame except the response variable" and the - operator for "but leave these out" ...

    lm(y ~ . - excluded_1 - excluded_2, data = myFrame)