h_pca_var_rsquared: Calculation of R2 between Sample Variable and Principal...

View source: R/pca_cor_samplevar.R

h_pca_var_rsquaredR Documentation

Calculation of R2 between Sample Variable and Principal Components

Description

[Stable]

This helper function calculates R2 values between one sample variable from AnyHermesData and all Principal Components (PCs) separately (one linear model is fit for each PC).

Usage

h_pca_var_rsquared(pca, x)

Arguments

pca

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

x

(vector)
values of one sample variable from a AnyHermesData object.

Details

Note that in case there are estimation problems for any of the PCs, then NA will be returned for those.

Value

A vector with R2 values for each principal component.

Examples

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

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

# Obtain the sample variable.
x <- colData(object)$AGE18

# Correlate them.
r2 <- h_pca_var_rsquared(pca, x)

insightsengineering/hermes documentation built on Sept. 19, 2024, 9:06 p.m.