4

Given a data matrix $\mathbf X$ of $12 \times 7$ size with samples in rows and variables in columns, I have calculated centered data $\mathbf X_c$ by subtracting column means, and then computed covariance matrix as $\frac{1}{N-1} \mathbf X_c^\top \mathbf X_c$.

The dimensions of this covariance matrix are $7 \times 7$. After that I have calculated the eigenvalue decomposition, obtaining eigenvector matrix $\mathbf V$ with eigenvectors in columns.

Now I want to know about projections (i.e. principal component scores in PCA): is it $\mathbf{V}^\top \mathbf{X}_c$ or $\mathbf{X}_c \mathbf{V}$?

mean_matrix = X - repmat(mean(X),size(X,1),1);
covariance = (transpose(mean_matrix) * mean_matrix)/(12-1);

[V,D] = eig(covariance);
[e,i] = sort(diag(D), 'descend');
V_sorted = V(:,i);
amoeba
  • 93,463
  • 28
  • 275
  • 317
dato datuashvili
  • 723
  • 2
  • 7
  • 21
  • 2
    If you want the PCA, why not call `[COEFF,SCORE] = princomp(X)` (see [here](http://www.mathworks.com.au/help/stats/princomp.html)) directly? – Glen_b Jun 17 '14 at 22:45
  • Also, why bother with the long road of standardizing the covariance matrix, when simply using the correlation matrix will get you there in one step? – Alexis Jun 18 '14 at 04:15
  • 1
    it is just self understanding,that why i preferred to do it myself – dato datuashvili Jun 18 '14 at 05:10
  • 1
    @Dato, in my previous [answer](http://stats.stackexchange.com/a/102999/3277) to you there is clearly written: "Raw component scores ... are computed directly as X*V". All necessary formulas for PCA and factor analysis were given by me there. – ttnphns Jun 18 '14 at 05:38

1 Answers1

6

The projection is given by $\mathbf{X}_c \mathbf{V}$; principal component scores are columns of this matrix.

Your first formula cannot be computed, as $\mathbf{V}^\top$ is of $7 \times 7$ size and $\mathbf{X}_c$ has $12$ rows; the dimensions do not match, and the matrix product is not defined. Instead, $\mathbf{V}^\top \mathbf{X}_c^\top$ would be another correct formula, but it is simply a transpose of the first equation: $\mathbf{V}^\top \mathbf{X}^\top_c = (\mathbf{X}_c\mathbf{V})^\top$. Here PC scores are in rows.

amoeba
  • 93,463
  • 28
  • 275
  • 317