This plot in 2D, help us to decide the number of PCs, it is easy to create in R, once we have discompose the X matrix into a P matrix (loadings) and a T matrix (scores).

For this plot, we just need the T matrix.

**> CPs<-seq(1,10,by=1)**

**> matplot(CPs,t(Xnipals$T),lty=1,pch=21,**

** + xlab=”PC_number”,ylab=”Explained_Var”)**

Every dot for every vertical line represents the score of a sample for that particular PC. We made the NIPALS calculations for 10 PCs. Every vertical line represents the projections of the samples over that particular PC. The score of a sample for that PC is the distance to the mean.

We can calculate for every PC, the standard deviation for all the scores and the variance.

As we see the firsts 2 PCs represents almost all the variance, and for the rest the projections are becoming narrower.

This plot is good to select how many components to choose, and also to detect outliers, extreme samples,…..

*Related*

To

**leave a comment** for the author, please follow the link and comment on his blog:

** NIR-Quimiometría**.

R-bloggers.com offers

**daily e-mail updates** about

R news and

tutorials on topics such as: visualization (

ggplot2,

Boxplots,

maps,

animation), programming (

RStudio,

Sweave,

LaTeX,

SQL,

Eclipse,

git,

hadoop,

Web Scraping) statistics (

regression,

PCA,

time series,

trading) and more...

If you got this far, why not

__subscribe for updates__ from the site? Choose your flavor:

e-mail,

twitter,

RSS, or

facebook...

**Tags:** "R" Chemometrics