pca | R Documentation |
PCA
pca(x, k = 50, seed = 1, threshold = 0.9)
x |
A matrix which has columns as features and rows as samples. |
k |
Number of eigenvalues requested. |
seed |
A numeric number of seed used for Capper's method of determining PC number. In brief, the method shuffles features across samples and determine the PC number by comparing the maximum of eigen values from the randomization. |
threshold |
A numeric scalar between 0 to 1 of the threshold of the fraction of variance to choose PC number. Default to 0.9. |
The function wraps up the following five steps of PCA:
Center and scale.
Compute the correlation/covariance matrix.
Calculate the eigenvectors and eigenvalues.
Choose the PC number. I use Capper's method and fraction of
variance to calculate PC numbers and choose the bigger one
from the two methods. See details at find_pc_number.capper
and find_pc_number.var_frac
.
Project the scaled input matrix onto the new basis.
I use eigs
function in Rspectra package
instead of eigen
function in base to deal
with large matrix.
A list of four elements:
projected
The result matrix of PCA analysis.
pca123
A list of result from step 1-3 returned by
pca123
.
capper
A list of the result of choosing PC number
by Capper's method, returned by find_pc_number.capper
.
vf
A list of the result of choosing PC number
by fraction of variance, returned by find_pc_number.var_frac
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.