View source: R/recipe_steps_preprocessing.R
| step_emsc | R Documentation |
step_emsc() creates a specification of a recipe step that corrects
each spectrum for multiplicative effects, a polynomial baseline and,
optionally, known interferents, with emsc().
step_emsc(
recipe,
...,
role = NA,
trained = FALSE,
degree = 2,
interferents = NULL,
wavelength = NULL,
robust = TRUE,
res = NULL,
columns = NULL,
skip = FALSE,
id = recipes::rand_id("emsc")
)
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. |
degree |
The degree of the polynomial baseline. Default is 2. |
interferents |
An optional numeric matrix or data frame of interferent spectra, one per row. 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. |
wavelength |
An optional numeric vector of wavelengths, one per
selected column, used to build the polynomials. If |
robust |
A logical: use the median ( |
res |
The fitted EMSC 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 |
id |
A character string that is unique to this step. |
The reference spectrum is estimated from the training spectra when the recipe is prepped, and new spectra are corrected with the same reference, polynomials and interferents when they are baked. The selected columns form one spectrum per row and are replaced by the corrected values.
degree can be tuned with tune::tune(), using dials::degree_int()
with values 0 to 4. tidy() returns the selected
terms, the reference value of each (NA before the step is trained)
and id.
An updated version of recipe with the new step added to the
sequence of existing steps.
emsc(), step_msc()
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))]
rec <- recipes::recipe(K ~ ., data = dat[1:300, ]) |>
step_emsc(recipes::all_predictors(), degree = 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.