| prep_smooth | R Documentation |
Creates a preprocessing constructor for smoothing spectral data. The
constructor is intended to be passed to preprocess_recipe and
executed via process.
Two algorithms are supported: Savitzky-Golay ("savitzky-golay") and
moving average ("moving-average").
prep_smooth(w, p = NULL, algorithm = c("savitzky-golay", "moving-average"))
w |
A positive odd integer specifying the filter window size. |
p |
An integer specifying the polynomial order. Required when
|
algorithm |
A character string specifying the smoothing algorithm. One
of |
Savitzky-Golay ("savitzky-golay"): fits a polynomial of
order p within a moving window of size w and returns the
zero-order coefficient (i.e. the smoothed value). Implemented via
savitzkyGolay with m = 0.
Moving average ("moving-average"): computes a simple moving
average of window size w using movav.
Edge values are handled using progressively narrower windows so the output
has the same number of columns as the input. This reproduces the "Smooth"
pre-treatment from BUCHI NIRWise PLUS.
For "moving-average", the NIRWise PLUS half-window convention is:
\mjdeqnhalf_w = (w - 1) / 2half_w = (w - 1) / 2
stored internally for device file serialization and not user-facing.
An object of class preprocessing to be used in
preprocess_recipe and executed by process.
The object is a list containing the method name and all parameters. For
algorithm = "moving-average", the NIRWise PLUS half-window value
(half_w) is also stored for device file serialization.
Leonardo Ramirez-Lopez and Claudio Orellano
preprocess_recipe, process
data("proximateCannabis")
X <- proximateCannabis$spc
# Savitzky-Golay smoothing, window 11, polynomial order 3
sg <- prep_smooth(w = 11, p = 3, algorithm = "savitzky-golay")
# Moving average smoothing, window 7
ma <- prep_smooth(w = 7, algorithm = "moving-average")
# Apply via preprocess_recipe
recipe <- preprocess_recipe(sg, device = "proxiscout")
X_smooth <- process(X, recipe)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.