Formula: Q = X'X/(n-1) on scaled columns; W the eigenvectors of Q; PC = X W; keep the first k columns
References
Montesinos Lopez, Montesinos Lopez and Crossa (2022), Multivariate Statistical Machine Learning Methods for Genomic Prediction, Springer, doi:10.1007/978-3-030-89010-0. Chapter 2, Sect. 2.8 pp. 63-64. DEFECT FOUND: neither shared core sign-fixes its eigenvectors, so morie.fn._gp_core.pca_compress and the R morie_pca return loadings and scores that differ by a column sign; the three-way parity harness caught it. The sign is fixed HERE, in the same way morie.fn._tail1core.eigsym does it – the largest-magnitude entry of every loading column is made positive – rather than in the shared cores, which this slice must not edit. With that, a repeated eigenvalue leaves its loadings determined only up to a rotation within the eigenspace and is not a stable quantity in either language.
Examples
V <- c(1, 2, 3, 4, 5, 6, 7, 8)
Pcadim(V)
#> $scores
#> [,1]
#> [1,] -1.4288690
#> [2,] -1.0206207
#> [3,] -0.6123724
#> [4,] -0.2041241
#> [5,] 0.2041241
#> [6,] 0.6123724
#> [7,] 1.0206207
#> [8,] 1.4288690
#>
#> $loadings
#> [,1]
#> [1,] 1
#>
#> $eigenvalues
#> [1] 1
#>
#> $compressed
#> [,1]
#> [1,] -1.4288690
#> [2,] -1.0206207
#> [3,] -0.6123724
#> [4,] -0.2041241
#> [5,] 0.2041241
#> [6,] 0.6123724
#> [7,] 1.0206207
#> [8,] 1.4288690
#>
#> $prop_variance
#> [1] 1
#>
#> $cum_variance
#> [1] 1
#>
#> $k
#> [1] 1
#>
#> $n
#> [1] 8
#>
#> $p
#> [1] 1
#>
#> $method
#> [1] "PCA compression, MVSML Sect. 2.8"
#>
#> attr(,"class")
#> [1] "morie_rich_result" "list"
