Perform a permutation correlation test on every row of a matrix
Source:R/permutation.R
permutation_correlation_test.Rd
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.
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.2662474 0.4552640 0.9013406 0.91531092 0.60306497 0.08655646
#> feature.2 0.8253921 0.4258724 0.9938062 0.57127229 0.13512341 0.17154187
#> feature.3 0.1744037 0.4352768 0.1697599 0.36899524 0.34321429 0.44868471
#> feature.4 0.6273238 0.4290254 0.7752482 0.48737756 0.47505250 0.29212738
#> feature.5 0.1609637 0.2758725 0.7283146 0.02551313 0.03749574 0.42441138
#> feature.6 0.5173081 0.2358571 0.5767007 0.34011008 0.19981703 0.80485172
#> sample.7 sample.8 sample.9 sample.10 cor empirical.p
#> feature.1 0.7293484 0.3700858 0.92330389 0.2092298 -0.03030303 0.449
#> feature.2 0.6564562 0.7242420 0.05269735 0.7591043 -0.24848485 0.229
#> feature.3 0.1600544 0.3306400 0.43022271 0.8950066 0.33333333 0.155
#> feature.4 0.1617591 0.5021804 0.29157056 0.7514272 -0.22424242 0.265
#> feature.5 0.6551433 0.2017496 0.55512118 0.4511958 0.33333333 0.180
#> feature.6 0.5412135 0.6030285 0.72769927 0.8650728 0.69696970 0.017
#> FDR
#> feature.1 0.4852632
#> feature.2 0.4646465
#> feature.3 0.4517045
#> feature.4 0.4766187
#> feature.5 0.4556962
#> feature.6 0.4146341