I'm using Mathematica's PrincipalComponents[] to do a principal components analysis on a data set with m data points and n variables (m > n). The command produces the m by $n$ matrix which contains the representation of each of the data in the principal components basis.

My question is -- how can I instead extract the principal component vector itself, as coefficients of original variable basis vectors? I'm aware you can do this with singular value decomposition or calculating the eigenvectors of the covariance matrix, but in doing those calculations there is an arbitrary choice of sign involved which might not be the same choice as PrincipalComponents[]. I want to see exactly the principal component vectors used by PrincipalComponents[].

  • 3
    $\begingroup$ I would say it's a duplicate of this: mathematica.stackexchange.com/q/37762/12 (though I'm not completely satisfied with that solution) $\endgroup$ – Szabolcs Jun 7 '18 at 18:37
  • $\begingroup$ @Szabolcs Thanks for the link; the command FindGeometricTransform[] does seem to work. However it also seems very slow, without getting into details, I'm doing a principal components analysis on a set with ~20 observations and ~15 variables. PrincipalComponents[] is very fast. FindGeometricTransform[] takes minutes. If I remove half the variables it takes a few seconds. Frustrating since one would think PrincipalComponents[] would have already calculated them. $\endgroup$ – William Kennerly Jun 9 '18 at 4:31
  • $\begingroup$ @Szabolcs I can update my previous comment to say that you can speed up FindGeometricTransform[] using the Method->"Linear" option, which the documentation says uses SVD just like PrincipalComponents[] should, so its speed is nearly instantaneous. Unfortunately I don't believe it orders the principal components by decreasing variance so this is still not the ideal solution. $\endgroup$ – William Kennerly Jun 9 '18 at 14:05
  • 2
    $\begingroup$ I'm sorry, I don't have a good solution for you. When I needed this last time, I went straight to SingularValueDecomposition precisely because I couldn't get the transformation from PrincipalComponents. $\endgroup$ – Szabolcs Jun 9 '18 at 16:54
  • 1
    $\begingroup$ I agree. I think it is worth contacting Wolfram Support about such issues and suggesting improvements for future versions. $\endgroup$ – Szabolcs Jun 13 '18 at 7:40

Your Answer

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

Browse other questions tagged or ask your own question.