# pcaFit: Principal Component Analysis In mvdalab: Multivariate Data Analysis Laboratory

## 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` 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

## 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.

`loadingsplot2D`, `T2`, `Xresids`, `ScoreContrib`
 ``` 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 ```