predict.specproc_opls: Predict with an OPLS Model

predict.specproc_oplsR Documentation

Predict with an OPLS Model

Description

Applies an OPLS model fitted by opls() to new data: removes the orthogonal components (the OPLS filter), or predicts the response or the scores.

Usage

## S3 method for class 'specproc_opls'
predict(object, newdata, type = c("correction", "response", "scores"), ...)

Arguments

object

A model returned by opls().

newdata

A numeric matrix or data frame of new data, with the same variables as the calibration data. If both have column names, the columns of newdata are matched by name.

type

The prediction: "correction" (default) the filtered data, like the correction component of the model; "response" the predicted response; "scores" the predictive (p1) and orthogonal (o1, ...) scores.

...

Not used.

Details

The new data are preprocessed with the centers and scales of the calibration data, and the orthogonal components are removed one at a time (\textbf{t}_o = \textbf{X}\textbf{w}_o, \textbf{X} \leftarrow \textbf{X} - \textbf{t}_o\textbf{p}_o^T). The predicted response is \textbf{X}\textbf{w}c, of the filtered data, back in the units of y.

Value

A tibble of filtered data or of scores, or a numeric vector of predicted responses.

See Also

opls(), step_opls()

Examples

data(forageLIBS)
wl <- suppressWarnings(as.numeric(names(forageLIBS)))
spectra <- forageLIBS[which(wl > 760 & wl < 780)]  # the K I resonance lines
cal <- 1:300
fit <- opls(spectra[cal, ], forageLIBS$K[cal], ncomp = 2)
head(predict(fit, spectra[-cal, ], type = "response"))

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