Skip to contents

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.

Value

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

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.

See also

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"))
#> [1] 1.977714 2.147724 2.209448 1.998919 2.021025 1.675603