detrend: Detrend transformation

View source: R/detrend.R

detrendR Documentation

Detrend transformation

Description

Detrend transformations of the row observations (usually spectra) of a data set.

- Method poly fits an orthogonal polynom (of a given degree).

- Method lowess fits a LOWESS smoother (Cleveland, 1979) with function lowess.

- Method als fits an asymmetric least square (ALS) regression model (Eilers & Boelens, 2005). The function uses function asysm of package ptw (J. Gerretzen, P. Eilers, H. Wouters, T. Bloemberg & R. Wehrens).

The function returns either the residuals (corrected spectra) or the fitted predictions (baselines) depending on argument baseline.

Usage

detrend(X, method = c("poly", "lowess", "als"), ...)

Arguments

X

A matrix or data frame. The column names of X must be integers (usually wavelengths).

method

The detrend method.

...

Other arguments to pass depending on the method. See the examples.

Details

detrend uses function poly of package stat.

Value

A matrix of the transformed data.

References

- Cleveland, W. S. (1979). Robust locally weighted regression and smoothing scatterplots. Journal of the American Statistical Association, 74, 829-836. doi: 10.1080/01621459.1979.10481038.

- Eilers, P. H. C., Boelens, H. F. M., 2005. Baseline correction with asymmetric least squares smoothing

Examples


data(datcass)

X <- datcass$Xu

headm(X)

### Polynom

degree <- 1
#degree <- 2
z <- detrend(X, method = "poly", degree = degree)
headm(z)

oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(1, 2))
plotsp(z, zeroes = TRUE, main = "Corrected signal")
plotsp(X - z, main = "Baseline")
par(oldpar)

### Lowess

z <- detrend(X, method = "lowess", f = .5)
headm(z)

oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(1, 2))
plotsp(z, zeroes = TRUE, main = "Corrected signal")
plotsp(X - z, main = "Baseline")
par(oldpar)

### ALS

lambda <- 1e7 ; p <- .05
z <- detrend(X, method = "als", lambda = lambda, p = p)

oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(1, 2))
plotsp(z, zeroes = TRUE, main = "Corrected signal")
plotsp(X - z, main = "Baseline")
par(oldpar)


mlesnoff/rnirs documentation built on April 24, 2023, 4:17 a.m.