Skip to contents

Tests every correlation between the columns of x and those of y (or among the columns of x) by permutation: the rows of y are shuffled B times and each correlation's p-value is how often a shuffle gives one as strong. It also gives p-values adjusted for testing all the pairs at once, by Westfall and Young's maxT. Permutation p-values need no assumption of normality, which for small samples and skewed data the t test of gpuCor makes; each shuffle costs a whole correlation matrix, which the GPU computes in one matrix product.

Usage

gpuCorPerm(x, y = NULL, B = 1000L, method = "pearson",
    precision = getOption("gputools.precision", "single"))

Arguments

x

a numeric matrix whose columns are the variables, with no missing values.

y

a numeric matrix with the same number of rows, or NULL for x with itself.

B

the number of permutations. The smallest p-value possible is \(1 / (B + 1)\).

method

"pearson" or "spearman".

precision

"single" or "double": the floating point precision the GPU computes in; see gpuCor.

Details

The permutations are drawn with sample.int, so set.seed makes the results reproducible. Each is applied to the rows of y (of a copy of x when y is NULL), and all of a permutation's correlations are computed from it, so the tests share their permutations, as the maxT adjustment needs.

The p-value of a correlation \(r\) is \((1 + b) / (1 + B)\), where \(b\) of the \(B\) permutations gave a correlation with \(|r_b| \ge |r|\): two-sided, and counting the observed data as one of the permutations (Phipson and Smyth 2010), so that it is never zero. The adjusted p-value counts instead the permutations whose largest \(|r_b|\) over all the tests reaches \(|r|\): single-step maxT (Westfall and Young 1993), which controls the family-wise error rate.

The whole ncol(x) by ncol(y) matrix is held on the GPU, twice; for wider data, split the columns of y (the maxT adjustment is then within each part).

Value

A list:

coefficients

the correlations, as cor gives them.

p.value

the permutation p-values.

p.adjusted

the maxT adjusted p-values.

permutations

B.

With y = NULL the diagonal is NA.

References

Westfall, P. H. and Young, S. S. (1993) Resampling-Based Multiple Testing. Wiley.

Phipson, B. and Smyth, G. K. (2010) Permutation p-values should never be zero. Statistical Applications in Genetics and Molecular Biology 9, 39.

See also

Examples

if (FALSE) { # gpuAvailable()
set.seed(1)
# 15 samples of skewed data; one real association
x <- matrix(rexp(15 * 40), 15, 40)
y <- matrix(rexp(15 * 30), 15, 30)
y[, 1] <- y[, 1] + 2 * x[, 1]
res <- gpuCorPerm(x, y, B = 2000)
res$p.value[1, 1]
res$p.adjusted[1, 1]
min(res$p.adjusted[-1, -1])
}