step_measure_peaks_detect() creates a specification of a recipe step that
detects peaks in measurement data and stores them in a new .peaks column.
Arguments
- recipe
A recipe object.
- method
Peak detection method. One of
"prominence"(default) or"derivative".- min_height
Minimum peak height. If
snr_threshold = TRUE, this is interpreted as a signal-to-noise ratio threshold.- min_distance
Minimum distance between peaks in x-axis units.
- min_prominence
Minimum peak prominence (only for
method = "prominence").- snr_threshold
Logical. If
TRUE,min_heightis interpreted as a signal-to-noise ratio. Noise is estimated as the MAD of the signal.- 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.
Details
This step detects peaks in measurement data and creates a new .peaks
column containing the detected peaks for each sample. The original
.measures column is preserved.
Detection methods:
"prominence": Finds local maxima and calculates their prominence (how much a peak stands out from surrounding signal). More robust to noise."derivative": Finds peaks by detecting zero-crossings in the first derivative. Faster but more sensitive to noise.
Peak properties stored:
peak_id: Integer identifierlocation: X-axis position of peak apexheight: Y-value at peak apexleft_base,right_base: X-axis positions of peak boundariesarea: Initially NA; usestep_measure_peaks_integrate()to calculate
See also
Other peak-operations:
step_measure_peaks_filter(),
step_measure_peaks_integrate(),
step_measure_peaks_to_table()
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, min_distance = 5) |>
prep()
result <- bake(rec, new_data = NULL)
# Result now has .peaks column alongside .measures