Skip to contents

step_measure_baseline_airpls() creates a specification of a recipe step that applies airPLS baseline correction. This method automatically adjusts weights based on the difference between the signal and fitted baseline.

Usage

step_measure_baseline_airpls(
  recipe,
  measures = NULL,
  lambda = 1e+05,
  max_iter = 50L,
  tol = 0.001,
  role = NA,
  trained = FALSE,
  skip = FALSE,
  id = recipes::rand_id("measure_baseline_airpls")
)

Arguments

recipe

A recipe object.

measures

An optional character vector of measure column names.

lambda

Smoothness parameter. Higher values produce smoother baselines. Default is 1e5. Tunable via baseline_lambda().

max_iter

Maximum number of iterations. Default is 50.

tol

Convergence tolerance for weight changes. Default is 1e-3.

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

airPLS (Adaptive Iteratively Reweighted Penalized Least Squares) is an improvement over standard ALS that automatically adapts the asymmetry parameter based on the residuals. Key features:

  • No need to manually set asymmetry parameter

  • Good for signals with varying baseline curvature

  • Robust to different peak heights

References

Zhang, Z.M., Chen, S., & Liang, Y.Z. (2010). Baseline correction using adaptive iteratively reweighted penalized least squares. Analyst, 135, 1138-1146.

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_airpls(lambda = 1e5) |>
  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