Skip to contents

Correlates each column of x with each column of y, as cor does, with Pearson's, Kendall's (tau-b) or Spearman's coefficient, and tests each correlation for zero, as cor.test does.

Usage

gpuCor(x, y = NULL, use = "everything", method = "pearson",
    test = FALSE, precision = getOption("gputools.precision", "single"))

Arguments

x

a numeric matrix whose columns are the variables.

y

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

use

"everything" (a variable with a missing value gives NA) or "pairwise.complete.obs" (each pair of variables uses the rows where both are present), as with cor.

method

"pearson", "kendall" or "spearman".

test

TRUE to also return p-values (and Kendall's z), as cor.test would. They are computed on the CPU, at about 0.3 microseconds each: negligible for hundreds of variables, but for thousands (millions of pairs) they take longer than the correlations.

precision

"single" or "double": the floating point precision the GPU computes in. Single precision is the default, set with options(gputools.precision = "double"); it runs many times faster on most consumer GPUs. Results are returned as doubles either way.

Details

Kendall's coefficient is tau-b and Spearman's is Pearson's on the ranks, ties averaged; with use = "pairwise.complete.obs", each pair is ranked over its complete rows only. All three match cor.

The p-values are two-sided and match cor.test: exactly for Pearson's (a t test on pairs - 2 degrees of freedom), and as cor.test(exact = FALSE) gives them for Spearman's (the same t approximation) and Kendall's (a normal approximation with the tie correction). cor.test's exact small-sample tests for the rank coefficients are not computed.

Value

A list of matrices, each with a row per column of x and a column per column of y, named as cor names them:

coefficients

the correlations.

ts

for Pearson's and Spearman's, the t statistics, \(r \sqrt{(n - 2) / (1 - r^2)}\).

z

for Kendall's, with test = TRUE, the normal statistics.

p.value

with test = TRUE, the two-sided p-values.

pairs

the number of rows each correlation used.

See also

Examples

if (FALSE) { # gpuAvailable()
numAvars <- 5
numBvars <- 10
numSamples <- 30
A <- matrix(runif(numAvars*numSamples), numSamples, numAvars)
B <- matrix(runif(numBvars*numSamples), numSamples, numBvars)
gpuCor(A, B, method="pearson")
gpuCor(A, B, method="kendall")
gpuCor(A, B, method="spearman", test=TRUE)$p.value
A[3,2] <- NA
gpuCor(A, B, use="pairwise.complete.obs", method="pearson")
}