# Permutation tests in R for correlations

What's the easiest way to run permutation tests for a bivariate Pearson correlation matrix in R?

I have tried running MPT.Corr, Multivariate Permutation Test for Correlations by Urbano Blackford et al., but I am not sure this function is applicable to the problem.

The data contains mainly Likert scale items and time measures. At least one nominal variable needs to be entered as a covariate - i.e. controlled for.

-

This is fairly simple to do using R code without needing a special function, here is an example:

library(plyr)

tmpfun <- function() {
tmp <- ddply( iris, .(Species), function(df) {
data.frame( Petal.Width=df$Petal.Width, Sepal.Width=sample( df$Sepal.Width ) ) } )
cor(tmp$Petal.Width, tmp$Sepal.Width)
}

out <- c( cor(iris$Petal.Width, iris$Sepal.Width),
replicate(999, tmpfun()) )

hist(out)
abline(v=out[1], col='red')
mean( out >= out[1] )


This uses the plyr package to do the permuting within levels of Species to adjust for it.

-
 Thanks. Looks good. I was not aware of plyr. Migrating from SPSS, it seems - at first sight - to be an advanced version of Data/Aggregate. – noumenal Apr 27 '12 at 22:20