# PCA in Matlab: why is the number of PCs always equal to the number of rows/observations minus 1? [duplicate]

I am currently trying to use classification analysis for some EEG data. As such data is of very high dimensionality, I am looking at using PCA for dimensionality reduction to prevent overfitting of the classification models.

My data structure is approximately 50 (rows, observations) times 38000 (columns, variables). I used the Matlab ‘pca’ function to generate principal components from my variables. I have three questions about this.

1. First, as stated on the Mathworks website (https://uk.mathworks.com/help/stats/pca.html), rows of the input matrix X should correspond to observations and columns to variables, which is the case for my approach. However, the number of principal components is always equal to rows/observations-1 (I tried using different numbers of rows). Why is this the case? Should it be this way? To me, it would be more intuitive if the number of (maximal) components would be equal to columns/variables-1.

2. Also, I observed that the sum of the output variable ‘explained’ is always 100, whether I have 5 or 50 principal components. Am I right to assume that this variable therefore does not refer to the proportion of the original data’s variance explained by the principal components but rather reflects the spread of ‘principal component’ variance across individual components? How can I find out the former? That is, how much of my data’s variance is included in the resulting principal components? Or do principal components always reflect the whole variance, no matter how few they might be?

3. Finally, I understand the ‘scores’ variable so that it reflects my data’s variance, meaning that it can be used analogously to my original data’s variables (e.g. columns). Is this right? Or do I have to project my data back to the original axes after performing PCA and using only a subset of the components? If so, how do I then even reduce input dimensions? I tried ‘reversing’ PCA and I received the same number of variables as before, just with different values in the matrix.

## marked as duplicate by amoeba, mdewey, Nick Cox, DeltaIV, Michael ChernickDec 24 '17 at 17:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• That's too many questions in one. Your FIRST question is a duplicate, so I vote to close as such. If you want answers to the other questions, I suggest you cut them out of here, and repost separately. – amoeba Dec 24 '17 at 15:55
• Sorry, I should have seen this post. Thanks a lot for pointing it out. – Mah1510 Dec 26 '17 at 2:14

## 1 Answer

The answer to your first question... the number of PCs is less than or equal to the rank of your matrix. Rank is equal to the dimension of the column space. The column space is the number of linearly independent vectors in the columns of your matrix, which cannot exceed the number of rows, being 50 in this case.