Creates a preprocessing constructor for detrending spectral data. The
constructor is intended to be passed to preprocess_recipe and
executed via process.
Value
An object of class preprocessing to be used in
preprocess_recipe and executed by process.
Details
For each spectrum, a polynomial of order p is fitted using the
column wavelengths as the explanatory variable (or integer indices if column
names are not numeric). The residuals from this fit are returned as the
detrended spectrum, removing wavelength-dependent baseline effects.
This constructor always performs pure polynomial detrending without a prior
SNV transformation. Users who want the full Barnes et al. (1989) procedure
(SNV followed by detrending) should chain prep_snv before
prep_detrend in their recipe.
The computation is delegated to detrend with
snv = FALSE.
References
Barnes RJ, Dhanoa MS, Lister SJ. 1989. Standard normal variate transformation and de-trending of near-infrared diffuse reflectance spectra. Applied Spectroscopy, 43(5): 772-777.
Examples
data("NIRcannabis")
X <- NIRcannabis$spc
# Pure polynomial detrend
dt <- prep_detrend(p = 2)
recipe <- preprocess_recipe(dt, device = "unspecified")
X_dt <- process(X, recipe)
# Barnes et al. (1989): SNV followed by detrend
recipe_barnes <- preprocess_recipe(
prep_snv(), prep_detrend(p = 2),
device = "unspecified"
)
X_barnes <- process(X, recipe_barnes)
