| step_epo | R Documentation |
step_epo() creates a specification of a recipe step that projects the
selected predictors onto the space orthogonal to the dominant directions
of a clutter matrix, with epo().
step_epo(
recipe,
...,
role = NA,
trained = FALSE,
clutter = NULL,
num_comp = 2,
res = NULL,
columns = NULL,
skip = FALSE,
id = recipes::rand_id("epo")
)
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. |
clutter |
A numeric matrix or data frame of clutter spectra. If it has column names, the columns matching the selected predictors are used; otherwise it must have one column per selected predictor, in the same order. |
num_comp |
The number of orthogonal components to remove. |
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 clutter describes variation that should not affect the outcome, for
example the differences between repeated measurements of the same samples.
It is external information, supplied when the step is specified, and is
not estimated from the training data. If clutter = NULL, the dominant
directions of the training data themselves are removed, as in epo().
The outcome is not used.
The selected columns are replaced by the corrected values (not centered).
num_comp can be tuned with tune::tune(). tidy()
returns the selected terms, num_comp and id.
An updated version of recipe with the new step added to the
sequence of existing steps.
epo(), predict.specproc_filter()
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))]
# the three samples measured twice
twice <- forageLIBS$Sample[duplicated(forageLIBS$Sample)]
first <- match(twice, forageLIBS$Sample)
second <- vapply(twice, function(s) max(which(forageLIBS$Sample == s)), integer(1))
# their differences describe the variation between repeated measurements
clutter <- as.matrix(dat[second, -1]) - as.matrix(dat[first, -1])
rec <- recipes::recipe(K ~ ., data = dat[1:300, ]) |>
step_epo(recipes::all_predictors(), clutter = clutter, num_comp = 1)
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.