Learn R Programming

convergenceDFM (version 0.1.4)

select_optimal_components_safe: Select optimal number of PLS components with cross-validation

Description

Determines the optimal number of Partial Least Squares components using leave-one-out or k-fold cross-validation, with robust error handling.

Usage

select_optimal_components_safe(X, Y, max_comp = 15, verbose = TRUE)

Value

List with components:

ncomp_optimal

Optimal number of components selected.

RMSEP

Root Mean Squared Error of Prediction for each component.

R2

R-squared values for each component.

validation_method

Validation method used.

pls_fit

Fitted PLS model object with optimal components.

Arguments

X

First data matrix

Y

Second data matrix

max_comp

Maximum number of components to test (default: 15)

verbose

Logical; print progress and diagnostic information. Default TRUE.

Details

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.