pca: PCA

View source: R/pca.R

pcaR Documentation

PCA

Description

PCA

Usage

pca(x, k = 50, seed = 1, threshold = 0.9)

Arguments

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.

Details

The function wraps up the following five steps of PCA:

  1. Center and scale.

  2. Compute the correlation/covariance matrix.

  3. Calculate the eigenvectors and eigenvalues.

  4. 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.

  5. 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.

Value

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.


markgene/yamatClassifier documentation built on Oct. 14, 2024, 2:36 a.m.