A faster, one-step calculation of Student correlation p-values for multiple correlations, properly taking into account the actual number of observations.
corAndPvalue(x, y = NULL,
use = "pairwise.complete.obs",
alternative = c("two.sided", "less", "greater"),
...)
A list with the following components, each a matrix:
the calculated correlations
the Student p-values corresponding to the calculated correlations
Fisher transforms of the calculated correlations
Student t statistics of the calculated correlations
Numbers of observations for the correlation, p-values etc.
a vector or a matrix
a vector or a matrix. If NULL
, the correlation of columns of x
will be calculated.
determines handling of missing data. See cor
for details.
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
.
Peter Langfelder and Steve Horvath
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.
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/
# 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.
Run the code above in your browser using DataLab