6 mar. 2016

Tutorials with Resemble (Part 3)

“ex1” is a list, and one of the values is “pcAnalysis” which is another list containing the scores of the  training spectra matrix and the scores of the validation spectra matrix. The scores are standardized, so the variance is one in each principal component.

pcAnalysis<-ex1\$pcAnalysis
scores_Xt<-pcAnalysis\$scores_Xr
scores_Xv<-pcAnalysis\$scores_Xu

As we have done in other plots if we have the score matrix we can plot the different planes to check the samples in the PC space select the combinations we prefer, in this plot we represent PC1 vs. PC2:

plot(scores_Xt[,1],scores_Xt[,2],col="blue",
panel.first=grid(),xlim=c(-7,7),
ylim=(c(-7,7)))
par(new=T)
plot(scores_Xv[,1],scores_Xv[,2],col="red",
xlim=c(-7,7),ylim=(c(-7,7)))

and we can draw ellipses of radio 1,  to see more clearly the distance to the centroid.
Training samples are in blue and validation samples are in red.

This is an example of how to build an ellipse of radio 4:

library( plotrix)
draw.ellipse(0,0,4,4,border=1,
angle=0, lty=3)