Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

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.

share|improve this question

1 Answer

up vote 4 down vote accepted

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.

share|improve this answer
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.