Solved – Manually calculating PCA rotation using original data and PCA projections (scores)

pcar

Is there any possibility of calculating PCA rotation similar to R's prcomp function, by that I mean if I do the following

log.ir <- log(iris[, 1:4])
ir.species <- iris[, 5]
ir.pca <- prcomp(log.ir)$x 

where ir.pca is a 150 by 4 (row by column) matrix, can I use this information to calculate rotation without using prcomp(log.ir)$rotation?

Best Answer

The principal components of your $N\times p$ (centered) data matrix $\mathbf{X}$ are given by $$ \mathbf{Z} = \mathbf{X V} $$ So you have that $$ \mathbf{V}' = \mathbf Z'\mathbf X (\mathbf X'\mathbf X) ^ {-1}. $$ You can compare the output of the second and third command:

X <- matrix(rnorm(1000), nrow = 100) # simulate some data
prcomp(X)$rotation
t(t(prcomp(X)$x) %*% X %*% solve(cov(X)))
Related Question