BaselineCorrection: Set the baseline to a uniform zero signal.

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/BaselineCorrection.R

Description

The function estimates and removes the smoothed baseline from the spectra.

Usage

1
2
3
4
BaselineCorrection(Spectrum_data, ptw.bc = TRUE, maxIter = 42,
                   lambda.bc = 1e7, p.bc = 0.05, eps = 1e-8, 
                   ppm.bc = TRUE, exclude.bc = list(c(5.1,4.5)),
                   returnBaseline = FALSE, verbose = FALSE)

Arguments

Spectrum_data

Matrix containing the spectra, one row per spectrum.

ptw.bc

If TRUE, calculates the baseline in C using the ptw library which is a lot faster. The R version is only kept because it is easier to understand than C and in case of problems with the installation of the ptw package.

maxIter

Maximum number of iterations for the R version (if ptw.bc is set to FALSE).

lambda.bc

Smoothing parameter (generally 1e5 – 1e8). See details.

p.bc

Asymmetry parameter. See details.

eps

Numerical precision for convergence when estimating the baseline.

ppm.bc

If TRUE, the values in exclude.zopc represent frequencies in ppm value (column names of spectra), if FALSE these values are column indices.

exclude.bc

If not NULL and ptw.bc == FALSE, a list containing the extremities of the intervals excluded for the baseline estimation, either expressed in ppm (decreasing values) OR in column indices (increasing values), e.g. exclude.bc = list(c(0,10000)) if ppm.bc == FALSE or exclude.bc = list(c(1,-1)) if ppm.bc == TRUE.

returnBaseline

If TRUE, returns the estimated baselines.

verbose

If"TRUE", will print processing information.

Details

The signal should be an addition of positive peaks which represent metabolites from the samples. These peaks are added to the baseline which is the signal representing the absence of any metabolite and should therefore be uniformly zero. For each spectrum, its baseline is thus estimated and removed. Let F be our initial spectrum an Z be its baseline. Once Z is approximated, the corrected spectrum is F - Z.

A negative signal doesn't make sense and creates problems with the statistical analysis. The estimated baseline should then not be such that F - Z < 0. Hence, in the objective function to be minimized, the squared difference F-Z are weighted by p if F - Z > 0 or 1 - p if F - Z < 0. p is indeed taken very small, e.g. 0.05, to avoid negative intensities. The function NegativeValuesZeroing is used thereafter to set the remaining negative intensities to zero after the baseline correction.

With this function to minimize, we would simply have F = Z as a solution which would make F - Z uniformly zero. Therefore, a roughness penalty term on Z is applied so that it does not match exactly the peaks. The importance of this smoothness constraint in the objective function is tuned by λ which is typically equal to 1e7.

In summary, usefull parameters are:

p.bc

The default value is 0.05. The smaller it is, the less Z will try to follow peaks when it is under the function and the more it will try to be under the function.

lambda.bc

The default value is 1e7. The larger it is, the smoother Z will be. With lambda = 0, the baseline will be equal to the signal and the corrected signal will be zero.

The algorithm used to find the baseline is iterative. In ptw, the iteration is done until the baseline is found but if ptw.bc is set to FALSE, we stop after maxIter iterations.

More details and motivations are given in the articles mentionned in the References.

Value

If returnBaseline is TRUE, will return a list with the following elements: Spectrum_data and Baseline. Otherwise, the function will just return Spectrum_data.

Spectrum_data

The matrix of spectra with the baseline removed.

Baseline

Estimation of the baseline.

Author(s)

Benoît Legat, Manon Martin & Paul H. C. Eilers

References

Martin, M., Legat, B., Leenders, J., Vanwinsberghe, J., Rousseau, R., Boulanger, B., & Govaerts, B. (2018). PepsNMR for 1H NMR metabolomic data pre-processing. Analytica chimica acta, 1019, 1-13.

Rousseau, R. (2011). Statistical contribution to the analysis of metabonomics data in 1H NMR spectroscopy (Doctoral dissertation, PhD thesis. Institut de statistique, biostatistique et sciences actuarielles, Université catholique de Louvain, Belgium).

Eilers, PHC. and Boelens, HFM. (2005). Baseline correction with asymmetric least squares smoothing. Leiden University Medical Centre report, 2005.

See Also

See also SolventSuppression which also uses the Whittaker smoother.

Examples

1
2
3
4
5
6
7
8
require(PepsNMRData)
BC_res <- BaselineCorrection(Data_HS_sp$Spectrum_data_HS_5,
                          lambda.bc=5e+06, p.bc=0.05)
#or
BC_res <- BaselineCorrection(Data_HS_sp$Spectrum_data_HS_5,
                          lambda.bc=5e+06, p.bc=0.05, returnBaseline=TRUE)
BC_spec = BC_res[["Spectrum_data"]]
plot(BC_res[["Baseline"]], type="l")

yclement/PepsNMR documentation built on April 10, 2020, 12:07 a.m.