Perform principle component analysis (PCA) using singular value decomposition (SVD)
One method for performing PCA on a matrix and getting its factor loadings and eigenvalues is to use SVD as follows:
Given matrix M:
- Compute the correlation matrix of M (i.e., the matrix of all of its columns' correlations to each other).
- Perform SVD on the correlation matrix.
- Get the loadings and eigenvalues, which are U and the positive non-zero values in \Sigma.
In pseudo-code:
const C = correlationMatrix(M)
const { U, S, VT } = svd(C)
const loadings = U
const eigenvalues = flatten(S).filter(v => v > 0)