11
$\begingroup$
matrix = N[{{1, 2}, {2, 3}, {4, 10}}]
   {{1., 2.}, {2., 3.}, {4., 10.}}

res1 = PrincipalComponents[matrix, Method -> "Correlation"]
   {{1.10388, 0.130549}, {0.478746, -0.170139}, {-1.58262, 0.0395904}}

res2 = PrincipalComponents[matrix, Method -> "Covariance"]
   {{3.27053, 0.285293}, {1.99969, -0.335165}, {-5.27023, 0.0498715}}

res3 = PrincipalComponents[Standardize @ matrix, Method -> "Covariance"]
   {{1.10388, 0.130549}, {0.478746, -0.170139}, {-1.58262, 0.0395904}}

Here, you see that res1 == res3. My question is, how can I get res2 manually like the following:

eigenVectors = Eigenvectors @ Covariance[Standardize @ matrix];
Standardize[matrix].Transpose[eigenVectors]
   {{-1.10388, 0.130549}, {-0.478746, -0.170139}, {1.58262, 0.0395904}}
$\endgroup$
21
$\begingroup$

I vastly prefer the formulation in terms of the singular value decomposition (SVD). This question gets asked a lot by users of these functions, so here's a quick reference:

mat = {{1., 2.}, {2., 3.}, {4., 10.}};

p1 = PrincipalComponents[mat, Method -> "Covariance"]
   {{3.27053, 0.285293}, {1.99969, -0.335165}, {-5.27023, 0.0498715}}

p1a = Dot @@ Most[SingularValueDecomposition[Standardize[mat, Mean, 1 &]]]
   {{3.27053, 0.285293}, {1.99969, -0.335165}, {-5.27023, 0.0498715}}

p2 = PrincipalComponents[mat, Method -> "Correlation"]
   {{1.10388, 0.130549}, {0.478746, -0.170139}, {-1.58262, 0.0395904}}

p2a = Dot @@ Most[SingularValueDecomposition[Standardize[mat, Mean, StandardDeviation]]]
   {{1.10388, 0.130549}, {0.478746, -0.170139}, {-1.58262, 0.0395904}}
$\endgroup$
  • $\begingroup$ So just out of curiosity: are there any practical reasons for preferring one over the other? From my brief experiments, computing the eigenvectors of the covariance matrix seems to be faster than computing the (truncated) SVD of the data. The covariance matrix is also a useful quantity by itself, so you'll often end up calculating that anyway and it's a small step to calculate the eigenvectors after that. $\endgroup$ – Sjoerd Smit Aug 12 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.