pcaFit: Principal Component Analysis

pcaFitR Documentation

Principal Component Analysis

Description

Function to perform principal component analysis.

Usage

pcaFit(data, scale = TRUE, ncomp = NULL)

Arguments

data

an data frame containing the variables in the model.

scale

should scaling to unit variance be used.

ncomp

the number of components to include in the model (see below).

Details

The calculation is done via singular value decomposition of the data matrix. Dummy variables are automatically created for categorical variables.

Value

pcaFit returns a list containing the following components:

loadings

X loadings

scores

X scores

D

eigenvalues

Xdata

X matrix

Percent.Explained

Explained variation in X

PRESS

Prediction Error Sum-of-Squares

ncomp

number of latent variables

method

PLS algorithm used

Author(s)

Nelson Lee Afanador (nelson.afanador@mvdalab.com)

References

Everitt, Brian S. (2005). An R and S-Plus Companion to Multivariate Analysis. Springer-Verlag.

Edoardo Saccentia, Jos? Camacho, (2015) On the use of the observation-wise k-fold operation in PCA cross-validation, J. Chemometrics 2015; 29: 467-478.

See Also

loadingsplot2D, T2, Xresids, ScoreContrib

Examples

data(iris)
pc1 <- pcaFit(iris, scale = TRUE, ncomp = NULL)
pc1

print(pc1) #Model summary
plot(pc1) #MSEP
PE(pc1) #X-explained variance

T2(pc1, ncomp = 2) #T2 plot

Xresids(pc1, ncomp = 2) #X-residuals plot

scoresplot(pc1) #scoresplot variable importance

(SC <- ScoreContrib(pc1, obs1 = 1:9, obs2 = 10:11))  #score contribution
plot(SC)  #score contribution plot

loadingsplot(pc1, ncomp = 1) #loadings plot
loadingsplot(pc1, ncomp = 1:2) #loadings plot
loadingsplot(pc1, ncomp = 1:3) #loadings plot
loadingsplot(pc1, ncomp = 1:7) #loadings plot
loadingsplot2D(pc1, comps = c(1, 2)) #2-D loadings plot
loadingsplot2D(pc1, comps = c(2, 3)) #2-D loadings plot

mvdalab documentation built on Oct. 6, 2022, 1:05 a.m.