Reputation: 163
My data is a [478 x 4200] matrix. I am considering 4200 elements as components and I want to reduce the number of components that I need to take care of. I used prcomp() and somehow it always returns 478 principal components even though I transpose the matrix. As far as I understand prcomp() uses columns as components. I think I should get 4200 principle components. I can do it manually by computing all the matrices that I need, but I want to check with this function.
Upvotes: 1
Views: 2798
Reputation: 3201
To be somewhat explicit:
If you have n = 478 observations of p = 4200 variables each you need to construct a 478 x 4200 matrix where each row is an observation of those 4200 variables. Let's call this matrix m.
PCA is then performed with
pca_result <- prcomp(m)
The resulting principal component vectors are in the matrix pca_result$rotation. Each column is a principal component, and the columns are ordered by decreasing variance explained.
Each principal component has dimension p = 4200, and there will be min(n-1, p) = 478 informative principal components. So pca_result$rotation is a 4200 x 478 matrix.
The PCA score vectors are the columns of the matrix pca_result$x. So there will also be 478 (=number of principal components) score vectors of dimension 478 (=number of observations) each.
Upvotes: 4