Determines the optimal number of Partial Least Squares components using leave-one-out or k-fold cross-validation, with robust error handling.
select_optimal_components_safe(X, Y, max_comp = 15, verbose = TRUE)List with components:
ncomp_optimalOptimal number of components selected.
RMSEPRoot Mean Squared Error of Prediction for each component.
R2R-squared values for each component.
validation_methodValidation method used.
pls_fitFitted PLS model object with optimal components.
First data matrix
Second data matrix
Maximum number of components to test (default: 15)
Logical; print progress and diagnostic information. Default TRUE.
default) or "CV" (k-fold cross-validation). validation = "LOO".
The function fits PLS models with 1 to max_comp components,
evaluates each via cross-validation, and selects the number that minimizes
prediction error while avoiding overfitting.