Applies an OPLS model fitted by opls() to new data: removes the
orthogonal components (the OPLS filter), or predicts the response or the
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
newdataare matched by name.- type
The prediction:
"correction"(default) the filtered data, like thecorrectioncomponent 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.
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
