Perform a permutation correlation test on every row of a matrix
Source:R/permutation.R
      permutation_correlation_test.RdCompute 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.0634590 0.5762059 0.97293487 0.1154842 0.42996696 0.37758118
#> feature.2 0.1350959 0.9337619 0.33100403 0.6728114 0.42217237 0.12568521
#> feature.3 0.8281568 0.8837198 0.42763149 0.8782941 0.08691266 0.62992541
#> feature.4 0.1656223 0.9048490 0.20599942 0.2188856 0.72180715 0.06151645
#> feature.5 0.3646320 0.8638160 0.03208898 0.2540279 0.90560364 0.07628601
#> feature.6 0.5541322 0.3211157 0.62031350 0.3773386 0.27895253 0.42494342
#>            sample.7  sample.8  sample.9 sample.10          cor empirical.p
#> feature.1 0.5237202 0.6930965 0.2750768 0.3286633  0.006060606       0.463
#> feature.2 0.8911154 0.6401472 0.6639770 0.9694662  0.369696970       0.118
#> feature.3 0.2291625 0.7712375 0.6758761 0.9199889 -0.006060606       0.505
#> feature.4 0.7414698 0.7244465 0.4384446 0.8576476  0.333333333       0.153
#> feature.5 0.4319108 0.1560931 0.1295175 0.9407493  0.090909091       0.386
#> feature.6 0.9827271 0.9530085 0.4726221 0.4141785  0.187878788       0.322
#>                 FDR
#> feature.1 0.4873950
#> feature.2 0.4572491
#> feature.3 0.5070281
#> feature.4 0.4579710
#> feature.5 0.4815642
#> feature.6 0.4772727