Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

predict-methods

Predict values from PCA.


Description

Predict data using PCA model

Usage

## S3 method for class 'pcaRes'
predict(object, newdata, pcs = nP(object), pre = TRUE,
  post = TRUE, ...)

## S4 method for signature 'pcaRes'
predict(object, newdata, pcs = nP(object),
  pre = TRUE, post = TRUE, ...)

Arguments

object

pcaRes the pcaRes object of interest.

newdata

matrix new data with same number of columns as the used to compute object.

pcs

numeric The number of PC's to consider

pre

pre-process newdata based on the pre-processing chosen for the PCA model

post

unpre-process the final data (add the center back etc)

...

Not passed on anywhere, included for S3 consistency.

Details

This function extracts the predict values from a pcaRes object for the PCA methods SVD, Nipals, PPCA and BPCA. Newdata is first centered if the PCA model was and then scores (T) and data (X) is 'predicted' according to : That=XnewP Xhat=ThatP'. Missing values are set to zero before matrix multiplication to achieve NIPALS like treatment of missing values.

Value

A list with the following components:

scores

The predicted scores

x

The predicted data

Author(s)

Henning Redestig

Examples

data(iris)
hidden <- sample(nrow(iris), 50)
pcIr <- pca(iris[-hidden,1:4])
pcFull <- pca(iris[,1:4])
irisHat <- predict(pcIr, iris[hidden,1:4])
cor(irisHat$scores[,1], scores(pcFull)[hidden,1])

pcaMethods

A collection of PCA methods

v1.82.0
GPL (>= 3)
Authors
Wolfram Stacklies, Henning Redestig, Kevin Wright
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.