| pls_rsimpls | R Documentation |
specProc adds the "rsimpls" engine to parsnip::pls(), which fits the
robust PLS regression of rsimpls(): outlying spectra and wrong reference
values have little influence on the model. It can be tuned, resampled and
combined with recipes like any parsnip model.
The engine is available once parsnip and specProc are both loaded, in
either order. It is for regression only, with one or several outcomes
(for example cbind(y1, y2) ~ .).
num_comp (ncomp of rsimpls()): the number of PLS components. It
has no default and must be given (or tuned). It can be tuned with
tune::tune(), using dials::num_comp().
predictor_prop, the proportion of predictors of sparse PLS, is not
used by this engine.
The models with 1 to ncomp_max components all come from the same ROBPCA fit
(see rsimpls()), so parsnip::multi_predict() gives the predictions of
all of them from one fit, and tune::tune_grid() fits a single model per
resample for a grid of num_comp. The predictions of a model with fewer
components are those of a separate fit with the same ncomp_max, as long as
ncomp_max is at least the largest num_comp.
The other arguments of rsimpls() are set with parsnip::set_engine():
ncomp_max, the largest number of components (default 10), alpha, the
fraction of observations assumed to be regular (default 0.75), and
ndir and nsamp of the ROBPCA step.
The predictors are centered robustly by the model, and are not scaled:
scale them beforehand if their units differ. Factor predictors are
converted to indicator variables. rsimpls() uses random directions and
subsets, so use set.seed() before fitting for reproducible results.
The fitted rsimpls() model is returned by
parsnip::extract_fit_engine(), for its outlier maps
(plot_outlier_map()) and distances.
Christian L. Goueguel
rsimpls(), step_rsimpls(), parsnip::pls()
library(parsnip)
data(forageLIBS)
# calcium and the Ca II and Ca I lines
wl <- suppressWarnings(as.numeric(names(forageLIBS)))
dat <- forageLIBS[c(which(names(forageLIBS) == "Ca"), which(wl > 380 & wl < 430))]
spec <- pls(num_comp = 4) |>
set_engine("rsimpls") |>
set_mode("regression")
set.seed(1)
fit <- fit(spec, Ca ~ ., data = dat[1:300, ])
predict(fit, dat[301:368, ])
# predictions with 1 to 4 components
multi_predict(fit, dat[301:303, ], num_comp = 1:4)$.pred[[1]]
plot_outlier_map(extract_fit_engine(fit))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.