corAndPvalue: Calculation of correlations and associated p-values

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/corAndPvalue.R

Description

A faster, one-step calculation of Student correlation p-values for multiple correlations, properly taking into account the actual number of observations.

Usage

1
2
3
4
corAndPvalue(x, y = NULL, 
             use = "pairwise.complete.obs", 
             alternative = c("two.sided", "less", "greater"),
             ...)

Arguments

x

a vector or a matrix

y

a vector or a matrix. If NULL, the correlation of columns of x will be calculated.

use

determines handling of missing data. See cor for details.

alternative

specifies the alternative hypothesis and must be (a unique abbreviation of) one of "two.sided", "greater" or "less". the initial letter. "greater" corresponds to positive association, "less" to negative association.

...

other arguments to the function cor.

Details

The function calculates correlations of a matrix or of two matrices and the corresponding Student p-values. The output is not as full-featured as cor.test, but can work with matrices as input.

Value

A list with the following components, each a matrix:

cor

the calculated correlations

p

the Student p-values corresponding to the calculated correlations

Z

Fisher transforms of the calculated correlations

t

Student t statistics of the calculated correlations

nObs

Numbers of observations for the correlation, p-values etc.

Author(s)

Peter Langfelder and Steve Horvath

References

Peter Langfelder, Steve Horvath (2012) Fast R Functions for Robust Correlations and Hierarchical Clustering. Journal of Statistical Software, 46(11), 1-17. https://www.jstatsoft.org/v46/i11/

See Also

cor for calculation of correlations only;

cor.test for another function for significance test of correlations

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# generate random data with non-zero correlation
set.seed(1);
a = rnorm(100);
b = rnorm(100) + a;
x = cbind(a, b);
# Call the function and display all results
corAndPvalue(x)
# Set some components to NA
x[c(1:4), 1] = NA
corAndPvalue(x)
# Note that changed number of observations.

Example output

Loading required package: dynamicTreeCut
Loading required package: fastcluster

Attaching package: 'fastcluster'

The following object is masked from 'package:stats':

    hclust


==========================================================================
*
*  Package WGCNA 1.61 loaded.
*
sh: 1: wc: Permission denied
sh: 1: cannot create /dev/null: Permission denied
sh: 1: wc: Permission denied
sh: 1: cannot create /dev/null: Permission denied
sh: 1: wc: Permission denied
sh: 1: cannot create /dev/null: Permission denied
*    Important note: It appears that your system supports multi-threading,
*    but it is not enabled within WGCNA in R. 
*    To allow multi-threading within WGCNA with all available cores, use 
*
*          allowWGCNAThreads()
*
*    within R. Use disableWGCNAThreads() to disable threading if necessary.
*    Alternatively, set the following environment variable on your system:
*
*          ALLOW_WGCNA_THREADS=<number_of_processors>
*
*    for example 
*
*          ALLOW_WGCNA_THREADS=2
*
*    To set the environment variable in linux bash shell, type 
*
*           export ALLOW_WGCNA_THREADS=2
*
*     before running R. Other operating systems or shells will
*     have a similar command to achieve the same aim.
*
==========================================================================



Attaching package: 'WGCNA'

The following object is masked from 'package:stats':

    cor

$cor
          a         b
a 1.0000000 0.6836311
b 0.6836311 1.0000000

$p
             a            b
a 0.000000e+00 4.583225e-15
b 4.583225e-15 0.000000e+00

$Z
         a        b
a      Inf 8.274985
b 8.274985      Inf

$t
         a        b
a      Inf 9.272878
b 9.272878      Inf

$nObs
    a   b
a 100 100
b 100 100

$cor
          a         b
a 1.0000000 0.6699188
b 0.6699188 1.0000000

$p
            a           b
a 0.00000e+00 8.40745e-14
b 8.40745e-14 0.00000e+00

$Z
         a        b
a      Inf 7.859018
b 7.859018      Inf

$t
         a        b
a      Inf 8.748388
b 8.748388      Inf

$nObs
   a   b
a 96  96
b 96 100

WGCNA documentation built on March 1, 2021, 1:05 a.m.

Related to corAndPvalue in WGCNA...