Learn R Programming

ccaPP (version 0.1.1)

permTest: (Robust) permutation test for independence

Description

Test for independence of two data sets, with a focus on robust and nonparametric correlation measures.

Usage

permTest(x, y, R = 1000, ccaFun = ccaGrid, nCores = 1,
    cl = NULL, seed = NULL, ...)

Arguments

x,y
each can be a numeric vector, matrix or data frame.
R
an integer giving the number of random permutations to be used.
ccaFun
a function to compute a maximum correlation measure between two data sets, e.g., ccaGrid (the default) or ccaProj. It should expect the data to be p
nCores
a positive integer giving the number of processor cores to be used for parallel computing (the default is 1 for no parallelization). If this is set to NA, all available processor cores are used.
cl
a parallel cluster for parallel computing as generated by makeCluster. This is ignored if nCores is supplied.
seed
optional integer giving the initial seed for the random number generator (see .Random.seed). For parallel computing, random number streams are used rather than the standard random number gener
...
additional arguments to be passed to ccaFun.

Value

  • An object of class "permTest" with the following components:
  • pValuethe $p$-value for the test.
  • cor0the value of the test statistic.
  • corthe values of the test statistic for each of the permutated data sets.
  • Rthe number of random permutations.
  • seedthe seed of the random number generator.
  • callthe matched function call.

Details

The test generates R data sets by randomly permuting the observations of x, while keeping the observations of y fixed. In each replication, a function to compute a maximum correlation measure is applied to the permuted data sets. The $p$-value of the test is then given by the percentage of replicates of the maximum correlation measure that are larger than the maximum correlation measure computed from the original data.

See Also

ccaGrid, ccaProj

Examples

Run this code
## generate data
library("mvtnorm")
set.seed(1234)  # for reproducibility
p <- 3
q <- 2
m <- p + q
sigma <- 0.5^t(sapply(1:m, function(i, j) abs(i-j), 1:m))
xy <- rmvnorm(100, sigma=sigma)
x <- xy[, 1:p]
y <- xy[, (p+1):m]

## Spearman correlation
permTest(x, y, R=100, method = "spearman")
permTest(x, y, R=100, method = "spearman", consistent = TRUE)

## Pearson correlation
permTest(x, y, R=100, method = "pearson")

Run the code above in your browser using DataLab