sample_n_random_cor: Generate a null distribution of correlation values

View source: R/permutation.R

sample_n_random_corR Documentation

Generate a null distribution of correlation values

Description

Selects n random rows from a numeric matrix with replacement. For each random row, permute vector y and perform correlation.

Usage

sample_n_random_cor(X, y, n = 10000, ...)

Arguments

X

numeric matrix or data.frame that can be converted to numeric matrix.

y

numeric vector. Numeric vector of values used to correlate with each row of df

n

integer. Number of random correlations to return. Default (1e4)

...

Additional arguments passed to 'cor' function

Value

numeric vector of correlation values. Vector can contain NAs if row variance == 0.

Examples

# generate example data
X <- matrix(runif(1e3 * 6), nrow = 1e3, ncol = 6)
y <- 1:6
dimnames(X) <- list(paste("feature", 1:1e3, sep = "."), paste("sample", 1:6, sep = "."))

# sample random correlations from permuted data
null_dist <- sample_n_random_cor(X, y, n = 1e3, method = "spearman")

head(null_dist)

coriell-research/coriell documentation built on March 29, 2025, 2:19 p.m.