y_gradient_glsw: y-Gradient Generalized Least Squares Weighting

View source: R/y_gradient_glsw.R

y_gradient_glswR Documentation

y-Gradient Generalized Least Squares Weighting

Description

The y-gradient generalized least squares weighting algorithm (GLSW) removes variance from the data (spectra), which is orthogonal to the response.

Usage

y_gradient_glsw(x, y, alpha = 0.01, window = 5)

Arguments

x

A numeric matrix, data frame or tibble, representing the predictors data.

y

A numeric vector representing the response vector.

alpha

A positive numeric value specifying the weighting parameter. Typical values range from 1 to 0.0001. Default is 0.01.

window

An odd integer giving the width of the Savitzky-Golay window used to compute the gradients. Default is 5.

Details

The y-Gradient GLSW is an alternative method to GLSW, where a continuous \textbf{y}-variable is used to develop pseudo-groupings of samples in \textbf{X} by comparing the differences in the corresponding \textbf{y} values. This is referred to as the "gradient method" because it utilizes a gradient of the sorted \textbf{X}- and \textbf{y}-blocks to calculate a covariance matrix.

The samples are sorted by increasing \textbf{y}, and the first derivatives of \textbf{X} and \textbf{y} along the sample axis are computed with a Savitzky-Golay filter. Samples whose neighbors have similar \textbf{y} values receive large weights w_i = 2^{-\Delta y_i / s_{\Delta y}}, so the differences between their spectra, \Delta\textbf{X}, describe variation unrelated to \textbf{y}. The filter is then built as in glsw() from \textbf{C} = \Delta\textbf{X}^T\textbf{W}^2\Delta\textbf{X}.

Value

A tibble containing the p \times p filtering matrix.

Author(s)

Christian L. Goueguel

References

  • Zorzetti, B.M., Shaver, J.M., Harynuk, J.J., (2011). Estimation of the age of a weathered mixture of volatile organic compounds. Analytica Chimica Acta, 694(1-2):31–37.

See Also

step_y_gradient_glsw() to use the filter in a tidymodels recipe.

Examples

data(forageLIBS)
spectra <- forageLIBS[-(1:14)]
wl <- as.numeric(names(spectra))
x <- spectra[wl > 760 & wl < 780]  # the K I resonance lines
G <- y_gradient_glsw(x, forageLIBS$K, alpha = 0.01)
filtered <- as.matrix(x) %*% as.matrix(G)
dim(filtered)

specProc documentation built on Nov. 20, 2026, 5:11 p.m.