Principal Component Analysis

Share:

Description

Function to perform principal component analysis.

Usage

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

Arguments

data

an data frame containing the variables in the model.

scale

an optional data frame containing the variables in the model.

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

GVC

approximate MSEP

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.

Josse, J. and Husson, F. (2011). Selecting the number of components in PCA using cross-validation approximations. Computational Statistics and Data Analysis. 56 (6), pp. 1869:1879.

See Also

loadingsplot2D, T2, Xresids, ScoreContrib

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.