predict.specproc_robpca: Scores and Distances of New Observations

View source: R/robust_pca.R

predict.specproc_macropcaR Documentation

Scores and Distances of New Observations

Description

Projects new observations onto a robust PCA model fitted by robpca(), rospca() or macropca(), and computes their score and orthogonal distances with the cut-offs of the calibration data.

Usage

## S3 method for class 'specproc_macropca'
predict(object, newdata, ...)

## S3 method for class 'specproc_cellpca'
predict(object, newdata, ...)

## S3 method for class 'specproc_robpca'
predict(object, newdata, ...)

Arguments

object

An object returned by robpca(), rospca() or macropca().

newdata

A numeric matrix or data frame with the same variables as the calibration data. For macropca(), missing values are allowed.

...

Not used.

Value

A tibble with the scores (PC1, ..., PCk), the score distance sd, the orthogonal distance od and the outlier_type of each new observation.

See Also

plot_outlier_map(), which can display new observations.

Examples

data(forageLIBS)
wl <- suppressWarnings(as.numeric(names(forageLIBS)))
spectra <- forageLIBS[which(wl > 760 & wl < 780)]  # the K I resonance lines
set.seed(1)
fit <- robpca(spectra[1:300, ])
head(predict(fit, spectra[301:368, ]))

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