Question: Getting loadings of components from pcaMethods
0
Entering edit mode
10 months ago
johnnytam100 • 100

I want to get the loadings of components from pcaMethods.

To illustrate the problem, I have a matrix x

    a   b   c
1   ... ... ...
2   ... ... ...
3   ... ... ...

By loadings(pca(x, method="nipals", nPcs=2)), I get

    PC1 PC2
a   ... ...
b   ... ...
c   ... ...

However, I want to get

    PC1 PC2
1   ... ...
2   ... ...
3   ... ...

Anyone knows how to do that?

Thanks a lot!

ADD COMMENTlink 10 months ago johnnytam100 • 100 • updated 10 months ago Philipp Bayer 6.1k
0
Entering edit mode
10 months ago
Philipp Bayer 6.1k
Australia/Perth/UWA

Wouldn't you just need to transpose your input table while keeping names intact?

tx = setNames(data.frame(t(x[,-1])), x[,1])
loadings(pca(tx, method="nipals", nPcs=2))
ADD COMMENTlink 10 months ago Philipp Bayer 6.1k
Entering edit mode
0

Good idea! I had a similar thought but does it work for a PCA analysis that we just swap the columns and rows?

ADD REPLYlink 10 months ago
johnnytam100
• 100

Login before adding your answer.

Powered by the version 1.5