[R] PCA (prcomp) details info.

Bjørn-Helge Mevik bhs2 at mevik.net
Sun Jan 14 12:59:20 CET 2007

Francesco Savorani wrote:

> I'm handling a matrix dataset composed by a number of variables much
> higher than the objects (900 vs 100) and performing a prcomp
> (centered and scaled) PCA on it. What I get is a Loadings (rotation)
> matrix limited by my lower number of objects and thus 900x100
> instead of 900x900. If I try to manually calculate the matrix scores
> multiplying the original variables (centered and scaled) for such a
> loadings matrix I cannot obtain the same values calculated by R and
> stored on the prcomp$x matrix (100x100).

This works for me:

M <- matrix(rnorm(900*100), ncol = 900)
pca <- prcomp(M, scale = TRUE)
S <- scale(M) %*% pca$rotation
all.equal(S, pca$x) ## => TRUE

Bjørn-Helge Mevik

More information about the R-help mailing list