Skip to contents

step_measure_peaks_integrate() creates a specification of a recipe step that calculates the area under each detected peak.

Usage

step_measure_peaks_integrate(
  recipe,
  method = c("trapezoid", "simpson"),
  baseline = c("local", "none", "global"),
  measures = NULL,
  role = NA,
  trained = FALSE,
  skip = FALSE,
  id = recipes::rand_id("measure_peaks_integrate")
)

Arguments

recipe

A recipe object.

method

Integration method. One of "trapezoid" (default) or "simpson".

baseline

Baseline handling. One of "local" (linear interpolation between peak bases), "none" (integrate to zero), or "global" (use minimum value as baseline).

measures

Optional character vector of measure column names.

role

Not used.

trained

Logical indicating if the step has been trained.

skip

Logical. Should the step be skipped when baking?

id

Unique step identifier.

Value

An updated recipe with the new step added.

Details

This step calculates the area under each peak detected by step_measure_peaks_detect(). The areas are stored in the area column of the .peaks tibble.

Integration methods:

  • "trapezoid": Trapezoidal rule integration. Fast and accurate for well-resolved peaks.

  • "simpson": Simpson's rule integration. More accurate for smooth curves but requires odd number of points.

Baseline handling:

  • "local": Subtracts a linear baseline connecting the left and right peak bases before integration.

  • "none": Integrates directly to y=0.

  • "global": Subtracts the minimum value in the peak region.

For prominence-based detection, left_base and right_base are clipped to the lowest sampled value between adjacent retained peaks. Ties use the first sample in acquisition order. Only retained peaks define these bounds: an adjacent peak removed by a detection threshold does not split the interval. Consequently a bound can remain wide or include baseline/noise, and baseline = "none" retains any background signal within the interval. Deconvolution uses current left_base and right_base as finite limits, so fitted areas omit model tails outside them.

Peaks with fitted model metadata from step_measure_peaks_deconvolve() are integrated from their individual fitted component over the finite bounds stored in left_base and right_base. The method and baseline settings apply only to observed-signal integration. The area_basis column records whether each area came from the fitted component or the observed signal.

Examples

library(recipes)

rec <- recipe(water + fat + protein ~ ., data = meats_long) |>
  update_role(id, new_role = "id") |>
  step_measure_input_long(transmittance, location = vars(channel)) |>
  step_measure_peaks_detect(min_height = 0.5) |>
  step_measure_peaks_integrate() |>
  prep()

result <- bake(rec, new_data = NULL)