Using the seatpos
dataset from the faraway
package in R, I wanted to do PLS regression models with up to eight components, choose the one with lowest RMSE as optimal model, and make predictions with it.
So I first created the models and computed the RMSEs for each of them:
> plsmod <- plsr(hipcenter ~ .,data=seatpos,ncomp=8,validation='CV')
> plsCV <- RMSEP(plsmod,estimate='CV')
Plotting RMSEP vs number of components, it can be seen that the model with lowest RMSE has three components:
> plot(plsCV,main='')
The lowest RMSEP thus corresponds to the model with three components, which corresponds to plsCV[4]
:
> plsCV
(Intercept) 1 comps 2 comps 3 comps 4 comps 5 comps
60.45 45.90 40.54 38.62 42.36 43.54
6 comps 7 comps 8 comps
45.05 45.12 45.33
Looking to the plot, the output for plsCV
, and the documentation of plsr()
I would specify ncmop = 3
in predict()
, but if I followed the same way of analysis as for PCR in the book of Faraway, then I should use the output for which.min(plsCV$val)
, i.e. 4 in my case, for ncomp
.
So, when using predict()
in my PLS model, do I need to specify ncomp = 3
or ncomp = 4
?
ncomp=4
gives lower RMSE:> rmse <- function(x,y) sqrt(mean((x-y)^2)) > rmse(predict(plsmod,ncomp = 3),seatpos$hipcenter) [1] 34.17719 > rmse(predict(plsmod,ncomp = 4),seatpos$hipcenter) [1] 33.19577
But how to concile that with the plot and plsCV values? $\endgroup$