I am looking for a variable selection technique in R to reduce the number of my regression predictors, where I can force the method to keep a specific variable within the model. Here is a toy example from the R help of ?step, the variable "Examination" will be removed:

summary(lm1 <- lm(Fertility ~ ., data = swiss));
slm1 <- step(lm1);
  • 2
    $\begingroup$ This related thread might help: Multiple regression with no origin and mix of directly entered and stepwise entered variables using R. $\endgroup$
    – chl
    Commented Jul 7, 2011 at 6:14
  • 1
    $\begingroup$ (+1) to @chl, nice answer regarding scope option (and there is enough information on this pre-selection in ?step). $\endgroup$ Commented Jul 7, 2011 at 6:48
  • $\begingroup$ thank you both for your answers! sorry that i missed the information i have been looking for in the R help. best m $\endgroup$
    – Marco
    Commented Jul 7, 2011 at 8:07
  • 1
    $\begingroup$ Note that typical variable selection strategies (such as stepwise selection algorithms), which I suspect you have in mind based on the reference to step(), are not valid. If that doesn't make sense / you want to know why, you may want to read my answer here: algorithms-for-automatic-model-selection. $\endgroup$ Commented May 26, 2013 at 19:10


Browse other questions tagged or ask your own question.