PCA Space Projection – How to Project a New Vector in R

pcar

After performing principal component analysis (PCA), I want to project a new vector onto PCA space (i.e. find its coordinates in the PCA coordinate system).

I have calculated PCA in R language using prcomp. Now I should be able to multiply my vector by the PCA rotation matrix. Should principal components in this matrix be arranged in rows or columns?

Best Answer

Well, @Srikant already gave you the right answer since the rotation (or loadings) matrix contains eigenvectors arranged column-wise, so that you just have to multiply (using %*%) your vector or matrix of new data with e.g. prcomp(X)$rotation. Be careful, however, with any extra centering or scaling parameters that were applied when computing PCA EVs.

In R, you may also find useful the predict() function, see ?predict.prcomp. BTW, you can check how projection of new data is implemented by simply entering:

getS3method("predict", "prcomp")
Related Question