Title: | Baseline Correction of Spectra |
---|---|
Description: | Collection of baseline correction algorithms, along with a framework and a Tcl/Tk enabled GUI for optimising baseline algorithm parameters. Typical use of the package is for removing background effects from spectra originating from various types of spectroscopy and spectrometry, possibly optimizing this with regard to regression or classification results. Correction methods include polynomial fitting, weighted local smoothers and many more. |
Authors: | Kristian Hovde Liland [aut, cre] , Bjørn-Helge Mevik [aut], Roberto Canteri [ctb] |
Maintainer: | Kristian Hovde Liland <[email protected]> |
License: | GPL-2 |
Version: | 1.3-5 |
Built: | 2024-11-22 04:06:30 UTC |
Source: | https://github.com/khliland/baseline |
A common framework with implementations of several baseline correction methods
Use function baseline for baseline correction. This function takes matrices of spectra, a method name and parameters needed for the specific method. See helpfiles for details.
Kristian Hovde Liland and Bjørn-Helge Mevik
Maintainer: Kristian Hovde Liland <[email protected]>
Andreas F. Ruckstuhl, Matthew P. Jacobson, Robert W. Field, James A. Dodd: Baseline subtraction using robust local regression estimation; CHAD A. LIEBER and ANITA MAHADEVAN-JANSEN: Automated Method for Subtraction of Fluorescence from Biological Raman Spectra; Mark S. Friedrichs: A model-free algorithm for the removal of baseline artifacts; AHMET K. ATAKAN, W. E. BLASS, and D. E. JENNINGS: Elimination of Baseline Variations from a Recorded Spectrum by Ultra-low Frequency Filtering; M.A. Kneen, H.J. Annegarn: Algorithm for fitting XRF, SEM and PIXE X-ray spectra backgrounds; K.H. Liland, B.-H. Mevik, E.-O. Rukke, T. Almøy, M. Skaugen and T. Isaksson (2009) Quantitative whole spectrum analysis with MALDI-TOF MS, Part I: Measurement optimisation. Chemometrics and Intelligent Laboratory Systems, 96(2), 210–218.
# Load data data(milk) # The baseline() function is an S4 wrapper for all the different # baseline correction methods. The default correction method # is IRLS. Data must be organized as row vectors in a matrix # or data.frame. bc.irls <- baseline(milk$spectra[1,, drop=FALSE]) ## Not run: # Computationally heavy plot(bc.irls) ## End(Not run) # Available extractors are: # getBaseline(bc.irls) # getSpectra(bc.irls) # getCorrected(bc.irls) # getCall(bc.irls) # Correction methods and parameters can be specified through the wrapper. bc.fillPeaks <- baseline(milk$spectra[1,, drop=FALSE], lambda=6, hwi=50, it=10, int=2000, method='fillPeaks') ## Not run: # Computationally heavy plot(bc.fillPeaks) ## End(Not run) # If a suitable gWidgets2 implementation is installed, a # graphical user interface is available for interactive # parameter adaption. ## Not run: # Dependent on external software baselineGUI(milk$spectra) ## End(Not run)
# Load data data(milk) # The baseline() function is an S4 wrapper for all the different # baseline correction methods. The default correction method # is IRLS. Data must be organized as row vectors in a matrix # or data.frame. bc.irls <- baseline(milk$spectra[1,, drop=FALSE]) ## Not run: # Computationally heavy plot(bc.irls) ## End(Not run) # Available extractors are: # getBaseline(bc.irls) # getSpectra(bc.irls) # getCorrected(bc.irls) # getCall(bc.irls) # Correction methods and parameters can be specified through the wrapper. bc.fillPeaks <- baseline(milk$spectra[1,, drop=FALSE], lambda=6, hwi=50, it=10, int=2000, method='fillPeaks') ## Not run: # Computationally heavy plot(bc.fillPeaks) ## End(Not run) # If a suitable gWidgets2 implementation is installed, a # graphical user interface is available for interactive # parameter adaption. ## Not run: # Dependent on external software baselineGUI(milk$spectra) ## End(Not run)
Extraction methods specifically for objects of class baselineAlgTest
algorithm(object) extraArgs(object)
algorithm(object) extraArgs(object)
object |
Object of class |
The corresponding slot
Bjørn-Helge Mevik and Kristian Hovde Liland
Common framework for baseline correction
baseline(spectra, method = "irls", ...)
baseline(spectra, method = "irls", ...)
spectra |
Matrix with spectra in rows |
method |
Baseline correction method |
... |
Additional parameters, sent to the method |
Estimates baselines for the spectra
, using the algorithm named
in method
.
An object of class baseline
.
Kristian Hovde Liland and Bjørn-Helge Mevik
Kristian Hovde Liland, Trygve Almøy, Bjørn-Helge Mevik (2010), Optimal Choice of Baseline Correction for Multivariate Calibration of Spectra, Applied Spectroscopy 64, pp. 1007-1016.
The functions implementing the baseline algorithms:
baseline.als
, baseline.fillPeaks
,
baseline.irls
, baseline.lowpass
,
baseline.medianWindow
,
baseline.modpolyfit
,
baseline.peakDetection
,
baseline.rfbaseline
, baseline.rollingBall
,
baseline.shirley
, baseline.TAP
# Load data data(milk) # The baseline() function is an S4 wrapper for all the different # baseline correction methods. The default correction method # is IRLS. Data must be organized as row vectors in a matrix # or data.frame. bc.irls <- baseline(milk$spectra[1,, drop=FALSE]) ## Not run: # Computationally heavy plot(bc.irls) ## End(Not run) # Available extractors are: # getBaseline(bc.irls) # getSpectra(bc.irls) # getCorrected(bc.irls) # getCall(bc.irls) # Correction methods and parameters can be specified through the wrapper. bc.fillPeaks <- baseline(milk$spectra[1,, drop=FALSE], lambda=6, hwi=50, it=10, int=2000, method='fillPeaks') ## Not run: # Computationally heavy plot(bc.fillPeaks) ## End(Not run) # If a suitable gWidgets2 implementation is installed, a # graphical user interface is available for interactive # parameter adaption. ## Not run: # Dependent on external software baselineGUI(milk$spectra) ## End(Not run)
# Load data data(milk) # The baseline() function is an S4 wrapper for all the different # baseline correction methods. The default correction method # is IRLS. Data must be organized as row vectors in a matrix # or data.frame. bc.irls <- baseline(milk$spectra[1,, drop=FALSE]) ## Not run: # Computationally heavy plot(bc.irls) ## End(Not run) # Available extractors are: # getBaseline(bc.irls) # getSpectra(bc.irls) # getCorrected(bc.irls) # getCall(bc.irls) # Correction methods and parameters can be specified through the wrapper. bc.fillPeaks <- baseline(milk$spectra[1,, drop=FALSE], lambda=6, hwi=50, it=10, int=2000, method='fillPeaks') ## Not run: # Computationally heavy plot(bc.fillPeaks) ## End(Not run) # If a suitable gWidgets2 implementation is installed, a # graphical user interface is available for interactive # parameter adaption. ## Not run: # Dependent on external software baselineGUI(milk$spectra) ## End(Not run)
Stores the result of estimating baselines for one or more spectra.
The normal way to create objects is with the function
baseline
. Several baseline algorithms are available. See
baseline
for details. There is a plot method for the
class; see plot,baseline-method
.
baseline
:A matrix with the estimated baselines
corrected
:A matrix with the corrected spectra
spectra
:A matrix with the original spectra
call
:The call to baseline
signature(object = "baseline")
: Extract
the estimated baselines
signature(object = "baseline")
: Extract the
call to baseline
used to create the object
signature(object = "baseline")
: Extract
the corrected spectra
signature(object = "baseline")
: Extract the
original spectra
In a future versoion, one of the slots might be
removed from the class definition and calculated on the fly instead,
in order to save space. Therefore, do use the extractor
functions (getSpectra
, getBaseline
and
getCorrected
) instead of accessing the slots directly.
Bjørn-Helge Mevik and Kristian Hovde Liland
baseline
, getBaseline
,
getSpectra
, getCorrected
,
getCall
showClass("baseline")
showClass("baseline")
Baseline correction by 2nd derivative constrained weighted regression. Original algorithm proposed by Paul H. C. Eilers and Hans F.M. Boelens
baseline.als(spectra, lambda = 6, p = 0.05, maxit = 20)
baseline.als(spectra, lambda = 6, p = 0.05, maxit = 20)
spectra |
Matrix with spectra in rows |
lambda |
2nd derivative constraint |
p |
Weighting of positive residuals |
maxit |
Maximum number of iterations |
Iterative algorithm applying 2nd derivative constraints. Weights from previous
iteration is p
for positive residuals and 1-p
for negative residuals.
baseline |
Matrix of baselines corresponding to spectra |
corrected |
Matrix of baseline corrected spectra |
wgts |
Matrix of final regression weights |
Kristian Hovde Liland and Bjørn-Helge Mevik
Paul H. C. Eilers and Hans F.M. Boelens: Baseline Correction with Asymmetric Least Squares Smoothing
data(milk) bc.als <- baseline(milk$spectra[1,, drop=FALSE], lambda=10, method='als') ## Not run: plot(bc.als) ## End(Not run)
data(milk) bc.als <- baseline(milk$spectra[1,, drop=FALSE], lambda=10, method='als') ## Not run: plot(bc.als) ## End(Not run)
An iterative algorithm using suppression of baseline by means in local windows
baseline.fillPeaks(spectra, lambda, hwi, it, int)
baseline.fillPeaks(spectra, lambda, hwi, it, int)
spectra |
Matrix with spectra in rows |
lambda |
2nd derivative penalty for primary smoothing |
hwi |
Half width of local windows |
it |
Number of iterations in suppression loop |
int |
Number of buckets to divide spectra into |
In local windows of buckets the minimum of the mean and the previous iteration is chosen as the new baseline
baseline |
Matrix of baselines corresponding to spectra |
corrected |
Matrix of baseline corrected spectra |
Kristian Hovde Liland and Bjørn-Helge Mevik
Kristian Hovde Liland, 4S Peak Filling - baseline estimation by iterative mean suppression, MethodsX 2015
data(milk) bc.fillPeaks <- baseline(milk$spectra[1,, drop=FALSE], lambda=6, hwi=50, it=10, int=2000, method='fillPeaks') ## Not run: plot(bc.fillPeaks) ## End(Not run)
data(milk) bc.fillPeaks <- baseline(milk$spectra[1,, drop=FALSE], lambda=6, hwi=50, it=10, int=2000, method='fillPeaks') ## Not run: plot(bc.fillPeaks) ## End(Not run)
An algorithm with primary smoothing and repeated baseline suppressions and regressions with 2nd derivative constraint
baseline.irls(spectra, lambda1 = 5, lambda2 = 9, maxit = 200, wi = 0.05)
baseline.irls(spectra, lambda1 = 5, lambda2 = 9, maxit = 200, wi = 0.05)
spectra |
Matrix with spectra in rows |
lambda1 |
2nd derivative constraint for primary smoothing |
lambda2 |
2nd derivative constraint for secondary smoothing |
maxit |
Maximum number of iterations |
wi |
Weighting of positive residuals |
baseline |
Matrix of baselines corresponding to spectra |
corrected |
Matrix of baseline corrected spectra |
smoothed |
Matrix of primary smoothed spectra |
Kristian Hovde Liland and Bjørn-Helge Mevik
data(milk) bc.irls <- baseline(milk$spectra[1,, drop=FALSE], method='irls') ## Not run: plot(bc.irls) ## End(Not run)
data(milk) bc.irls <- baseline(milk$spectra[1,, drop=FALSE], method='irls') ## Not run: plot(bc.irls) ## End(Not run)
An algorithm for removing baselines based on Fast Fourier Transform filtering
baseline.lowpass(spectra, steep = 2, half = 5)
baseline.lowpass(spectra, steep = 2, half = 5)
spectra |
Matrix with spectra in rows |
steep |
Steepness of filter curve |
half |
Half-way point of filter curve |
Since the scale of the spectra will be different after filtering, baselines will not be returned by the algorithm
baseline |
Matrix of baselines corresponding to spectra |
corrected |
Matrix of baseline corrected spectra |
Kristian Hovde Liland and Bjørn-Helge Mevik
AHMET K. ATAKAN, W. E. BLASS, and D. E. JENNINGS: Elimination of Baseline Variations from a Recorded Spectrum by Ultra-low Frequency Filtering
data(milk) bc.lowpass <- baseline(milk$spectra[1,, drop=FALSE], method='lowpass') ## Not run: plot(bc.lowpass) ## End(Not run)
data(milk) bc.lowpass <- baseline(milk$spectra[1,, drop=FALSE], method='lowpass') ## Not run: plot(bc.lowpass) ## End(Not run)
An implementation and extention of Mark S. Friedrichs' model-free algorithm
baseline.medianWindow(spectra, hwm, hws, end)
baseline.medianWindow(spectra, hwm, hws, end)
spectra |
Matrix with spectra in rows |
hwm |
Window half width for local medians |
hws |
Window half width for local smoothing (optional) |
end |
Original endpoint handling (optional boolean) |
An algorithm finding medians in local windows and smoothing with gaussian weighting
baseline |
Matrix of baselines corresponding to spectra |
corrected |
Matrix of baseline corrected spectra |
Kristian Hovde Liland and Bjørn-Helge Mevik
Mark S. Friedrichs: A model-free algorithm for the removal of baseline artifacts
data(milk) bc.medianWindow <- baseline(milk$spectra[1,, drop=FALSE], hwm=300, method='medianWindow') ## Not run: plot(bc.medianWindow) ## End(Not run)
data(milk) bc.medianWindow <- baseline(milk$spectra[1,, drop=FALSE], hwm=300, method='medianWindow') ## Not run: plot(bc.medianWindow) ## End(Not run)
An implementation of CHAD A. LIEBER and ANITA MAHADEVAN-JANSENs algorithm for polynomial fiting
baseline.modpolyfit(spectra, t, degree = 4, tol = 0.001, rep = 100)
baseline.modpolyfit(spectra, t, degree = 4, tol = 0.001, rep = 100)
spectra |
Matrix with spectra in rows |
t |
Optional vector of spectrum abcissa |
degree |
Degree of polynomial |
tol |
Tolerance of difference between iterations |
rep |
Maximum number of iterations |
Polynomial fitting with baseline suppression relative to original spectrum
baseline |
Matrix of baselines corresponding to spectra |
corrected |
Matrix of baseline corrected spectra |
Kristian Hovde Liland and Bjørn-Helge Mevik
CHAD A. LIEBER and ANITA MAHADEVAN-JANSEN: Automated Method for Subtraction of Fluorescence from Biological Raman Spectra
data(milk) bc.modpolyfit <- baseline(milk$spectra[1,, drop=FALSE], method='modpolyfit', deg=6) ## Not run: plot(bc.modpolyfit) ## End(Not run)
data(milk) bc.modpolyfit <- baseline(milk$spectra[1,, drop=FALSE], method='modpolyfit', deg=6) ## Not run: plot(bc.modpolyfit) ## End(Not run)
A translation from Kevin R. Coombes et al.'s MATLAB code for detecting peaks and removing baselines
baseline.peakDetection(spectra, left, right, lwin, rwin, snminimum, mono=0, multiplier=5, left.right, lwin.rwin)
baseline.peakDetection(spectra, left, right, lwin, rwin, snminimum, mono=0, multiplier=5, left.right, lwin.rwin)
spectra |
Matrix with spectra in rows |
left |
Smallest window size for peak widths |
right |
Largest window size for peak widths |
lwin |
Smallest window size for minimums and medians in peak removed spectra |
rwin |
Largest window size for minimums and medians in peak removed spectra |
snminimum |
Minimum signal to noise ratio for accepting peaks |
mono |
Monotonically decreasing baseline if |
multiplier |
Internal window size multiplier |
left.right |
Sets eflt and right to value of |
lwin.rwin |
Sets lwin and rwin to value of |
Peak detection is done in several steps sorting out real peaks through different criteria.
Peaks are removed from spectra and minimums and medians are used to smooth the remaining parts of the spectra.
If snminimum
is omitted, y3, midspec, y and y2 are not returned (faster)
baseline |
Matrix of baselines corresponding to spectra |
corrected |
Matrix of baseline corrected spectra |
peaks |
Final list of selected peaks |
sn |
List signal to noise ratios for peaks |
y3 |
List of peaks prior to singal to noise selection |
midspec |
Mid-way baseline estimation |
y |
First estimate of peaks |
y2 |
Second estimate of peaks |
Kristian Hovde Liland and Bjørn-Helge Mevik
KEVIN R. COOMBES et al.: Quality control and peak finding for proteomics data collected from nipple aspirate fluid by surface-enhanced laser desorption and ionization.
data(milk) bc.peakDetection <- baseline(milk$spectra[1,, drop=FALSE], method='peakDetection', left=300, right=300, lwin=50, rwin=50) ## Not run: plot(bc.peakDetection) ## End(Not run)
data(milk) bc.peakDetection <- baseline(milk$spectra[1,, drop=FALSE], method='peakDetection', left=300, right=300, lwin=50, rwin=50) ## Not run: plot(bc.peakDetection) ## End(Not run)
Wrapper for Andreas F. Ruckstuhl, Matthew P. Jacobson, Robert W. Field, James A. Dodd's algorithm based on LOWESS and weighted regression
baseline.rfbaseline(spectra, span = 2/3, NoXP = NULL, maxit = c(2, 2), b = 3.5, weight = NULL, Scale = function(r) median(abs(r))/0.6745, delta = NULL, SORT = FALSE, DOT = FALSE, init = NULL)
baseline.rfbaseline(spectra, span = 2/3, NoXP = NULL, maxit = c(2, 2), b = 3.5, weight = NULL, Scale = function(r) median(abs(r))/0.6745, delta = NULL, SORT = FALSE, DOT = FALSE, init = NULL)
spectra |
Matrix with spectra in rows |
span |
Amount of smoothing (by fraction of points) |
NoXP |
Amount of smoothing (by number of points) |
maxit |
Maximum number of iterations in robust fit |
b |
Tuning constant in the biweight function |
weight |
Optional weights to be given to individual observations |
Scale |
S function specifying how to calculate the scale of the residuals |
delta |
Nonnegative parameter which may be used to save computation. (See |
SORT |
Boolean variable indicating whether x data must be sorted. |
DOT |
Disregard outliers totally (boolean) |
init |
Values of initial fit |
Most of the code is the original code as given by the authors. The ability to sort by X-values has been removed and ability to handle multiple spectra has been added
baseline |
Matrix of baselines corresponding to spectra |
corrected |
Matrix of baseline corrected spectra |
Kristian Hovde Liland and Bjørn-Helge Mevik
Andreas F. Ruckstuhl, Matthew P. Jacobson, Robert W. Field, James A. Dodd: Baseline subtraction using robust local regression estimation
data(milk) bc.rbe <- baseline(milk$spectra[1,, drop=FALSE], method='rfbaseline', span=NULL, NoXP=1000) ## Not run: plot(bc.rbe) ## End(Not run)
data(milk) bc.rbe <- baseline(milk$spectra[1,, drop=FALSE], method='rfbaseline', span=NULL, NoXP=1000) ## Not run: plot(bc.rbe) ## End(Not run)
Ideas from Rolling Ball algorithm for X-ray spectra by M.A.Kneen and H.J. Annegarn. Variable window width has been left out
baseline.rollingBall(spectra, wm, ws)
baseline.rollingBall(spectra, wm, ws)
spectra |
Matrix with spectra in rows |
wm |
Width of local window for minimization/maximization |
ws |
Width of local window for smoothing |
baseline |
Matrix of baselines corresponding to spectra |
corrected |
Matrix of baseline corrected spectra |
Kristian Hovde Liland and Bjørn-Helge Mevik
M.A. Kneen, H.J. Annegarn: Algorithm for fitting XRF, SEM and PIXE X-ray spectra backgrounds
data(milk) bc.rollingBall <- baseline(milk$spectra[1,, drop=FALSE], wm=200, ws=200, method='rollingBall') ## Not run: plot(bc.rollingBall) ## End(Not run)
data(milk) bc.rollingBall <- baseline(milk$spectra[1,, drop=FALSE], wm=200, ws=200, method='rollingBall') ## Not run: plot(bc.rollingBall) ## End(Not run)
Shirley Background correction for X-ray Photoelectron Spectroscopy.
baseline.shirley(spectra, t = NULL, limits = NULL, maxit = 50, err = 1e-6)
baseline.shirley(spectra, t = NULL, limits = NULL, maxit = 50, err = 1e-6)
spectra |
matrix with only 1 y-coordinates by rows (i.e.: y = spectra[1,]) |
t |
Optional vector of spectrum abscissa |
limits |
list with the y coordinates between calculation of background. Ususally these are the extreme point of the data range. |
maxit |
max number of iteration |
err |
Tolerance of difference between iterations |
The shape of the spectrum background or baseline is affected by inelastic energy loss processes, secondary electrons and nearby peaks. A reasonable approximation is essential for a qualitative and quantitative analysis of XPS data especially if several components interfere in one spectrum. The choice of an adequate background model is determined by the physical and chemical conditions of the measurements and the significance of the background to the information to be obtained. The subtraction of the baseline before entering the fit iterations or the calculation of the peak area can be an acceptable approximation for simple analytical problems. In order to obtain chemical and physical parameters in detail, however, it is absolutely necessary to include the background function in the iterative peak fit procedure. The primary function F(E) results from the experimentally obtained function M(E) and the background function U(E) as
The kinetic energy E of the spectra can be described as
SE means the start energy in eV, SW is the step width in eV and i the channel number. i can assume values between 1 and N with N as the number of data points.
In case of baseline calculation before initiating the fit procedure, the background is set to the averaged experimental function M(E) in a sector around the chosen start and end channels. With as left channel (
: low energy side) and
as right channel (
: high energy side) the simulation of the baseline is obtained as
and
If ZAP is the number of points used for averaging (can be set in the preferences), the intensity of the averaged measuring function at the low energy side is calculated by
and at the high energy side by
In many cases the Shirley model turned out to be a successful approximation for the inelastic background of core level peaks of buried species, which suffered significantly from inelastic losses of the emitted photoelectrons. The calculation of the baseline is an iterative procedure. The number of iteration cycles should be chosen high enough so that the shape of the obtained background function does not change anymore. The analytical expression for the Shirley background is
The algorithm of Proctor and Sherwood ([1] A. Proctor, P.M.A. Sherwood, Anal. Chem. 54 (1982) 13) is based on the assumption that for every point of the spectrum the background intensity generated by a photoelectron line is proportional to the number of all photoelectrons with higher kinetic energy. The intensity of the background U(i) in channel i is given by
where a and b are the measured intensities in channel and
, respectively, and P(i) and Q(i) represent the effective peak areas to lower and higher kinetic energies relative to the channel under consideration. An iterative procedure is necessary because P, Q, and U(i) are unknown. In first approximation U(i) = b is used.
The function baseline.shirley
implements the shirley baseline
. It is an iterative algorithm.
The iteration stops when the deviation between two consequent iteration is
lower than err
or when the max number of iterations maxit
is
reached.
The baseline function return an object of class baseline
.
A. Proctor, P.M.A. Sherwood, Anal. Chem. 54 (1982) 13.
data("O1s") Data <- O1s ## The same example with C1s data # data("C1s") # Data <- C1s Y <- Data[2,, drop = FALSE] X <- Data[1,] corrected <- baseline(Y, method = "shirley", t = X) plot(corrected, rev.x = TRUE, labels = X) ## Not run: # Dependent on external software baselineGUI(Y, labels=X, method="shirley") ## End(Not run)
data("O1s") Data <- O1s ## The same example with C1s data # data("C1s") # Data <- C1s Y <- Data[2,, drop = FALSE] X <- Data[1,] corrected <- baseline(Y, method = "shirley", t = X) plot(corrected, rev.x = TRUE, labels = X) ## Not run: # Dependent on external software baselineGUI(Y, labels=X, method="shirley") ## End(Not run)
An implementation of Roman Svoboda and Jirí Málek's algorithm for baseline identification in kinetic anlaysis of derivative kinetic data.
baseline.TAP(spectra, t, interval = 15, tol = 0.001)
baseline.TAP(spectra, t, interval = 15, tol = 0.001)
spectra |
Matrix with spectra in rows |
t |
Optional vector of spectrum abcissa |
interval |
Distance from spectrum end to starting points for the TAP (default = 15) |
tol |
Tolerance of difference between iterations (default = 0.001) |
(i) A first approximation of the baseline equation is selected as the straight line between start and end of the curve. (ii) Based on the first approximation of the baseline equation, the phase change progress parameter is calculated. (iii) An updated equation of the baseline is calculated and the phase change progress parameter equation from step (ii). (iv) The baseline equation from step (iii) is compared (point by point) with the one from the previous iteration. If the convergence criterion is met (the difference between every baseline value corresponding to two successive iterations was less than 0.1%) the procedure is stopped and the final baseline equation is selected. If the convergence criterion is not fulfilled then a new iteration is carried out from step (ii) until convergence was achieved.
baseline |
Matrix of baselines corresponding to spectra |
corrected |
Matrix of baseline corrected spectra |
Kristian Hovde Liland
Roman Svoboda and Jirí Málek: Importance of proper baseline identification for the subsequent kinetic analysis of derivative kinetic data, Journal of Thermal Analysis and Calorimetry.
# My T myT <- 40:170 # My artifical curve myAlpha <- c(seq(0.01, 0.02, length.out=40), dnorm(seq(-3,3,length.out=51))/2+(0:50)/2000+0.02) myAlpha <- c(myAlpha, seq(myAlpha[90]-0.001, 0.01, length.out=40)) myAlpha <- myAlpha - min(myAlpha) myAlpha <- cumsum(dadt <- myAlpha/sum(myAlpha)) # Discrete derivative mydAlpha <- c(0,diff(myAlpha)); mydAlpha <- matrix(mydAlpha, ncol=length(mydAlpha)) rm(myAlpha) # Throw away myAlpha # Compute baseline from T and derivative B <- baseline(mydAlpha, t=myT, method="TAP") # Plot plot(B, xlab = "T", ylab = "da/dT")
# My T myT <- 40:170 # My artifical curve myAlpha <- c(seq(0.01, 0.02, length.out=40), dnorm(seq(-3,3,length.out=51))/2+(0:50)/2000+0.02) myAlpha <- c(myAlpha, seq(myAlpha[90]-0.001, 0.01, length.out=40)) myAlpha <- myAlpha - min(myAlpha) myAlpha <- cumsum(dadt <- myAlpha/sum(myAlpha)) # Discrete derivative mydAlpha <- c(0,diff(myAlpha)); mydAlpha <- matrix(mydAlpha, ncol=length(mydAlpha)) rm(myAlpha) # Throw away myAlpha # Compute baseline from T and derivative B <- baseline(mydAlpha, t=myT, method="TAP") # Plot plot(B, xlab = "T", ylab = "da/dT")
A class that describes a baseline correction algorithm. The idea is that it contains all information needed to use an algorithm with the optimisation framework and the graphical user interface (but see Notes below).
Objects can be created by calls of the form new("baselineAlg", ...)
.
name
:Short-name of the algorithm. This must match
the name of the object in the baselineAlgorithms
list of
algorithms, and is used throughout the code to identify the
algorithm. It should thus start with a letter and contain only
letters, digits, underscores ("_") or dots (".").
description
:Description of the algorithm, typically the full name. This will be used in the code to describe the algorith, so it should not be too long, and not contain newline characters.
funcName
:The name of the function used to estimate
the baseline. The function must take an argument
spectra
, and return a list with the estimated baselines
(baseline
) original spectra (spectra
) and the
corrected spectra (corrected
). It can also take other
arguments (typically parameters) and return additional components
in the list.
param
:A data frame with information about the
parameters of the algorithm. It should contain the following
coloumns: name
- the name of the parameter; integer
- TRUE
if the parameter only takes integer values,
otherwise FALSE
; min
- the lower limit of allowed values;
incl.min
- TRUE
if the lower limit is an allowed
value, otherwise FALSE
; default
- the default value;
max
- the upper limit of allowed values; incl.max
-
TRUE
if the upper limit is an allowed value, otherwise FALSE
signature(object = "baselineAlg")
: Extract
the description
slot
signature(object = "baselineAlg")
: Extract
the funcName
slot
signature(object = "baselineAlg")
: Extract
the name
slot
signature(object = "baselineAlg")
: Extract
the param
slot
The goal is that the
optimisation framework and the GUI code should get all information about
available baseline algorithms through a list of baselineAlg
objects. This will make it relatively simple to add new baseline algorithms.
Currenly, there is information about the algorithms spread around in the
code. We plan to move that information into the baselineAlg
objects, and expand the class accordingly.
Bjørn-Helge Mevik and Kristian Hovde Liland
showClass("baselineAlg")
showClass("baselineAlg")
A list with descriptions of all baseline algorithms available through
the optimisaiont framework and graphical user interface. The elements
of the list are baselineAlg
objects. The list is
used by the code to extract names and information about the baseline
algorithms.
The list is not meant for usage by end-users, but is extendable and customizable, allowing for extra algorithms or removal of algoritms.
The names of the list must match the name
slot of the
elements.
## Get a list of all algorithms: names(baselineAlgorithms) ## Show the descriptions sapply(baselineAlgorithms, description) ## Add new algorithm baseline.my.alg <- function(spectra, kappa=1, gamma=1){ baseline <- spectra-kappa+gamma corrected <- spectra-baseline list(baseline=baseline,corrected=corrected) } baselineAlgorithms$my.alg = new("baselineAlg", name = "my.alg", description = "A new baseline correction algorithm", funcName = "baseline.my.alg", param = data.frame( name = c("kappa","gamma"), # maxit integer = c(FALSE, FALSE), min = c(0, 0), incl.min = c(TRUE, TRUE), default = c(1, 1), max = c(Inf, 1), incl.max = c(FALSE, TRUE) ))
## Get a list of all algorithms: names(baselineAlgorithms) ## Show the descriptions sapply(baselineAlgorithms, description) ## Add new algorithm baseline.my.alg <- function(spectra, kappa=1, gamma=1){ baseline <- spectra-kappa+gamma corrected <- spectra-baseline list(baseline=baseline,corrected=corrected) } baselineAlgorithms$my.alg = new("baselineAlg", name = "my.alg", description = "A new baseline correction algorithm", funcName = "baseline.my.alg", param = data.frame( name = c("kappa","gamma"), # maxit integer = c(FALSE, FALSE), min = c(0, 0), incl.min = c(TRUE, TRUE), default = c(1, 1), max = c(Inf, 1), incl.max = c(FALSE, TRUE) ))
A list with data.frames containing parameters, minimum and maximum values for GUIs, step lengths for sliders, default values and currently selected values, plus a short description of each parameter. The list is used by the GUIs, and is user customizable.
The list is not meant for usage by end-users, but is extendable and customizable, allowing for extra algorithms, removal of algoritms or changing of parameter sets.
## Get a list of all algorithms: names(baselineAlgorithmsGUI) ## Add new algorithm: baselineAlgorithmsGUI$my.alg <- as.data.frame(matrix(c(0,20,1,1, 0,20,1,1), 2,4, byrow=TRUE)) dimnames(baselineAlgorithmsGUI$my.alg) <- list(par=c("kappa", "gamma"), val=c("min","max","step","default")) baselineAlgorithmsGUI$my.alg$current <- c(1,1) baselineAlgorithmsGUI$my.alg$name <- c("Subtractive constand", "Additive constant")
## Get a list of all algorithms: names(baselineAlgorithmsGUI) ## Add new algorithm: baselineAlgorithmsGUI$my.alg <- as.data.frame(matrix(c(0,20,1,1, 0,20,1,1), 2,4, byrow=TRUE)) dimnames(baselineAlgorithmsGUI$my.alg) <- list(par=c("kappa", "gamma"), val=c("min","max","step","default")) baselineAlgorithmsGUI$my.alg$current <- c(1,1) baselineAlgorithmsGUI$my.alg$name <- c("Subtractive constand", "Additive constant")
A class describing the result of a baseline algorithm test
Objects are typically created by running runTest
on a
baselineAlgTest
object.
param
:A named list with the parameter values that were tested. This includes both the predictor parameters and the baseline algorithm parameters. All combinations of values are tested.
qualMeas
:A matrix of quality measure values for the different combinations of parameter values. Each row corresponds to one prediction parameter value, and each coloumn to one combination of baseline parameters.
qualMeas.ind.min
:The index in qualMeas
of the minimum quality measure value
minQualMeas
:The minimum quality measure value
param.ind.min
:A vector of indices into the elemets of
param
of the parameter values corresponding to the minimum
quality measure value
param.min
:A list of the parameter values corresponding to the minimum quality measure value
qualMeasName
:The name of the quality measure
signature(object = "baselineAlgResult")
:
Extract the minQualMeas
slot
signature(object = "baselineAlgResult")
:
Extract the param
slot
signature(object = "baselineAlgResult")
:
Extract the param.ind.min
slot
signature(object = "baselineAlgResult")
:
Extract the param.min
slot
signature(object = "baselineAlgResult")
:
Extract the qualMeas
slot
signature(object = "baselineAlgResult")
:
Extract the qualMeas.ind.min
slot
signature(object = "baselineAlgResult")
:
Extract the qualMeasName
slot
Bjørn-Helge Mevik and Kristian Hovde Liland
Class baselineAlgTest
, function runTest
.
showClass("baselineAlgResult")
showClass("baselineAlgResult")
A class that describes a baseline algorithm test. The test is
performed with the function runTest
.
Objects can be created by calls of the form new("baselineAlgTest", ...)
.
algorithm
:A "baselineAlg"
object. The
baseline algorithm to test.
param
:A named list with parameter values to test. All combinations of parameters are tested.
extraArgs
:A named list of extra parameters to the baseline algorithm. These will be held fixed during the testing.
signature(object = "baselineAlgTest")
:
Extract the algorithm
slot
signature(object = "baselineAlgTest")
:
Extract the extraArgs
slot ...
signature(object = "baselineAlgTest")
:
Extract the funcName
slot ...
signature(object = "baselineAlgTest")
:
Extract the param
slot
signature(object = "baselineAlgTest")
: Run the
test.
Bjørn-Helge Mevik and Kristian Hovde Liland
Classes baselineAlg
,
baselineAlgResult
. Function runTest
.
showClass("baselineAlgTest")
showClass("baselineAlgTest")
Methods to access the baseline environment.
baselineEnv() getBaselineEnv(x, mode="any") putBaselineEnv(x, value)
baselineEnv() getBaselineEnv(x, mode="any") putBaselineEnv(x, value)
x |
Name of object to put/get. |
mode |
Mode of object to get. |
value |
Object to put. |
getBaseline
retrieves an object.
Kristian Hovde Liland and Bjørn-Helge Mevik
The functions implementing the baseline algorithms:
baseline.als
, baseline.fillPeaks
,
baseline.irls
, baseline.lowpass
,
baseline.medianWindow
,
baseline.modpolyfit
,
baseline.peakDetection
,
baseline.rfbaseline
, baseline.rollingBall
putBaselineEnv('fish', '<==x-<') getBaselineEnv('fish')
putBaselineEnv('fish', '<==x-<') getBaselineEnv('fish')
An interactive plotting tool for dynamic visualization of baselines and their effect using the gWidgets2 package with GTK+ or Tcl/Tk.
baselineGUI(spectra, method='irls', labels, rev.x = FALSE)
baselineGUI(spectra, method='irls', labels, rev.x = FALSE)
spectra |
Matrix with spectra in rows |
method |
Baseline correction method (optional) |
labels |
Labels for X-axis (optional) |
rev.x |
Reverse X-axis (optional, default=FALSE) |
Creates and updates a list containing current baseline and spectrum (baseline.result). Make sure a gWidget2 implementation is available, e.g gWidgets2RGtk2 or gWidgets2tcltk and a corresponding backend like GTK+ or Tcl/Tk. The GUI was developed using GTK which is an external dependency in Windows ans OS X.
Kristian Hovde Liland and Bjørn-Helge Mevik
data(milk) ## Not run: # Dependent on external software baselineGUI(milk$spectra) ## End(Not run)
data(milk) ## Not run: # Dependent on external software baselineGUI(milk$spectra) ## End(Not run)
This function rescales spectrum abscissa by use of breaks
and
gaps
before baseline correction. The effect is that the
chosen baseline correction algorithm and paramters will have varying
effects along the spectra, effectively giving local control of the amount
of rigidity/flexibility of the estimated baseline.
custom.baseline(spectra, breaks, gaps, trans.win = NULL, just.plot = FALSE, method, ...)
custom.baseline(spectra, breaks, gaps, trans.win = NULL, just.plot = FALSE, method, ...)
spectra |
Matrix with spectra in rows. |
breaks |
Vector of locations of break points between sections of varying baseline flexibility (given as abscissa numbers). |
gaps |
Vector giving the abscissa spacing between each instance of
|
trans.win |
Optional width of transition window around break points used for smoothing rough breaks by LOWESS (default = NULL). |
just.plot |
Plot the rescaled spectra instead of applying the customized
baseline correction if |
method |
Baseline correction method to use (class character). |
... |
Additional named arguments to be passed to the baseline correction method. |
This is an implementation of the customized baseline correction suggested by Liland et al. 2011 for local changes in baseline flexibility.
baseline |
Estimated custom baselines. |
corrected |
Spectra corrected by custom baselines. |
spectra.scaled |
Re-scaled spectra. |
baseline.scaled |
Estimated baselines of re-scaled spectra. |
Kristian Hovde Liland and Bjørn-Helge Mevik
Kristian Hovde Liland et al.: Customized baseline correction
data(milk) spectrum1 <- milk$spectra[1,1:10000,drop=FALSE] ordinary <- baseline(spectrum1, method="als", lambda=6, p=0.01) customized <- custom.baseline(spectrum1, 2900, c(1,20), trans.win=100, just.plot=FALSE, method="als", lambda=6, p=0.01) ## Not run: plot(1:10000,spectrum1, type='l') lines(1:10000,getBaseline(ordinary), lty=2, col=2, lwd=2) lines(1:10000,customized$baseline, lty=3, col=3, lwd=2) ## End(Not run)
data(milk) spectrum1 <- milk$spectra[1,1:10000,drop=FALSE] ordinary <- baseline(spectrum1, method="als", lambda=6, p=0.01) customized <- custom.baseline(spectrum1, 2900, c(1,20), trans.win=100, just.plot=FALSE, method="als", lambda=6, p=0.01) ## Not run: plot(1:10000,spectrum1, type='l') lines(1:10000,getBaseline(ordinary), lty=2, col=2, lwd=2) lines(1:10000,customized$baseline, lty=3, col=3, lwd=2) ## End(Not run)
Tests several baseline algorithms with one predictor for a given data
set. The baseline algorithms are represented as a list of
baselineAlgTest
objects, and the predictor as a
predictionTest
object.
doOptim(baselineTests, X, y, predictionTest, postproc = NULL, tmpfile = "tmp.baseline", verbose = FALSE, cleanTmp = FALSE)
doOptim(baselineTests, X, y, predictionTest, postproc = NULL, tmpfile = "tmp.baseline", verbose = FALSE, cleanTmp = FALSE)
baselineTests |
a list of |
X |
A matrix. The spectra to use in the test |
y |
A vector or matrix. The response(s) to use in the test |
predictionTest |
A |
postproc |
A function, used to postprocess the baseline corrected spectra prior to prediction testing. The function should take a matrix of spectra as its only argument, and return a matrix of postprocessed spectra |
tmpfile |
The basename of the files used to store intermediate
calculations for checkpointing. Defaults to |
verbose |
Logical, specifying whether the test should print out
progress information. Default is |
cleanTmp |
Logical, specifying whether the intermediate files should
be deleted when the optimisation has finished. Default is |
The function loops through the baseline algorithm tests in
baselineTests
, testing each of them with the given data and
prediction test, and collects the results. The results of each
baseline algorithm test is saved in a temporary file so that if the
optimisation is interrupted, it can be re-run and will use the
pre-calculated results. If cleanTmp
is TRUE
, the temporary
files are deleted when the whole optimisation has finished.
A list with components
baselineTests |
The |
results |
A list with the |
minQualMeas |
The minimum quality measure value |
baselineAlg.min |
The name of the baseline algorithm giving the minimum quality measure value |
param.min |
A list with the parameter values corresponding to the minimum quality measure value |
Bjørn-Helge Mevik and Kristian Hovde Liland
baselineAlgTest
,predictionTest
Extract the funcName
slot from an object of class
baselineAlg
or baselineAlgTest
funcName(object)
funcName(object)
object |
An object of class
|
The funcName
slot of the object.
Bjørn-Helge Mevik and Kristian Hovde Liland
The functions extract the baseline
, spectra
,
corrected
or call
slot of a baseline
object; usually the result of a call to baseline
.
getBaseline(object) getSpectra(object) getCorrected(object) getCall(object)
getBaseline(object) getSpectra(object) getCorrected(object) getCall(object)
object |
A |
getCall
returns the baseline
call used to create the
object. The other functions return a matrix with the original
spectra, estimated baselines or corrected spectra.
In a future versoion, one of the slots might be
removed from the class definition and calculated on the fly instead,
in order to save space. Therefore, do use the extractor
functions (getSpectra
, getBaseline
and
getCorrected
) instead of accessing the slots directly.
Bjørn-Helge Mevik and Kristian Hovde Liland
The function baseline
, the class baseline
data(milk) bl <- baseline(milk$spectra[1:2,]) baseline <- getBaseline(bl) spectra <- getSpectra(bl) corrected <- getCorrected(bl) call <- getCall(bl)
data(milk) bl <- baseline(milk$spectra[1:2,]) baseline <- getBaseline(bl) spectra <- getSpectra(bl) corrected <- getCorrected(bl) call <- getCall(bl)
Extract information from objects of class
predictionResult
.
ind.min(object) paramName(object)
ind.min(object) paramName(object)
object |
Object of class |
The corresponding slot of the object.
Bjørn-Helge Mevik and Kristian Hovde Liland
Matrix of 45 spectra of 21451 m/z values from MALDI-TOF on mixed milk samples.
data(milk)
data(milk)
A data frame with 45 observations on the following 2 variables.
cow
a numeric vector
spectra
a matrix with 21451 columns
cow
is the concentration of cow milk
in mixed samples of cow, goat, and ewe milk.
Kristian Hovde Liland, Bjørn-Helge Mevik, Elling-Olav Rukke, Trygve Almøy, Morten Skaugen and Tomas Isaksson (2009) Quantitative whole spectrum analysis with MALDI-TOF MS, Part I: Measurement optimisation. Chemometrics and Intelligent Laboratory Systems, 96(2), 210–218.
data(milk) ## Not run: plot(milk$spectra[1,], type = "l") ## End(Not run)
data(milk) ## Not run: plot(milk$spectra[1,], type = "l") ## End(Not run)
Extraction methods specifically for objects of class baselineAlg
name(object) description(object)
name(object) description(object)
object |
Object of class |
The methods return the corresponding slot of the object.
Bjørn-Helge Mevik and Kristian Hovde Liland
Set up optimization through a graphical user interface. Optionally collecting values directly from 'baselineGUI'.
Retrieve optimisation parameters and results with getOptim
and getOptimRes
, respectively.
optimWizard(X, y, postproc, predictionTest, cvsegments) getOptim() getOptimRes()
optimWizard(X, y, postproc, predictionTest, cvsegments) getOptim() getOptimRes()
X |
Matrix with spectra in rows |
y |
Response vector or matrix in analysis |
postproc |
Custum function for post processing of spectra (optional) |
predictionTest |
Custom prediction object (optional) |
cvsegments |
Cross-validation segments (optional) |
Kristian Hovde Liland and Bjørn-Helge Mevik
## Not run: # Computationally intensive data(milk) X <- milk$spectra[,-1] y <- milk$spectra[,1] optimWizard(X,y) # Retrieve optimisation myResults <- getOptimRes() # After optimisation is complete plotOptim(myResults) ## End(Not run)
## Not run: # Computationally intensive data(milk) X <- milk$spectra[,-1] y <- milk$spectra[,1] optimWizard(X,y) # Retrieve optimisation myResults <- getOptimRes() # After optimisation is complete plotOptim(myResults) ## End(Not run)
Takes the result of an optimisation (a call to doOptim
)
and extracts the minimum quality measure value along with the
parameters giving rise to the value.
overall.min(results)
overall.min(results)
results |
Result of call to |
A list with components
qualMeas |
The minimum quality measure value |
algorithm |
The name of the baseline algorithm corresponding to the minimum |
param |
A list with the parameter values corresponding to the minimum quality measure value |
Bjørn-Helge Mevik and Kristian Hovde Liland
Extracts the param
slot of the object.
param(object)
param(object)
object |
An object of class |
The param
slot of the object. Usually a data frame, list or numeric.
Bjørn-Helge Mevik and Kristian Hovde Liland
Classes baselineAlg
,
baselineAlgTest
,
baselineAlgResult
,
predictionResult
Extraction methods that are specific for objects of class
baselineAlgResult
param.ind.min(object) qualMeas.ind.min(object)
param.ind.min(object) qualMeas.ind.min(object)
object |
Object of class |
The corresponding slot
Bjørn-Helge Mevik and Kristian Hovde Liland
Class baselineAlgResult
Plot the original spectrum, the estimated baseline, and the corrected spectrum. Optionally zoom and pan plot, either with arguments or interactively.
## S4 method for signature 'baseline' plot(x, y, specNo = 1, grid = FALSE, labels = 1:n, rev.x = FALSE, zoom = NULL, ...) plotBaseline(x, y, specNo = 1, grid = FALSE, labels = 1:n, rev.x = FALSE, zoom = list(xz = 1, yz = 1, xc = 0, yc = 0), ...)
## S4 method for signature 'baseline' plot(x, y, specNo = 1, grid = FALSE, labels = 1:n, rev.x = FALSE, zoom = NULL, ...) plotBaseline(x, y, specNo = 1, grid = FALSE, labels = 1:n, rev.x = FALSE, zoom = list(xz = 1, yz = 1, xc = 0, yc = 0), ...)
x |
The |
y |
Unused. Ignored with a warning |
specNo |
The row number of the spectrum and baseline to plot. Defaults to 1 |
grid |
Logical. Whether to show a grid or not. Defaults to |
labels |
Vector. Labels for the x tick marks. Defaults to |
rev.x |
Logical. Whether the spectrum should be reversed.
Defaults to |
zoom |
Either |
... |
Other arguments. Currently ignored |
The normal way to plot baseline
objects is to use the
plot
method. The plotBaseline
function is the
underlying work-horse function, and is not meant for interactive use.
Because the argument list of any plot method must start with x
,
y
, and the plot method for the baseline
class does not
use the y
argument, all arguments except x
must be named
explicitly. Positional matching will not work.
Kristian Hovde Liland and Bjørn-Helge Mevik
baseline
, baseline
,
baselineGUI
data(milk) bl <- baseline(milk$spectra[1,, drop=FALSE]) ## Not run: # Computationally intensive plot(bl) plot(bl, zoom = TRUE) ## End(Not run)
data(milk) bl <- baseline(milk$spectra[1,, drop=FALSE]) ## Not run: # Computationally intensive plot(bl) plot(bl, zoom = TRUE) ## End(Not run)
A graphical user interface for plotting optimisation results, either one algorithm at the time or comparing algorithms.
plotOptim(results)
plotOptim(results)
results |
Result list from optimization |
plotOptim
creates a user interface based on the supplied results.
Curve and level plots from single algorithms or comparison of algorithms
is avilable.
For single algorithms subsets, levels corresponding to local or global minima, and averages can be extracted for plotting. For comparison of algorithms levels corresponding to local or global minima can be used, or levels corresponding to the minimum when averaging over selected values of the regression parameter, e.g. selected components in PLSR.
Kristian Hovde Liland and Bjørn-Helge Mevik
A class describing a PLSR prediction test. To run the test, the "pls" package must be installed.
Objects can be created by calls of the form new("PLSRTest",
...)
.
ncomp
:Integer vector. The number of PLSR components to test
cvsegments
:A list of the segments to use in the cross-validation
Class predictionTest
, directly.
signature(object = "PLSRTest")
: Run the test
Bjørn-Helge Mevik and Krisitan Hovde Liland
The base class predictionTest
. The
runTest
function. The plsr
function from the "pls" package.
showClass("PLSRTest")
showClass("PLSRTest")
A class containing the result of running a
predictionTest
.
The normal way to create objects is by calling the method
runTest
for any object of subclass of
predictionTest
.
param
:Numeric vector. The regression parameter values tested.
qualMeas
:Numeric vector. The quality measure values
for each of the values of the param
slot
ind.min
:The index (into qualMeas
) of the
minimum quality measure value
minQualMeas
:The minimum quality measure value
param.min
:The value of the parameter value corresponding to the minimum quality measure value
qualMeasName
:The name of the quality measure
paramName
:The name of the regression parameter
signature(object = "predictionResult")
: Extract
the ind.min
slot
signature(object = "predictionResult")
: Extract the minQualMeas
slot
signature(object = "predictionResult")
: Extract the param
slot
signature(object = "predictionResult")
: Extract the param.min
slot
signature(object = "predictionResult")
: Extract the paramName
slot
signature(object = "predictionResult")
: Extract the qualMeas
slot
signature(object = "predictionResult")
: Extract the qualMeasName
slot
Bjørn-Helge Mevik and Kristian Hovde Liland
Function runTest
, class
predictionTest
, subclasses
PLSRTest
and
ridgeRegressionTest
showClass("predictionResult")
showClass("predictionResult")
A virtual class for all predictor test subclasses. Currently
subclasses PLSRTest
and
ridgeRegressionTest
are defined.
A virtual Class: No objects may be created from it.
No methods defined with class "predictionTest" in the signature.
Bjørn-Helge Mevik and Kristian Hovde Liland
Subclasses PLSRTest
and
ridgeRegressionTest
.
Extract slots from objects of class
predictionResult
or
baselineAlgResult
.
qualMeas(object, ...) ## S4 method for signature 'predictionResult' qualMeas(object, ...) ## S4 method for signature 'baselineAlgResult' qualMeas(object, ..., MIN, AVG, DEFAULT = c("all", "cond.min", "overall.min", "avg")) minQualMeas(object) param.min(object) qualMeasName(object)
qualMeas(object, ...) ## S4 method for signature 'predictionResult' qualMeas(object, ...) ## S4 method for signature 'baselineAlgResult' qualMeas(object, ..., MIN, AVG, DEFAULT = c("all", "cond.min", "overall.min", "avg")) minQualMeas(object) param.min(object) qualMeasName(object)
object |
An object of class |
MIN |
List or vector of parameter names to take the minimum
over. Not used if |
AVG |
List or vector of parameter names to take the average
over. Not used if |
DEFAULT |
Character string. The default way to calculate the minimum (or average) for all parameters. See Details |
... |
Other arguments. Selection of subsets of parameter levels. See Details |
The arguments to the baselineAlgResult
method are
interpreted in the following way:
Subsets of parameters levels can be selected by supplying their names
and specifying the level indices as vectors. Substituting a vector
with "all"
will return all levels of the corresponding parameter, and
substituting it with "overall"
will return the level corresponding
to the overall minimum.
Minimum and average values for selected parameters can be chosen using
MIN
and AVG
, respectively, together with a vector of parameter names.
DEFAULT
specifies the action for each remaining parameters:
If "all"
(default): returns all levels. If "cond.min"
:
take minimum for each remaining parameter (MIN is not used). If
"overall.min"
: set any remaining parameters to their value
corresponding to the overall min. If "avg"
: take average for
each remaining parameter (AVG is not used).
The qualMeas
method for baselineAlgResult
objects returns
the subsets or minimum values of the qualMeas
slot of the object as specified
above. All other methods simply return the corresponding slot.
Bjørn-Helge Mevik and Kristian Hovde Liland
Function runTest
, classes
baselineAlgResult
and predictionResult
A class describing a ridge regression test.
Objects can be created by calls of the form new("ridgeRegressionTest", ...)
.
lambda
:Numeric vector. The smoothing parameter values to test
Class predictionTest
, directly.
signature(object = "ridgeRegressionTest")
: Run
the test
Bjørn-Helge Mevik and Kristian Hovde Liland
The base class predictionTest
. The
runTest
function.
showClass("ridgeRegressionTest")
showClass("ridgeRegressionTest")
Runs the test defined in a predictionTest
or
baselineAlgTest
object
runTest(object, X, y, ...) ## S4 method for signature 'PLSRTest' runTest(object, X, y) ## S4 method for signature 'ridgeRegressionTest' runTest(object, X, y) ## S4 method for signature 'baselineAlgTest' runTest(object, X, y, predictionTest, postproc, verbose = FALSE)
runTest(object, X, y, ...) ## S4 method for signature 'PLSRTest' runTest(object, X, y) ## S4 method for signature 'ridgeRegressionTest' runTest(object, X, y) ## S4 method for signature 'baselineAlgTest' runTest(object, X, y, predictionTest, postproc, verbose = FALSE)
object |
An object of class |
X |
A matrix. The spectra to use in the test |
y |
A vector or matrix. The response(s) to use in the test |
predictionTest |
A |
postproc |
A function, used to postprocess the baseline corrected spectra prior to prediction testing. The function should take a matrix of spectra as its only argument, and return a matrix of postprocessed spectra |
verbose |
Logical, specifying whether the test should print out
progress information. Default is |
... |
Other arguments. Currently only used by the
|
runTest
returns an object of class
predictionResult
or baselineAlgResult
.
signature(object = "baselineAlgTest")
Baseline corrects the spectra, optionally postprocesses them, and runs a prediction test on the corrected spectra.
signature(object = "PLSRTest")
Runs PLSR on the data and calculates the cross-validated RMSEP
signature(object = "ridgeRegressionTest")
Runs ridge regression on the data and calculates the GCV
Bjørn-Helge Mevik and Kristian Hovde Liland
baselineAlgTest
,
predictionTest
, PLSRTest
,
ridgeRegressionTest
Matrix of x,y values from X-Ray Photoelectron Spectroscopy on test sample.
The data are about the Carbon
and Oxygen
element for
1s
shell.
data(C1s) data(O1s)
data(C1s) data(O1s)
A matrix with the following 2 variables (rows).
first row
is the abscissa, ( Binding Energy [eV] )
second row
is the Intensity, ( a.u. )
data(C1s) data(O1s) plot(C1s[1,], C1s[2,], type = "l") plot(O1s[1,], O1s[2,], type = "l")
data(C1s) data(O1s) plot(C1s[1,], C1s[2,], type = "l") plot(O1s[1,], O1s[2,], type = "l")