Why do the first output of PRINCOMP and the third output of SVD of the covariance of the data differ in MATLAB 7.7 (R2008b)?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I calculate the principal component of the data using PRINCOMP.
X=magic(4);
coeff = princomp(X);
I then compute singular value decomposition of the covariance of the data using SVD:
c=COV(X);
[U,S,V] = svd(c);
I expect 'coeff ' and 'V ' to be equal but they are not.
coeff==V
ans =
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
Réponse acceptée
MathWorks Support Team
le 18 Oct 2013
The difference you are observing between the first output of PRINCOMP and the third output of SVD of the covariance of the data is due to the way PRINCOMP is performing the Principal Component Analysis (PCA). Usually in PCA, one is interested in the directions of variation about the mean. PRINCOMP centers the data first and then performs the singular value decomposition on the centered data.
PRINCOMP centers the first input argument, X by subtracting off column means, but does not rescale the columns of X. You can use the function PCACOV to perform PCA directly on a covariance or correlation matrix.
Compare the result of calculating 'princomp(X) ' with the result of the following
[n,p] = size(X);
x0 = X - repmat(mean(X,1),n,1);
[U1,S1,V1]=svd(x0);
'V' and 'coeff' are the same.
V1==coeff
ans =
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
This calculation is different from computing the singular value decomposition of the covariance of the data using SVD. Consider the following:
c = COV(X);
[U,S,V] = svd(c);
Compare V with the results of Principal Component Analysis on the covariance of the data using the PCACOV function:
coeff2=pcacov(c);
'V' and 'coeff2' are the same.
V==coeff2
ans =
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
For more information on PRINCOMP, SVD, and PCACOV refer to the documentation which can be located by executing the following in the MATLAB command prompt:
web([docroot,'/toolbox/stats/princomp.html'])
web([docroot,'/techdoc/ref/svd.html'])
web([docroot,'/toolbox/stats/pcacov.html'])
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!