# Find the number of dimensions with lowest cross validation error
cv <- RMSEP(pls.model)
best.dims <- which.min(cv$val[estimate = "adjCV", , ]) - 1
# Rerun the model
pls.model <- plsr(pref ~ ., data = dat, ncomp = best.dims)