| step_glsw | R Documentation |
step_glsw() creates a specification of a recipe step that down-weights
the directions of the selected predictors that vary in a clutter matrix,
with the generalized least squares weighting filter of glsw().
step_glsw(
recipe,
...,
role = NA,
trained = FALSE,
clutter,
alpha = 0.01,
res = NULL,
columns = NULL,
skip = FALSE,
id = recipes::rand_id("glsw")
)
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 difference spectra. It is
matched to the selected predictors as in |
alpha |
A positive number: the weighting parameter, relative to the largest eigenvalue of the clutter. Default is 0.01. |
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. |
clutter holds differences between spectra that should be identical, such
as x2 - x1 for the paired spectra of glsw(). It is centered, so the
filter equals glsw(x1, x2, alpha = a), where the absolute a is alpha
times the largest eigenvalue of the centered clutter cross-product. Setting
alpha relative to that eigenvalue makes it independent of the scale of
the spectra, which simplifies tuning: small values remove the clutter
directions almost completely (like step_epo()), large values leave the
data nearly unchanged.
The filter is stored in factored form, so its memory use grows with the
number of predictors rather than its square. The selected columns are
replaced by the filtered values (not centered). alpha can be tuned with
tune::tune(), using glsw_alpha(). tidy()
returns the selected terms, alpha (relative) and id.
An updated version of recipe with the new step added to the
sequence of existing steps.
glsw(), step_y_gradient_glsw()
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_glsw(recipes::all_predictors(), clutter = clutter, alpha = 0.01)
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.