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!

1 Answer 1

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.

1
  • I've tried to use the "caret" package, but I have some problems. Can you help me? Thank you.
    – Matthew
    May 23, 2015 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.