I am experiencing sign differences between my computations for principal component analysis using the pca function and the svd function. Consider this matrix:
X = magic(4)X = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1coeff = pca(X) %this will automatically save only the first few principal components
coeff = 0.5000 0.6708 0.4458 -0.5000 -0.2236 0.3573 -0.5000 0.2236 0.6229 0.5000 -0.6708 0.5344
Now when I do svd, I get the following results.
x0 = bsxfun(@minus,X,mean(X,1)); %first center the data
[~,~,v] = svd(x0)v = -0.5000 0.6708 -0.4458 -0.3182 0.5000 -0.2236 -0.3573 -0.7565 0.5000 0.2236 -0.6229 0.5586 -0.5000 -0.6708 -0.5344 0.1202
So I get essentially negatives of the first and third principal component. Does anyone know why this is?
Best Answer