| predict.specproc_filter | R Documentation |
Corrects new spectra with a filter estimated by epo(), osc(),
direct_orthogonal(), direct_osc(), projected_osc() or o2pls().
The new spectra are preprocessed with the centers and scales of the
calibration data, and the components estimated on the calibration data are
removed. Estimating the filter on calibration data and applying it to
validation data with predict() avoids the optimistic bias that arises
when a supervised filter is fitted to all the data before validation.
## S3 method for class 'specproc_epo'
predict(object, newdata, ...)
## S3 method for class 'specproc_osc'
predict(object, newdata, ...)
## S3 method for class 'specproc_direct_orthogonal'
predict(object, newdata, ...)
## S3 method for class 'specproc_direct_osc'
predict(object, newdata, ...)
## S3 method for class 'specproc_projected_osc'
predict(object, newdata, ...)
## S3 method for class 'o2pls'
predict(object, newdata, ...)
object |
A filter returned by |
newdata |
A numeric matrix or data frame of new spectra, with the same
variables as the calibration data. If both have column names, the
columns of |
... |
Not used. |
For epo() the spectra are not centered, and the correction is
\textbf{X}_{new} - \textbf{X}_{new}\textbf{VV}^T. For the other
methods, the corrected spectra are centered (and scaled, if scale = TRUE
was used), like the correction component of the fitted object:
osc() with method = "wold" or "sjoblom", and o2pls(), remove the
orthogonal components one at a time, because their weights refer to the
deflated matrix.
osc() with method = "fearn", direct_orthogonal(), direct_osc()
and projected_osc() remove all components at once:
\textbf{X}_{new} - \textbf{X}_{new}\textbf{WP}^T.
Applied to the calibration spectra, predict() returns the correction
component of the fitted object.
A tibble of corrected spectra, with the same columns as newdata.
Christian L. Goueguel
The recipe steps step_osc() and related functions, which apply
these filters within a tidymodels workflow.
data(forageLIBS)
spectra <- forageLIBS[-(1:14)]
wl <- as.numeric(names(spectra))
x <- spectra[wl > 760 & wl < 780] # the K I resonance lines
cal <- 1:300
fit <- osc(x[cal, ], forageLIBS$K[cal], method = "fearn", ncomp = 2)
corrected <- predict(fit, x[-cal, ])
dim(corrected)
# applied to the calibration spectra, predict() gives the correction
all.equal(predict(fit, x[cal, ]), fit$correction)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.