Skip to contents

Compute a correlation value for every row of X against the vector y and n random permutations of y. If the number of possible permutations is less than the the argument n_perm then an exact test is performed instead. In both cases the function returns a data.frame of the original data with additional columns for the test statistic, empirical p-value, and FDR corrected empirical p-value.

Usage

permutation_correlation_test(X, y, n_perm = 10000, n_core = 1, ...)

Arguments

X

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

y

numeric vector of values to correlate with rows of X

n_perm

integer. The desired number of permutations to sample from. Default (10,000)

n_core

integer. The number of cores to use for processing. Default (1)

...

Additional arguments to pass to `cor` function

Examples

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

# correlate each row of X with 1,000 random permutations of vector y
res <- permutation_correlation_test(X, y, n_perm = 1e3, n_core = 8, method = "spearman")

head(res)
#>            sample.1  sample.2   sample.3   sample.4   sample.5  sample.6
#> feature.1 0.7821933 0.6602043 0.48967790 0.75132905 0.60629744 0.6202229
#> feature.2 0.4291988 0.2354373 0.61205202 0.51226119 0.03515643 0.6820479
#> feature.3 0.9272740 0.7137101 0.04128511 0.28267931 0.87701057 0.6256800
#> feature.4 0.7732432 0.8436818 0.94495533 0.09581502 0.25778071 0.7987585
#> feature.5 0.2596812 0.7661008 0.17228455 0.51790417 0.59102029 0.2347332
#> feature.6 0.3212247 0.7935108 0.15859775 0.55098693 0.18830556 0.9114281
#>             sample.7  sample.8   sample.9  sample.10        cor empirical.p
#> feature.1 0.91611895 0.8945791 0.01401642 0.16415494 -0.2969697       0.208
#> feature.2 0.58738448 0.2587961 0.67671086 0.79105816  0.5272727       0.057
#> feature.3 0.21747829 0.6450892 0.67225925 0.03130573 -0.4545455       0.097
#> feature.4 0.06514611 0.3728736 0.49071237 0.78709861 -0.2848485       0.198
#> feature.5 0.49508171 0.2482119 0.17214143 0.52142752 -0.2121212       0.282
#> feature.6 0.32647564 0.5998900 0.99117209 0.57493332  0.4545455       0.106
#>                 FDR
#> feature.1 0.4571429
#> feature.2 0.3774834
#> feature.3 0.4173554
#> feature.4 0.4489796
#> feature.5 0.4723618
#> feature.6 0.4206349