cor_perm: Permutation Tests for Multiple Correlations

Description Usage Arguments Details Value See Also Examples

View source: R/cor_perm.R

Description

Calculates the empirical probabilities of obtaining correlation coefficients equal or greater in squared magnitude than the ones observed, given the null hypothesis that the true correlations all equal 0.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
cor_perm(
  x,
  y = NULL,
  use = "pairwise",
  method = "pearson",
  n_perm = 10000,
  seed = 42,
  n_cores = NULL,
  ...
)

Arguments

x

a numeric matrix or data frame.

y

NULL (default) or a matrix or data frame with compatible dimensions to x. The default is equivalent to y = x (but more efficient).

use

an optional character string giving a method for computing covariances in the presence of missing values. This must be (an abbreviation of) one of the strings "everything", "all.obs", "complete.obs", "na.or.complete", or "pairwise.complete.obs" (default).

method

a character string indicating which correlation coefficient is to be computed. One of "pearson" (default), "kendall", or "spearman": can be abbreviated.

n_perm

The number of permutations.

seed

Integer used to seed the random number generator.

n_cores

Integer indicating number of processes to be used in parallel processing. Set to 1 fewer than the number of available CPUs by default.

Details

To calculate permutation-based P values for all bivariate relationships between the columns of X and the columns of Y, the observations in each column of X are randomly reshuffled (which simulates how the data would be distributed if the null hypothesis were true), and all bivariate correlations between the reshuffled X and Y are recalculated, with the largest squared coefficient recorded. This procedure is repeated n_perm times to construct an empirical sampling distribution of the largest correlation that one obtains by chance when the null hypothesis is true and one computes the same number of correlations. The correlations calculated from the real data are then squared and compared to this distribution to determine an empirical adjusted P value. If n permutations were carried out and r of the n largest squared coefficients are equal to or greater than a given squared coefficient from the actual correlation matrix, then the empirical adjusted P value for that coefficient is given by (r + 1)/(n + 1), i.e., the frequency of values in the null distribution that are at least as large as what was observed, with an added constant of 1 to prevent a probability of 0 in the event that the observed value lies entirely outside the null distribution.

Value

Object of class "cor_perm", containing a cor_list object with an additional vector of empirically adjusted p-values that correct for multiple testing.

See Also

cor_test, cor_list,

Examples

1
2
# Create a correlation list for the numeric variables from the iris data set
cor_perm(iris[,-5], n_perm = 1000)

jashu/corxplor documentation built on Dec. 10, 2019, 7:09 p.m.