compute_pcas: Compute principal components.

Description Usage Arguments Value Examples

View source: R/pca.R

Description

Computation can be done using the recipes package (robust = FALSE, uses regular PCA) or with the rrcov package which uses rrcov::PcaGrid(), a robust PCA computation with built-in outlier identification.

Usage

1
2
3
4
5
6
7
8
compute_pcas(
  df,
  num_comp = 5,
  subset = NULL,
  normalize = TRUE,
  robust = FALSE,
  crit_pca_distances = 0.999
)

Arguments

df

A data frame.

num_comp

A positive integer. The number of PCA components to compute.

subset

A character vector. The subset of columns to use for PCA calculation. Default is all columns. Columns in df outside of this subset will be kept in the result.

normalize

A flag. Center and scale before PCA calculation?

robust

A flag. Use robust PCA (from rrcov::PcaGrid())?

crit_pca_distances

A number between 0 and 1. Outlier identification parameter. See rrcov::PcaGrid(). The larger this number, the fewer outliers identified.

Value

A data frame with the principal components with attributes

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
if (rlang::is_installed("mirmisc")) {
  ga_data <- get_ga_data(
    log2 = TRUE,
    gene_predicate = ~ median(.) > 0
  )
  pca_reg <- compute_pcas(ga_data,
    subset = intersect(
      mirmisc::get_gene_names(),
      names(ga_data)
    ),
    robust = FALSE
  )
  pca_rob <- compute_pcas(ga_data,
    subset = intersect(
      mirmisc::get_gene_names(),
      names(ga_data)
    ),
    robust = TRUE
  )
  ggplot2::ggplot(
    pca_reg,
    ggplot2::aes(PC1, PC2, color = meta_collectionga)
  ) +
    ggplot2::geom_point() +
    ggplot2::scale_color_viridis_c() +
    ggplot2::ggtitle("GAPPS regular")
  ggplot2::ggplot(
    pca_rob,
    ggplot2::aes(PC1, PC2, color = meta_collectionga)
  ) +
    ggplot2::geom_point() +
    ggplot2::scale_color_viridis_c() +
    ggplot2::ggtitle("GAPPS robust")
}

mirvie/mirmodels documentation built on Jan. 14, 2022, 11:12 a.m.