Title: | Extended Multiplicative Signal Correction |
---|---|
Description: | Background correction of spectral like data. Handles variations in scaling, polynomial baselines, interferents, constituents and replicate variation. Parameters for corrections are stored for further analysis, and spectra are corrected accordingly. |
Authors: | Kristian Hovde Liland [aut, cre] , Ulf Geir Indahl [ctb] |
Maintainer: | Kristian Hovde Liland <[email protected]> |
License: | GPL-2 |
Version: | 0.9.4 |
Built: | 2025-01-05 03:46:58 UTC |
Source: | https://github.com/khliland/emsc |
Performs model-based background correction and normalisation of spectra. EMSC handles variations in scaling, polynomial baselines and interferents. Parameters for corrections are stored for further analysis, and spectra are corrected accordingly.
EMSC(X, model = NULL, ...)
EMSC(X, model = NULL, ...)
X |
|
model |
an EMSC model to use instead of the other parameters. |
... |
named model parameters for EMSC_model. |
This is the main EMSC function performing all calculations. It can be run with
no parameters (defaults are used), with a predefined EMSC model object or with
parameters that are passed on to the EMSC model building function EMSC_model
.
An object of class EMSC is returned. This contains:
corrected
: matrix
of corrected spectra.
parameters
: matrix
of fitted parameter values.
model
: object containing input all input parameters.
X
: original data.
H. Martens, E. Stark, Extended multiplicative signal correction and spectral interference subtraction: new preprocessing methods for near infrared spectroscopy. J Pharm Biomed Anal. 1991; 9(8):625-35.
Joakim Skogholt, Kristian Hovde Liland, Ulf Geir Indahl, Pre-processing of spectral data in the extended multiplicative signal correction framework using multiple reference spectra Journal of Raman Spectroscopy 50(3), (2019), pp. 407-417.
EMSC_model
predict.EMSC
plot.EMSC
data(fishoil) Raman <- fishoil$Raman[, 850:3300] EMSC.basic <- EMSC(Raman) EMSC.poly6 <- EMSC(Raman, degree = 6) EMSC.rep <- EMSC(Raman, degree = 6, reference = Raman[30, ], replicates = fishoil$replicates) old.par <- par(mfrow = c(2,2), mar = c(4,4,1,1)) xlim <- rev(as.numeric(range(colnames(Raman)))) matplot(colnames(Raman), t(Raman), type = 'l', xlim = xlim, ylab = 'Relative intensity', xlab = 'Raw spectra') matplot(colnames(Raman), t(EMSC.basic$corrected), type = 'l', xlim = xlim, ylab = 'Relative intensity', xlab = 'Corrected (basic)') matplot(colnames(Raman), t(EMSC.poly6$corrected), type = 'l', xlim = xlim, ylab = 'Relative intensity', xlab = 'Corrected (6th degree polynomial)') matplot(colnames(Raman), t(EMSC.rep$corrected), type = 'l', xlim = xlim, ylab = 'Relative intensity', xlab = 'Corrected (reference = spec. #30, replicate correction (90%))') par(old.par)
data(fishoil) Raman <- fishoil$Raman[, 850:3300] EMSC.basic <- EMSC(Raman) EMSC.poly6 <- EMSC(Raman, degree = 6) EMSC.rep <- EMSC(Raman, degree = 6, reference = Raman[30, ], replicates = fishoil$replicates) old.par <- par(mfrow = c(2,2), mar = c(4,4,1,1)) xlim <- rev(as.numeric(range(colnames(Raman)))) matplot(colnames(Raman), t(Raman), type = 'l', xlim = xlim, ylab = 'Relative intensity', xlab = 'Raw spectra') matplot(colnames(Raman), t(EMSC.basic$corrected), type = 'l', xlim = xlim, ylab = 'Relative intensity', xlab = 'Corrected (basic)') matplot(colnames(Raman), t(EMSC.poly6$corrected), type = 'l', xlim = xlim, ylab = 'Relative intensity', xlab = 'Corrected (6th degree polynomial)') matplot(colnames(Raman), t(EMSC.rep$corrected), type = 'l', xlim = xlim, ylab = 'Relative intensity', xlab = 'Corrected (reference = spec. #30, replicate correction (90%))') par(old.par)
Sets up an EMSC model to be applied to one or more set of spectra.
EMSC_model( x, reference = NA, degree = 2, interferent = NULL, constituent = NULL, weights = NULL, replicates = NULL, rep_corr = 0.9 )
EMSC_model( x, reference = NA, degree = 2, interferent = NULL, constituent = NULL, weights = NULL, replicates = NULL, rep_corr = 0.9 )
x |
|
reference |
|
degree |
|
interferent |
|
constituent |
|
weights |
|
replicates |
optional |
rep_corr |
proportion of variance or number of subspace components in replicate space (default = 0.9). |
An EMSC model is returned containing all parameters.
42 fish oil samples with 3 replicates each constitute a Raman data set of 126 samples over 3471 Raman shifts. There is a large fluorescence signal in the spectra that needs to be removed before any data analysis can be performed.
data(fishoil)
data(fishoil)
A data.frame
consisting of three parts. The estimated Iodine concentrations
of the fish oil samples, Raman spectra (matrix
) and a replicate vector.
K.H. Liland, A. Kohler, N.K. Afseth. Model-based pre-processing in Raman spectroscopy of biological samples. Journal of Raman Spectroscopy (2016).
42 milk (should be fish oil) samples with 3 replicates each constitute a Raman data set of 126 samples over 3471 Raman shifts. There is a large fluorescence signal in the spectra that needs to be removed before any data analysis can be performed.
data(milk)
data(milk)
A data.frame
consisting of three parts. The estimated Iodine concentrations
of the milk samples, Raman spectra (matrix
) and a replicate vector.
K.H. Liland, A. Kohler, N.K. Afseth. Model-based pre-processing in Raman spectroscopy of biological samples. Journal of Raman Spectroscopy (2016).
Create orthogonal set of vectors that resemble the original input vectors.
orthogonalVectors(X, dim = 1, re = TRUE)
orthogonalVectors(X, dim = 1, re = TRUE)
X |
a |
dim |
an integer specifying which dimension is the object dimension. |
re |
a logical indicating if vectors should be norm-scaled before orthogonalization and rescaled afterwards (default = TRUE). |
The input vectors are orthgonalized using singular value decomposition. To make the resulting vectors similar to the input vectors (not just any base for the same space) they are re-oriented towards the original vectors using Procrustes rotations.
To force the procedure to handle vectors of unequal magnitudes similarilly
they are by default rescaled to norm vectors before orthogonalization and
rescaled afterwards. This can be overridden using the re
paramter.
Plotting routine for EMSC
ojects. The default behaviour is to
plot raw spectra, reference spectrum, polynomials, interferents,
constituents, replicate model and corrected spectra. This can be
tweaked by changing the parameters.
## S3 method for class 'EMSC' plot( x, y, spec = "all", what = c("raw", "reference", "polynomials", "interferents", "constituents", "replicates", "corrected"), where = c(1, 1, 2, 3, 3, 4, 5), revX = FALSE, labels, type, lty, lwd = NULL, pch, cex = NULL, col, xlab, ylab, pretty.xlabels = TRUE, xlim, ... ) ## S3 method for class 'EMSC' print(x, ...) ## S3 method for class 'EMSC' summary(object, ...)
## S3 method for class 'EMSC' plot( x, y, spec = "all", what = c("raw", "reference", "polynomials", "interferents", "constituents", "replicates", "corrected"), where = c(1, 1, 2, 3, 3, 4, 5), revX = FALSE, labels, type, lty, lwd = NULL, pch, cex = NULL, col, xlab, ylab, pretty.xlabels = TRUE, xlim, ... ) ## S3 method for class 'EMSC' print(x, ...) ## S3 method for class 'EMSC' summary(object, ...)
x |
An object fitted by the |
y |
Unused parameter to conform to generic |
spec |
Parameter specifying if all spectra should be plotted (default)
or a subset ( |
what |
|
where |
|
revX |
Reverse x axis (default = FALSE). |
labels |
"names" or "numbers" uses column names for x axis labelling. |
type |
plotting type (line, points, ...). |
lty |
line type. |
lwd |
line width. |
pch |
plot character. |
cex |
symbol/line scaling. |
col |
symbol/line colour. |
xlab |
x label. |
ylab |
y label. |
pretty.xlabels |
Use pretty x labels (default = TRUE). |
xlim |
x limits. |
... |
Additional arguments to |
object |
An object fitted by the |
The parameters what
and where
must match
so that the parts of the EMSC model end up in the correct subplot.
There are limits to the freedom of this function.
print
and summary
return minimal information on the
EMSC object.
No return.
Kristian Hovde Liland
data(fishoil, package = "EMSC") Raman <- fishoil$Raman[, 850:3300] EMSC.rep <- EMSC(Raman, degree = 6, reference = Raman[30, ], replicates = fishoil$replicates) plot(EMSC.rep)
data(fishoil, package = "EMSC") Raman <- fishoil$Raman[, 850:3300] EMSC.rep <- EMSC(Raman, degree = 6, reference = Raman[30, ], replicates = fishoil$replicates) plot(EMSC.rep)
Prediction for EMSC
ojects. Corrections are calculated for the new
matrix
based on the EMSC model used in the input object.
## S3 method for class 'EMSC' predict(object, newdata = NULL, ...)
## S3 method for class 'EMSC' predict(object, newdata = NULL, ...)
object |
An object fitted by the |
newdata |
A |
... |
unused. |
data(fishoil) Raman.cal <- fishoil$Raman[ 1:90, 850:3300] Raman.val <- fishoil$Raman[-(1:90), 850:3300] EMSC.cal <- EMSC(Raman.cal) EMSC.val <- predict(EMSC.cal, Raman.val) identical(EMSC.cal$model, EMSC.val$model) # Same model, reference spectrum, etc. matplot(t(EMSC.cal$corrected), type = 'l', col = 'black', lty = 1, ylab = 'Intensity') matplot(t(EMSC.val$corrected), type = 'l', col = 'red', lty = 2, add = TRUE) legend('topleft', legend = c('Calibration','Validation'), lty = 1:2, col = 1:2)
data(fishoil) Raman.cal <- fishoil$Raman[ 1:90, 850:3300] Raman.val <- fishoil$Raman[-(1:90), 850:3300] EMSC.cal <- EMSC(Raman.cal) EMSC.val <- predict(EMSC.cal, Raman.val) identical(EMSC.cal$model, EMSC.val$model) # Same model, reference spectrum, etc. matplot(t(EMSC.cal$corrected), type = 'l', col = 'black', lty = 1, ylab = 'Intensity') matplot(t(EMSC.val$corrected), type = 'l', col = 'red', lty = 2, add = TRUE) legend('topleft', legend = c('Calibration','Validation'), lty = 1:2, col = 1:2)
Savitzky-Golay filtering and derivatives
SavitzkyGolay( X, poly = 3, width = 11, deriv = 2, ends = c("cut", "extrapolate", "zeros") )
SavitzkyGolay( X, poly = 3, width = 11, deriv = 2, ends = c("cut", "extrapolate", "zeros") )
X |
|
poly |
Polynomial degree of smoother. |
width |
Window width of smoother, default = 11, must be an odd number. |
deriv |
Derivative degree, can be 0, default = 2. |
ends |
Handling of spectrum ends, i.e. first and last (width-1)/2 points. Default is "cut", i.e. remove ends, "extrapolate" copies the first/last estimable point, while "zeros" is included for backward compatilibity (fill with 0). |
A matrix of filtered spectra (possibly with derivatives)
data(fishoil) Raman <- fishoil$Raman[, 850:3300] SavGol <- SavitzkyGolay(Raman) old.par <- par(mfrow = c(2,1), mar = c(4,4,1,1)) matplot(colnames(Raman), t(Raman), type = 'l', ylab = 'Relative intensity', xlab = 'Raw spectra') matplot(colnames(SavGol), t(SavGol), type = 'l', ylab = 'Relative intensity', xlab = 'Smoothed 2nd derivative') par(old.par)
data(fishoil) Raman <- fishoil$Raman[, 850:3300] SavGol <- SavitzkyGolay(Raman) old.par <- par(mfrow = c(2,1), mar = c(4,4,1,1)) matplot(colnames(Raman), t(Raman), type = 'l', ylab = 'Relative intensity', xlab = 'Raw spectra') matplot(colnames(SavGol), t(SavGol), type = 'l', ylab = 'Relative intensity', xlab = 'Smoothed 2nd derivative') par(old.par)