Subtract or Divide by Reference Spectrum
Source:R/reference-subtract.R
step_measure_subtract_reference.Rdstep_measure_subtract_reference() creates a specification of a recipe
step that subtracts or divides each spectrum by an external reference.
This is a simpler version of step_measure_subtract_blank() that always
uses an externally provided reference.
Usage
step_measure_subtract_reference(
recipe,
reference,
method = "subtract",
measures = NULL,
role = NA,
trained = FALSE,
learned_ref = NULL,
skip = FALSE,
id = recipes::rand_id("measure_subtract_reference")
)Arguments
- recipe
A recipe object. The step will be added to the sequence of operations for this recipe.
- reference
A required external reference spectrum. Can be:
A
measure_tblobject withlocationandvaluecolumnsA numeric vector (must match the number of locations in data)
A data.frame with
locationandvaluecolumns (will be interpolated)
- method
The correction method to apply:
"subtract"(default): Subtract the blank from each spectrum"divide": Divide each spectrum by the blank
- measures
An optional character vector of measure column names to process. If
NULL(the default), all measure columns (columns with classmeasure_list) will be processed.- role
Not used by this step since no new variables are created.
- trained
A logical to indicate if the quantities for preprocessing have been estimated.
- learned_ref
A named list containing the validated reference values for each measure column. This is
NULLuntil the step is trained.- skip
A logical. Should the step be skipped when the recipe is baked?
- id
A character string that is unique to this step to identify it.
Details
This step applies a simple reference correction to each spectrum:
method = "subtract":result = sample - referencemethod = "divide":result = sample / reference
Unlike step_measure_subtract_blank(), this step always requires an
externally provided reference and does not support learning from training
data.
See also
step_measure_subtract_blank() for blank correction with learning
Other measure-preprocessing:
step_measure_absorbance(),
step_measure_calibrate_x(),
step_measure_calibrate_y(),
step_measure_derivative(),
step_measure_derivative_gap(),
step_measure_emsc(),
step_measure_kubelka_munk(),
step_measure_log(),
step_measure_map(),
step_measure_msc(),
step_measure_normalize_istd(),
step_measure_osc(),
step_measure_ratio_reference(),
step_measure_snv(),
step_measure_subtract_blank(),
step_measure_transmittance()
Examples
library(recipes)
# Create a reference spectrum
ref_spectrum <- rep(1.0, 100)
rec <- recipe(water + fat + protein ~ ., data = meats_long) |>
update_role(id, new_role = "id") |>
step_measure_input_long(transmittance, location = vars(channel)) |>
step_measure_subtract_reference(reference = ref_spectrum, method = "divide")