Computes the sum of marginal component variances divided by \(tr(\Sigma)\).
This equals the variance explained by projection onto the span of U when the columns of U are orthonormal; otherwise it is the normalized sparse-PCA objective.
Usage
fraction_variance_explained(C, U)
Arguments
- C
A matrix. The correlation or covariance matrix (p x p).
- U
A matrix. The matrix containing the r PCs (p x r).
Examples
TestMat <- cor(mtcars)
mspcares <- mspca(TestMat, r = 2, ks = c(4, 4), verbose = FALSE)
fraction_variance_explained(TestMat, mspcares$x_best)
#> [1] 0.6023322