A matrix version of cor.test()

Atticus29 picture Atticus29 · Oct 28, 2012 · Viewed 36k times · Source

Cor.test() takes vectors x and y as arguments, but I have an entire matrix of data that I want to test, pairwise. Cor() takes this matrix as an argument just fine, and I'm hoping to find a way to do the same for cor.test().

The common advice from other folks seems to be to use cor.prob():

https://stat.ethz.ch/pipermail/r-help/2001-November/016201.html

But these p-values are not the same as those generated by cor.test()!!! Cor.test() also seems better equipped to handle pairwise deletion (I have quite a bit of missing data in my data set) than cor.prob().

Does anybody have any alternatives to cor.prob()? If the solution involves nested for loops, so be it (I'm new enough to R for even this to be problematic for me).

Answer

Sacha Epskamp picture Sacha Epskamp · Oct 28, 2012

corr.test in the psych package is designed to do this:

library("psych")
data(sat.act)
corr.test(sat.act)

As noted in the comments, to replicate the p-values from the base cor.test() function over the entire matrix, then you need to turn off adjustment of the p-values for multiple comparisons (the default is to use Holm's method of adjustment):

 corr.test(sat.act, adjust = "none")

[But be careful when interpreting those results!]