Skip to contents

[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.

Value

A vector with R2 values for each principal component.

Details

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

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)