Thanks in advance. I've used the 'PCA' function from the 'FactoMineR' package to obtain principal component scores. I've tried reading through the package details and similar questions on this forum but can't figure out the code to rotate the extracted components (either orthogonal or oblique).
I know the 'princomp' function and the 'principal' function in the 'psych' package have rotating abilities but I really like the ability in 'PCA' to scale the variables to unit-variance. Any help would be appreciated. Thank you.
IIUC:
library(FactoMineR)
data(iris)
Iris <- iris[,1:4]
res <- PCA(Iris, graph=F)
#rotation
t(apply(res$var$coord, 1, function(x) {x/sqrt(res$eig[,1])}))
Dim.1 Dim.2 Dim.3 Dim.4
Sepal.Length 0.5210659 0.37741762 -0.7195664 -0.2612863
Sepal.Width -0.2693474 0.92329566 0.2443818 0.1235096
Petal.Length 0.5804131 0.02449161 0.1421264 0.8014492
Petal.Width 0.5648565 0.06694199 0.6342727 -0.5235971
#check
prcomp(Iris, scale=T)
Rotation:
PC1 PC2 PC3 PC4
Sepal.Length 0.5210659 -0.37741762 0.7195664 0.2612863
Sepal.Width -0.2693474 -0.92329566 -0.2443818 -0.1235096
Petal.Length 0.5804131 -0.02449161 -0.1421264 -0.8014492
Petal.Width 0.5648565 -0.06694199 -0.6342727 0.5235971
An alternative line of code, if you wish to obtain loadings from PCA
object:
sweep(res$var$coord, 2, sqrt(res$eig[,1]),'/')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With