Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotation in 'FactoMineR' package

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.

like image 312
gtnbz2nyt Avatar asked Mar 31 '14 12:03

gtnbz2nyt


1 Answers

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]),'/')
like image 195
Sergey Bushmanov Avatar answered Oct 24 '22 02:10

Sergey Bushmanov