step_rsimpls: Robust PLS (RSIMPLS) Recipe Step

View source: R/recipe_steps_robust.R

step_rsimplsR Documentation

Robust PLS (RSIMPLS) Recipe Step

Description

step_rsimpls() creates a specification of a recipe step that converts the selected variables into robust partial least squares scores, with rsimpls(). It is the robust counterpart of recipes::step_pls(): outlying spectra and wrong reference values have little influence on the components.

Usage

step_rsimpls(
  recipe,
  ...,
  role = "predictor",
  trained = FALSE,
  num_comp = 2,
  outcome = NULL,
  options = list(),
  prefix = "RPLS",
  distances = FALSE,
  keep_original_cols = FALSE,
  res = NULL,
  columns = NULL,
  skip = FALSE,
  id = recipes::rand_id("rsimpls")
)

Arguments

recipe

A recipe object. The step will be added to the sequence of operations for this recipe.

...

One or more selector functions to choose the predictors (for example, the spectral channels). See recipes::selections().

role

The role of the new score columns. Default is "predictor".

trained

A logical indicating whether the step has been trained.

num_comp

The number of PLS components. Default is 2.

outcome

The outcome variable(s), as bare names or a selector. If NULL (default), the outcomes of the recipe are used.

options

A list of further arguments passed to rsimpls(), such as ncomp_max, alpha or ndir.

prefix

The prefix of the new column names. Default is "RPLS".

distances

A logical: add the score and orthogonal distances as columns. Default is FALSE.

keep_original_cols

A logical: keep the selected columns. Default is FALSE.

res

The fitted RSIMPLS model, stored once the step has been trained.

columns

The names of the selected columns, stored once the step has been trained.

skip

A logical. Should the step be skipped when the recipe is baked by recipes::bake()? Keep the default FALSE, so that new data are corrected with the same filter as the training data.

id

A character string that is unique to this step.

Details

The RSIMPLS model is estimated on the training data, with the outcome, when the recipe is prepped, and new data are projected onto it when they are baked; the outcome is not needed then. As the step uses the outcome, it must be estimated on the training data only: in a workflow, it is re-estimated for every resample. Several outcomes give one model of all of them, as with rsimpls().

The new columns are named with prefix followed by the component number, zero-padded as in recipes::step_pls(). With distances = TRUE, two more columns hold the score distance (⁠<prefix>_SD⁠) and the orthogonal distance (⁠<prefix>_OD⁠) of each observation, which can be used to screen new spectra; the residual distance needs the outcome and is not given. The selected columns are removed unless keep_original_cols = TRUE.

Value

An updated version of recipe with the new step added to the sequence of existing steps.

Tuning

num_comp can be tuned with tune::tune(), using dials::num_comp() with values 1 to 4.

Tidying

tidy() returns the weight vectors, which give the scores of the centered predictors, as a tibble with columns terms, value, component and id.

See Also

rsimpls(), step_robpca()

Examples


library(recipes)
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))]
set.seed(1)
rec <- recipe(Ca ~ ., data = dat[1:300, ]) |>
  step_rsimpls(all_predictors(), num_comp = 4, distances = TRUE)
prepped <- prep(rec)
bake(prepped, new_data = dat[301:368, ])
tidy(prepped, number = 1)


specProc documentation built on Nov. 20, 2026, 5:11 p.m.