h_pca_df_r2_matrix: Calculation of R2 Matrix between Sample Variables and...

View source: R/pca_cor_samplevar.R

h_pca_df_r2_matrixR Documentation

Calculation of R2 Matrix between Sample Variables and Principal Components

Description

[Stable]

This function processes sample variables from AnyHermesData and the corresponding principal components matrix, and then generates the matrix of R2 values.

Usage

h_pca_df_r2_matrix(pca, df)

Arguments

pca

(matrix)
comprises principal components generated by calc_pca().

df

(data.frame)
from the SummarizedExperiment::colData() of a AnyHermesData object.

Details

  • Note that only the df columns which are numeric, character, factor or logical are included in the resulting matrix, because other variable types are not supported.

  • In addition, df columns which are constant, all NA, or character or factor columns with too many levels are also dropped before the analysis.

Value

A matrix with R2 values for all combinations of sample variables and principal components.

See Also

h_pca_var_rsquared() which is used internally to calculate the R2 for one sample variable.

Examples

object <- hermes_data %>%
  add_quality_flags() %>%
  filter() %>%
  normalize()

# Obtain the principal components.
pca <- calc_pca(object)$x

# Obtain the `colData` as a `data.frame`.
df <- as.data.frame(colData(object))

# Correlate them.
r2_all <- h_pca_df_r2_matrix(pca, df)
str(r2_all)

# We can see that only about half of the columns from `df` were
# used for the correlations.
ncol(r2_all)
ncol(df)

insightsengineering/hermes documentation built on July 17, 2024, 1:01 p.m.