step_measure_ratio_reference() creates a specification of a recipe step
that computes the ratio of each spectrum to a reference, optionally with
blank subtraction.
Usage
step_measure_ratio_reference(
recipe,
reference,
blank = NULL,
measures = NULL,
role = NA,
trained = FALSE,
learned_ref = NULL,
learned_blank = NULL,
skip = FALSE,
id = recipes::rand_id("measure_ratio_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)
- blank
An optional blank spectrum to subtract from both sample and reference before computing the ratio. Same format options as
reference.- 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.- learned_blank
A named list containing the learned blank 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 computes a ratio relative to a reference spectrum:
Without blank:
result = sample / referenceWith blank:
result = (sample - blank) / (reference - blank)
This is useful for computing relative measurements, such as absorbance from transmittance when you have both sample and reference scans.
See also
step_measure_subtract_blank() for simple blank subtraction
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_snv(),
step_measure_subtract_blank(),
step_measure_subtract_reference(),
step_measure_transmittance()
Examples
library(recipes)
# Create reference and blank spectra
ref_spectrum <- rep(1.0, 100)
blank_spectrum <- rep(0.05, 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_ratio_reference(
reference = ref_spectrum,
blank = blank_spectrum
)