If I'm not mistaken, for positive semi-definite matrices, the eigenvalues are equal to squared singular values, so you should get the same answer either way.
The code you shown is definitely not R (looks like Matlab), so why are you posting to R-help? Andy > -----Original Message----- > From: Feng Zhang [mailto:[EMAIL PROTECTED]] > Sent: Thursday, February 06, 2003 1:03 PM > To: R-Help > Subject: [R] Confused by SVD and Eigenvector Decomposition in PCA > > > Hey, All > > In principal component analysis (PCA), we want to know how > many percentage > the first principal component explain the total variances > among the data. > > Assume the data matrix X is zero-meaned, and > I used the following procedures: > C = covriance(X) %% calculate the covariance matrix; > [EVector,EValues]=eig(C) %% > L = diag(EValues) %%L is a column vector with eigenvalues as > the elements > percent = L(1)/sum(L); > > > Others argue using Sigular Value Decomposition(SVD) to > calculate the same quantity, as: > [U,S,V]=svd(X); > L = diag(S); > L = L.^2; > percent = L(1)/sum(L); > > > So which way is the correct method to calculate the > percentage explained by > the first principal component? > > Thanks for your advices on this. > > Fred > > ______________________________________________ > [EMAIL PROTECTED] mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help > ------------------------------------------------------------------------------ ______________________________________________ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
