View source: R/dim-reduction.R
associate_components | R Documentation |
Calculate associations between metadata variables and PCA rotations. This
function is inspired by methylKit::assocComp
but is designed to work
with arbitrary input data.
associate_components(x, metadata, N = 10, ...)
x |
data.frame or matrix of values passed to |
metadata |
data.frame of metadata variables to test associations. rownames(metadata) must be identical to colnames(x). |
N |
First N PCs to test associations between. Default 10. |
... |
Additional arguments passed to the |
This function returns the p-values from testing the association
between a given metadata column and all PC rotations. For numeric values the
p-value returned is computed using the cor.test()
function. For
factor variables and variables that can be converted to factor variables the
function will return p-values from the wilcox.test()
function or the
kruskal.test()
function (when the metadata variable has > 2 levels).
data.frame with rows for each metadata variable, columns for each PC, and p-values from the given test in cells.
# Specify metadata
metadata <- data.frame(
age = c(30, 80, 34, 30, 80, 40),
treatment = factor(c(rep("Treatment", 3), rep("Control", 3))),
class = factor(c(rep("A", 2), rep("B", 2), rep("C", 2))),
row.names = c(paste0("trt", 1:3), paste0("ctrl", 1:3))
)
# Create values to perform PCA on
df <- data.frame(replicate(6, runif(1000, 0, 100)))
colnames(df) <- c(paste0("trt", 1:3), paste0("ctrl", 1:3))
# Test for associations
res <- associate_components(df, metadata)
# Show results
head(res)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.