Computes the fraction of variance explained (variance explained normalized by the trace of the covariance/correlation matrix) by each PC.
Usage
fraction_variance_explained_perPC(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).
Value
A numeric vector of length ncol(U).
Examples
C <- diag(c(3, 2, 1))
U <- diag(3)[, 1:2]
fraction_variance_explained_perPC(C, U)
#> [1] 0.5000000 0.3333333