Skip to content
Prev 67812 / 398506 Next

Pearson corelation and p-value for matrix

Here is what might be a slightly more efficient way to get to John's
question:

cor.pvals <- function(mat)
{
  rows <- expand.grid(1:nrow(mat), 1:nrow(mat))
  matrix(apply(rows, 1,
               function(x) cor.test(mat[x[1], ], mat[x[2], ])$p.value),
         ncol = nrow(mat))
}

HTH,

Marc Schwartz
On Fri, 2005-04-15 at 18:26 -0400, John Fox wrote: