PCA: Principal Component Analysis

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/PCA.R

Description

Functions for PCA: creating a PCA object, extracting variances, scores and loadings for individual PCs, projecting new data in the PC space, and reconstruction using a limited number of PCs.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
PCA(X, warn = TRUE)
## S3 method for class 'PCA'
summary(object, varperc = 90, pc.select = c(1:5,10), ...)
variances(object, npc = maxpc)
## S3 method for class 'PCA'
scores(object, npc = maxpc, ...)
## S3 method for class 'PCA'
loadings(object, npc = maxpc, ...)
reconstruct(object, npc = maxpc)
project(object, npc = maxpc, newdata, ldngs)

Arguments

X

a matrix, with each row representing an object.

warn

logical, whether or not to give a warning when the data are not mean-centered.

object

an object of class "PCA" (see below).

varperc

variance threshold in the summary function.

...

extra arguments, e.g., for printing the variance table (digits = ...).

pc.select

PCs to be included in the summary function.

npc

the number of PCs to be returned.

newdata

data (with the same number of variables as the original data) that are to be projected into the space of the first npc PCs.

ldngs

loadings to be used; by default the PCA loadings.

Value

Function PCA returns an object of class "PCA" with components

scores

object weights per PC.

loadings

variable weights per PC.

var

variance explained per PC.

totalvar

The total variance in the data set.

Function summary.PCA gives a short summary of the PCA model, stating how many PCs are needed to cover a certain percentage of the total variance, and for selected PCs gives the (cumulative) variance explained.

Function variances returns the variances associated with each PC.

Function scores returns the scores associated with each PC.

Function loadings returns the loadings associated with each PC.

Function reconstruct returns the reconstruction of the original data matrix, based on npc PCs.

Function project projects the new data into the subspace spanned by the given loadings. If argument ldngs is given, arguments pcamod and npc are not needed.

Author(s)

Ron Wehrens

References

R. Wehrens. "Chemometrics with R - Multivariate Data Analysis in the Natural Sciences and Life Sciences". Springer, Heidelberg, 2011.

See Also

plot.PCA

Examples

1
2
data(wines, package = "kohonen")
wines.PC <- PCA(scale(wines))

Example output

Attaching package: 'ChemometricsWithR'

The following objects are masked from 'package:stats':

    loadings, screeplot

ChemometricsWithR documentation built on May 2, 2019, 10:25 a.m.