View source: R/gt_pca_partialSVD.R
| gt_pca_partialSVD | R Documentation |
gen_tibble objects by partial SVDThis function performs Principal Component Analysis on a gen_tibble, by
partial SVD through the eigen decomposition of the covariance. It works well
if the number of individuals is much smaller than the number of loci;
otherwise, gt_pca_randomSVD() is a better option. This function is a
wrapper for bigstatsr::big_SVD().
gt_pca_partialSVD(
x,
k = 10,
fun_scaling = bigsnpr::snp_scaleBinom(),
total_var = TRUE
)
x |
a |
k |
Number of singular vectors/values to compute. Default is |
fun_scaling |
Usually this can be left unset, as it defaults to
|
total_var |
a boolean indicating whether to compute the total variance
of the matrix. Default is |
a gt_pca object, which is a subclass of bigSVD; this is an S3
list with elements: A named list (an S3 class "big_SVD") of
d, the eigenvalues (singular values, i.e. as variances),
u, the scores for each sample on each component (the left singular
vectors)
v, the loadings (the right singular vectors)
center, the centering vector,
scale, the scaling vector,
method, a string defining the method (in this case 'partialSVD'),
call, the call that generated the object.
square_frobenius, used to compute the proportion of variance explained
by the components (optional)
Note: rather than accessing these elements directly, it is better to use
tidy and augment. See gt_pca_tidiers.
bigstatsr::big_SVD() which this function wraps.
# Create a gen_tibble of lobster genotypes
bed_file <-
system.file("extdata", "lobster", "lobster.bed", package = "tidypopgen")
lobsters <- gen_tibble(bed_file,
backingfile = tempfile("lobsters"),
quiet = TRUE
)
# Remove monomorphic loci and impute
lobsters <- lobsters %>% select_loci_if(loci_maf(genotypes) > 0)
lobsters <- gt_impute_simple(lobsters, method = "mode")
# Create PCA object, including total variance
gt_pca_partialSVD(lobsters,
k = 10,
total_var = TRUE
)
# Change number of components and exclude total variance
gt_pca_partialSVD(lobsters,
k = 5,
total_var = FALSE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.