Skip to contents

Compute significant dimensions of a matrix using the Marchenko-Pastur or Gavish-Donoho methods

Usage

compute_dimension(
  x,
  var_explained,
  noise_select,
  pc_method = c("gd", "mp"),
  verbose = FALSE
)

Arguments

x

A data frame or matrix of methylation values; rows = features, columns = samples

var_explained

A numeric vector containing the variance explained by successive PCs, sorted in decreasing order. (Used for PCAtools)

noise_select

Numeric scalar specifying the variance of the random noise (Used for PCAtools)

pc_method

String indicating the method for estimating dimension; "gd" = Gavish-Donoho, "mp" = Marchenko-Pastur

verbose

Boolean indicating whether to print statements while running, default = FALSE

Value

Numeric scalar representing the optimal number of PCs to retain using the specified method

Examples

x <- diag(4)
pca_res <- PCAtools::pca(x) # Run PCA
eig_sq <- pca_res$sdev^2 # Compute variance explained
compute_dimension(x, eig_sq, 1, "gd")
#> [1] 1
#> attr(,"limit")
#> [1] 7.111111