step_measure_baseline_snip() creates a specification of a recipe step
that applies SNIP (Statistics-sensitive Non-linear Iterative Peak-clipping)
baseline correction.
Usage
step_measure_baseline_snip(
recipe,
measures = NULL,
iterations = 40L,
decreasing = TRUE,
role = NA,
trained = FALSE,
skip = FALSE,
id = recipes::rand_id("measure_baseline_snip")
)Arguments
- recipe
A recipe object.
- measures
An optional character vector of measure column names.
- iterations
Number of clipping iterations. More iterations produce lower baselines. Default is 40.
- decreasing
Logical. If
TRUE(default), iterations decrease fromiterationsto 1. IfFALSE, uses fixed window size.- 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
SNIP is a robust baseline estimation algorithm originally developed for gamma-ray spectroscopy. It works by iteratively replacing each point with the minimum of itself and the average of its neighbors at increasing distances.
The algorithm is particularly effective for:
Spectra with sharp peaks on slowly varying baseline
X-ray fluorescence and diffraction
Mass spectrometry
References
Ryan, C.G., et al. (1988). SNIP, a statistics-sensitive background treatment for the quantitative analysis of PIXE spectra in geoscience applications. Nuclear Instruments and Methods in Physics Research B, 34, 396-402.
See also
Other measure-baseline:
step_measure_baseline_airpls(),
step_measure_baseline_als(),
step_measure_baseline_arpls(),
step_measure_baseline_auto(),
step_measure_baseline_custom(),
step_measure_baseline_gpc(),
step_measure_baseline_minima(),
step_measure_baseline_morph(),
step_measure_baseline_poly(),
step_measure_baseline_py(),
step_measure_baseline_rf(),
step_measure_baseline_rolling(),
step_measure_baseline_tophat(),
step_measure_detrend()
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_baseline_snip(iterations = 30) |>
prep()
bake(rec, new_data = NULL)
#> # A tibble: 215 × 5
#> id water fat protein .measures
#> <int> <dbl> <dbl> <dbl> <meas>
#> 1 1 60.5 22.5 16.7 [100 × 2]
#> 2 2 46 40.1 13.5 [100 × 2]
#> 3 3 71 8.4 20.5 [100 × 2]
#> 4 4 72.8 5.9 20.7 [100 × 2]
#> 5 5 58.3 25.5 15.5 [100 × 2]
#> 6 6 44 42.7 13.7 [100 × 2]
#> 7 7 44 42.7 13.7 [100 × 2]
#> 8 8 69.3 10.6 19.3 [100 × 2]
#> 9 9 61.4 19.9 17.7 [100 × 2]
#> 10 10 61.4 19.9 17.7 [100 × 2]
#> # ℹ 205 more rows