This function performs multiplicative scatter/signal correction (MSC) on an input data of spectra. It corrects for multiplicative and additive effects in the spectral data by regressing against a reference spectrum.
Arguments
- x
A numeric matrix or data frame containing the input spectra. Each row represents a sample, and each column represents a spectral variable.
- xref
An optional numeric vector representing the reference spectrum. If
NULL(default), the mean or median ofxis used as the reference.- drop.offset
A logical value indicating whether the additive offset \(a_i\) should be removed from the spectra (default is
TRUE). IfFALSE, only the multiplicative effect is corrected: \(\textbf{x}_i / b_i\).- robust
A logical value indicating whether the median (
TRUE, default) or the mean (FALSE) ofxis used asxref.- window
An optional list of numeric vectors specifying the column indices of spectral windows. If provided, MSC is performed separately for each window.
- drop.na
A logical value indicating whether to remove spectra (rows) containing missing values. If
TRUE(the default), such rows are removed.
Value
A list with the following components:
correctionThe corrected spectra.
offsetThe intercepts/offsets \(a_i\) (a matrix with one column per window when
windowis given).slopeThe multiplicative scatter factors/slopes \(b_i\) (a matrix with one column per window when
windowis given).referenceThe reference spectrum used.
Details
Each spectrum \(\textbf{x}_i\) is regressed against the reference spectrum,
\(\textbf{x}_i = a_i + b_i \textbf{x}_{ref} + \textbf{e}_i\), and corrected as
\((\textbf{x}_i - a_i) / b_i\). When window is given, the regression and
correction are carried out separately in each spectral window (piecewise MSC);
variables outside all windows are left unchanged.
To correct new spectra consistently, pass the returned reference as xref.
Examples
data(forageLIBS)
spectra <- forageLIBS[-(1:14)] # the spectral channels
res <- msc(spectra)
res$correction[1:3, 1:4]
#> # A tibble: 3 × 4
#> `199.3771616` `199.4644141` `199.5516666` `199.6389192`
#> <dbl> <dbl> <dbl> <dbl>
#> 1 698. 709. 755. 708.
#> 2 664. 686. 716. 658.
#> 3 632. 650. 696. 650.
