calculate principal components

46 Views Asked by At

suppose that we have following data

X

X =

         332         428         354        1437         526         247         427
         293         559         388        1527         567         239         258
         372         767         562        1948         927         235         433
         406         563         341        1507         544         324         407
         386         608         396        1501         558         319         363
         438         843         689        2345        1148         243         341
         534         660         367        1620         638         414         407
         460         699         484        1856         762         400         416
         385         789         621        2366        1149         304         282
         655         776         423        1848         759         495         486
         584         995         548        2056         893         518         319
         515        1097         887        2630        1167         561         284

[m,n]=size(X)

m =

    12


n =

     7

i have calculated centered data from this matrix and also covariance matrix

mean_matrix=X-repmat(mean(X),size(X,1),1);

and finally covariance matrix

covariance=(mean_matrix'*mean_matrix)/(12-1);

dimensions of this covariance is

[m1,n1]=size(covariance)

m1 =

     7


n1 =

     7 

after that i have calculate eigenvalue decomposition

>> [V,D]=eig(covariance);
>> [e,i]=sort(diag(D),'descend');
>> sorted=V(:,i);
>> sorted

sorted =

   -0.0728    0.5758    0.4040   -0.1140   -0.1687   -0.6737   -0.0678
   -0.3281    0.4093   -0.2917   -0.6077    0.4265    0.1828    0.2348
   -0.3026   -0.1001   -0.3402    0.3965    0.5682   -0.4320   -0.3406
   -0.7532   -0.1082    0.0681    0.2942   -0.2848    0.0011    0.4987
   -0.4653   -0.2439    0.3809   -0.3299   -0.0645    0.2076   -0.6503
   -0.0911    0.6316   -0.2254    0.4135   -0.2366    0.4390   -0.3498
    0.0588    0.1444    0.6599    0.3068    0.5705    0.3005    0.1741

>> e

e =

   1.0e+05 *

    2.7483
    0.2642
    0.0625
    0.0230
    0.0209
    0.0034
    0.0007

now i want to know about projection: is it $V'*X$ or $X*V$? please help me to clarify this things

2

There are 2 best solutions below

0
On

Your vectors $V$ are eigen vectors of $covariance=X^TX$. I think these are columns of your matrix, but you can easily verify it multiplying your covariance matrix $covariance$ by columns and to verify property $Ax=\lambda x$.

0
On

If $Q$ is an orthogonal matrix whose columns span the space on which you wish to project the vector $x$, then the coefficients of the projection are given by $Q^T x$ and the projection itself is given by $Q Q^T x$. Your $V$ is an orthogonal matrix because your original covariance matrix is symmetric.