Skip to contents

step_measure_kubelka_munk() creates a specification of a recipe step that applies the Kubelka-Munk transformation for diffuse reflectance data.

Usage

step_measure_kubelka_munk(
  recipe,
  measures = NULL,
  role = NA,
  trained = FALSE,
  skip = FALSE,
  id = recipes::rand_id("measure_kubelka_munk")
)

Arguments

recipe

A recipe object. The step will be added to the sequence of operations for this recipe.

measures

An optional character vector of measure column names to process. If NULL (the default), all measure columns will be processed.

role

Not used by this step since no new variables are created.

trained

A logical to indicate if the step has been trained.

skip

A logical. Should the step be skipped when baking?

id

A character string that is unique to this step.

Value

An updated version of recipe with the new step added.

Details

The Kubelka-Munk transformation is used for diffuse reflectance spectroscopy to convert reflectance to a quantity proportional to concentration:

$$f(R) = \frac{(1-R)^2}{2R}$$

where \(R\) is the reflectance (0 to 1).

Important: Reflectance values should be in the range (0, 1). Values at the boundaries will produce extreme values or Inf.

This transformation is commonly used in:

  • NIR diffuse reflectance spectroscopy

  • Analysis of powders and solid samples

  • When Beer-Lambert law doesn't apply directly

The measurement locations are preserved unchanged.

Examples

library(recipes)

# Assuming reflectance data in (0, 1) range
# Note: meats_long has transmittance, this is illustrative
rec <- recipe(water + fat + protein ~ ., data = meats_long) |>
  update_role(id, new_role = "id") |>
  step_measure_input_long(transmittance, location = vars(channel)) |>
  step_measure_kubelka_munk()