Skip to contents

Perform principal component analysis on the expression data. The function uses prcomp() to perform PCA and broom::tidy() to tidy the results.

Usage

gly_pca(exp, center = TRUE, scale = TRUE, add_info = TRUE, ...)

gly_pca_(expr_mat, center = TRUE, scale = TRUE, ...)

Arguments

exp

A glyexp::experiment() object containing expression matrix and sample information.

center

A logical indicating whether to center the data. Default is TRUE.

scale

A logical indicating whether to scale the data. Default is TRUE.

add_info

A logical value. If TRUE (default), sample and variable information from the experiment will be added to the result tibbles. If FALSE, only the PCA results are returned. Only applicable to gly_pca().

...

Additional arguments passed to prcomp().

expr_mat

A numeric matrix with variables as rows and samples as columns.

Value

A list containing:

  • tidy_result: A list of tibbles with PCA results:

    • samples: PCA scores for each sample containing the following columns:

      • sample: Sample name

      • PC: Principal component name (PC1, PC2, etc.)

      • value: Score value for the principal component

    • variables: PCA loadings for each variable containing the following columns:

      • variable: Variable name

      • PC: Principal component name (PC1, PC2, etc.)

      • value: Loading value for the principal component

    • eigenvalues: PCA eigenvalues containing the following columns:

      • PC: Principal component name (PC1, PC2, etc.)

      • std.dev: Standard deviation

      • percent: Percentage of variance explained

      • cumulative: Cumulative percentage of variance explained

  • raw_result: The raw prcomp object from stats::prcomp()

Details

The function performs log transformation on the expression data (log(x + 1)) before PCA analysis.

gly_pca() is the top-level API that works with glyexp::experiment() objects and supports the add_info parameter for joining experiment metadata.

gly_pca_() is the underlying API that works with matrices directly, providing more flexibility for users who don't use the glyexp package.

Required packages

This function only uses base R packages and does not require additional dependencies.

See also