Apply Savitzky-Golay filtering at variable combinations of parameter sets for set(s) of spectra.

sg_apply(
  X,
  dt_sg_plan,
  dt_prep_sets = NULL,
  nest_params = TRUE,
  append_rows = FALSE
)

Arguments

X

matrix, data.frame or data.table with spectra to be preprocessed according to plan (see dt_sg_plan).

dt_sg_plan

A standardized data.table with the Savitzky-Golay parameter sets, which can be generated with sg_plan(). It must at least contain the following columns:

  • prep_set (character)

  • prep_label (character)

  • m (integer): order of the derivative; m = 0 signifies no derivative

  • p (integer): polynomal order

  • w (integer): window size in number of spectral points; must be uneven m is the , p is the polynomial order that should be bigger than the derivative order, and w is the window size in number of spectral points (must be uneven). See section Savitzky-Golay Plan for templating the required object and prospectr::savitzkyGolay() for further the original Savitzky-Golay algorithm.

dt_prep_sets

A standardized data.table, i.e. returned from specprepper::*_apply() function. Contains labelled sets of preprocessed spectra: This argument allows to chain preprocessing in sequential manner, and i.e. apply variable Savitzky-Golay smoothers with a single function application.

nest_params

logical whether to nest the Savitzky-Golay parameters in a prep_params list-column.

append_rows

logical whether to append the newly processed rows, when dt_prep_sets is not NULL.

Value

data.table with the following (list)columns:by #to be filled

Details

Design principles

Savitzky-Golay transformation (moving window polynomial least-squares) prior modeling can help to reduce noise and enhance signals in spectra. This can allowing models to extract parsimonious predictable information from spectra for more accurate estimation. However, this process requires empirical optimization and fine-tuning of the parameters that control the nature and degree of smoothing and hence noise removal for calibration task at hand, which is often not done. For example, systematically varying the size of the smoothing window control the amount of information filtered and potential artefacts created. Nonetheless, non-stationary noise as opposed to white gaussian noise and informative fluctuations in chemically-driven spectral dynamics (e.g. slope changes and different absorption peak widths and compositional complexity) can make a simple nonrecursive application of the original Savitzky-Golay algorithm less appropriate to filter noise.

Templating code for sequential and/or recursive branching of preprocessing methods with variation their parameters, if applicable, can be repetitive and cumbersome. This is where the specprep package with combinatory planning and application tools jumps in.

The combinatory power of the sg_apply() function stems from the ability to map Savitzly Golay both over row-wise sets of parametrizations (see subsection Savitzky-Golay Plan) and previous preprocessing rounds that yielded set(s) of (differently) processed spectra to be processed again (see section Set(s) of Previously Processed Spectra). Since data.tables are structured consistently across the specprep::*_apply type of functions, their inputs and outputs are interoperable. This allows flexiblity for applying combinations of preprocessing methods.

Savitzky-Golay Plan

dt_sg_plan is most conventiently built with sg_plan(). It parametrizes Savitzky-Golay preprocessing scheduled on either X or on all sets of already processed spectra contained in dt_prep_sets. Each row lays out one preprocessing step, linking the following data across columns:

  • prep_set: this string identifies the name of general preprocessing method that is chained to sets of spectra.

Set(s) of Previously Processed Spectra

tbd

Author

Philipp Baumann