0

I have to compare different models (OLS, BEST SUBSET, RIDGE, LASSO, PCR and PLS) using the LOO cross Validation (the criterion of comparison is the test-MSE). Could someone explain me how to do it (possibly using an example dataset)? I need the R code. Thank you all!

P.S : Sorry for my English , but I speak another language.

Ok, I've tried to use the "caret" package:

library(ISLR)

library(caret)

library(forecast)

myControl <- trainControl(method='LOOCV')

LM <- train(Salary~., data=Hitters, method=lm, 
            trControl=myControl)

Step <- train(Salary~., data=Hitters, method='leapSeq', 
                   trControl=myControl)

Ridge <- train(Salary~., data=Hitters, method='ridge', 
               trControl=myControl)

Lasso <- train(Salary~., data=Hitters, method='lasso', 
               trControl=myControl)

PLS <- train(Salary~., data=Hitters, method="pls", 
             trControl=myControl)

PCR <- train(Salary~., data=Hitters, method='pcr', 
             trControl=myControl)

How can I set the parameters lambda, ncomp and nvmax? Thank you all!

Matthew
  • 1
  • 1

1 Answers1

0

I think this is possible with the Caret package: install.packages("caret"). The advantage of Caret is that you can run many different models at the same time and compare the performance. I am however not sure if you can find all the models you request, but take a look at the following list if your models are there: http://topepo.github.io/caret/modelList.html . I would also suggest to read the tutorial: http://www.edii.uclm.es/~useR-2013/Tutorials/kuhn/user_caret_2up.pdf.

Ruthger Righart
  • 4,799
  • 2
  • 28
  • 33