1

I do the following in MATLAB :

>> X = [ 123 982 123 ; 434 233 842; 143 239 583; 733 292 503]

X =

123   982   123
434   233   842
143   239   583
733   292   503

[coeff,score] = princomp(X)

coeff =

-0.3714    0.9202    0.1241
 0.7330    0.2085    0.6475
-0.5700   -0.3314    0.7519


score =

 709.3366   26.4384   30.9912
-364.9469  -81.8490  125.1814
-104.8637 -262.5228 -101.7805
-239.5260  317.9334  -54.3921

>> X * coeff

ans =

 603.9913  277.1477  743.6166
-470.2922  168.8604  837.8069
-210.2090  -11.8134  610.8450
-344.8714  568.6428  658.2333

Why isn't score = X * coeff ?

I believe X * coeff is the same as projecting the raw data along the principal component axes.

Sykalen
  • 11
  • 1
  • I believe this is because the coefficients are not orthonormal. Check http://www.mathworks.com/help/stats/feature-transformation.html#f75476 for more info – epx Jun 11 '15 at 04:55
  • So should I ideally make them orthonormal first before calculating the projections? – Sykalen Jun 11 '15 at 04:59

1 Answers1

0

Xc*coeff is not equal to score because your X is not centered.

As documentation says,

princomp centers X by subtracting off column means

Here is what centering does:

[m n] = size(X);
Xc = X - kron(ones(m,1),sum(X,1))/m;

Output:

Xc =

 -235.2500  545.5000 -389.7500
   75.7500 -203.5000  329.2500
 -215.2500 -197.5000   70.2500
  374.7500 -144.5000   -9.7500

Observe that

  • [coeff,score] = princomp(Xc) returns exactly the same result as [coeff,score] = princomp(X).

  • Xc*coeff is indeed equal to score

When using princomp you don't have to center data prior to feeding it to princomp since the routine does that for you, and probably in a more efficient way.

(By the way: princomp is deprecated; it's recommended to use pca instead.)