| step_opls | R Documentation |
step_opls() creates a specification of a recipe step that removes
num_comp orthogonal components from the selected predictors with the
OPLS model of opls(): the selected columns are replaced by the
OPLS-filtered data.
step_opls(
recipe,
...,
role = NA,
trained = FALSE,
outcome = NULL,
num_comp = 2,
options = list(),
res = NULL,
columns = NULL,
skip = FALSE,
id = recipes::rand_id("opls")
)
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 |
role |
Not used by this step, since no new variables are created. |
trained |
A logical indicating whether the step has been trained. |
outcome |
The outcome variable, as a bare name or a selector. If
|
num_comp |
The number of orthogonal components to remove. |
options |
A list of further arguments passed to |
res |
The fitted filter, stored once the step has been trained. |
columns |
The names of the selected predictors, stored once the step has been trained. |
skip |
A logical. Should the step be skipped when the recipe is baked
by |
id |
A character string that is unique to this step. |
The filtered data are the same as those of step_projected_osc() with the
same num_comp. For Pareto scaling, add step_pareto_scale() before this
step. The model is fitted without cross-validation or permutation test,
which do not change the filter.
The number of orthogonal components is not selected automatically: tune
num_comp instead. As for step_osc(), the filter uses the outcome and
is estimated on the training data only; the outcome is not needed when new
data are baked.
An updated version of recipe with the new step added to the
sequence of existing steps.
num_comp can be tuned with tune::tune(); its default range is
dials::num_comp() with values 1 to 4.
tidy() returns a tibble with columns terms (the
selected predictors), num_comp and id.
opls(), predict.specproc_opls()
data(forageLIBS)
# potassium and the K I resonance lines
wl <- suppressWarnings(as.numeric(names(forageLIBS)))
dat <- forageLIBS[c(which(names(forageLIBS) == "K"), which(wl > 760 & wl < 780))]
# Pareto scaling, then the OPLS filter
rec <- recipes::recipe(K ~ ., data = dat[1:300, ]) |>
step_pareto_scale(recipes::all_predictors()) |>
step_opls(recipes::all_predictors(), num_comp = 2)
prepped <- recipes::prep(rec)
recipes::bake(prepped, new_data = dat[301:368, ])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.