Model Selection Methods: Strategies to select the best models with code.

Best subsets

library(leaps)
regsubsetsObj <- regsubsets(x=predictors.df ,y=response.df, nbest = 2, really.big = T)
plot(regsubsetsObj, scale = "adjr2")

Stepwise Regression

lmMod <- lm(responseVar ~ . , data = inputData)
selectedMod <- step(lmMod)
summary(selectedMod)

Leaps

library(leaps)
leapSet <- leaps(x= predictors.df, y= response.df, nbest = 5 ,method = criterion) # criterion could be one of "Cp", "adjr2", "r2". Works for max of 32 predictors.

RegBest() from FactoMineR

library(FactoMineR)
regMod <- RegBest(y= responseVar, x = predictors.df)
summary(regMod)

If you like us, please tell your friends.Share on LinkedInShare on Google+Share on RedditTweet about this on TwitterShare on Facebook