I assume the original question involved
DimensionReduction[...,Method->"PrincipalComponentsAnalysis"]
and not the function PrincipalComponents
. In which case this isn't correct, because, for whatever reason, the dimension reduction method does not correspond to the usual definition of PCA . The SVD usage, as shown, is however appropriate to the setting Method->"LatentSemanticAnalysis"
of DimensionReduction
and the like. Here is a quick example to illustrate.
mat = {{1., 2, 5.}, {3., -1., 2.}, {5, -1, 2}};
dimredPCA = DimensionReduction[mat, 2, Method -> "PrincipalComponentsAnalysis"];
dimredPCA[mat, "ReducedVectors"]
(* Out[107]= {{-2.34313, 0.0987804}, {0.83005, -0.55769}, {1.51308, 0.458909}} *)
We will not recover these using PCA.
{uu, ww, vv} = SingularValueDecomposition[mat, 2];
uu . ww
(* Out[110]= {{-4.16306, -3.55907}, {-3.55612, 1.06304}, {-5.00475, 2.20517}} *)
We do recover them with LSA though.
dimredLSA = DimensionReduction[mat, 2, Method -> "LatentSemanticAnalysis"];
dimredLSA[mat, "ReducedVectors"]
(* Out[112]= {{-4.16306, 3.55907}, {-3.55612, -1.06304}, {-5.00475, -2.20517}} *)
Let's get back to the other possibility, the function PrincipalComponents
.
PrincipalComponents[mat]
(* Out[481]= {{3.45902, 0.187592, 0.}, {-1.10879, -0.877829, 0.}, {-2.35023, 0.690237, 0.}} *)
It turns out this is essentially the same as what comes from the resource function MultidimensionalScaling, bearing in mind that resulting columns are only unique up to sign.
ResourceFunction["MultidimensionalScaling"][mat, 3]
(* Out[482]= {{-3.45902, 0.187592, 0.}, {1.10879, -0.877829, 0.}, {2.35023, 0.690237, 0.}} *)
Who knew? Certainly not the author of RF[MDS]. As a further note, this is essentially different from using Method->"MultidimensionalScaling"
in DimensionReduction
. Another note is that both PrincipalComponents
and ResourceFunction["MultidimensionalScaling"]
use what is usually termed "Principal Coordinate Analysis" (read second word carefully). This is as seen in the Wikipedia article for MDS at
https://en.wikipedia.org/wiki/Multidimensional_scaling
but I will remark that I've seen the same distinction in other places as well.