3
$\begingroup$

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);
$\endgroup$
  • 2
    $\begingroup$ If you want the PCA, why not call [COEFF,SCORE] = princomp(X) (see here) directly? $\endgroup$ – Glen_b Jun 17 '14 at 22:45
  • $\begingroup$ 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? $\endgroup$ – Alexis Jun 18 '14 at 4:15
  • 1
    $\begingroup$ it is just self understanding,that why i preferred to do it myself $\endgroup$ – dato datuashvili Jun 18 '14 at 5:10
  • 1
    $\begingroup$ @Dato, in my previous answer 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. $\endgroup$ – ttnphns Jun 18 '14 at 5:38
6
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ +1 Always grat answers for PCA questions from amoeba, Thanks! $\endgroup$ – hxd1011 Nov 18 '16 at 16:24
  • $\begingroup$ @hxd1011 Thanks. This is a very old answer, I am only editing because I wanted to close another thread as a duplicate. $\endgroup$ – amoeba Nov 18 '16 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.