Friday 13 March 2015

Testing if two correlations are significantly different

I had two variables var1, var2, var3, and wanted to test whether the correlation between var1 and var3 is significantly different from the correlation between var2 and var3. I found a nice blog post by Jeromy Anglim explaining how to do this in R:

> var1  <- c(14.1,31.5,102.9,26.8,30.6,18.4,11.1,6.3,4.9,3.1,4.1,4.0,4.7)
> var2 <- c(54.9,18.3, 151.7, 53.6, 44.8,30.5,26.9,23.3,18.8,35.3,21.4,21.6,27.6)
> var3 <- c(84.7,63.5,272.8,94.1,100.3,74.6,53.0,47.3,49.4,60.5,43.1,42.8,52.2)
> cor.test(var1,var3,method="spearman")
> cor.test(var2,var3,method="spearman")
> cor.test(var1,var2, method="spearman")

Now test whether a correlation of 0.80 is significantly different from 0.77 given that the two predictor variables (var1, var2) are correlated 0.37, assuming a sample size of 13:
> library(psych)
> paired.r(0.7692308,0.8021978,0.3736264,13)
Call: paired.r(xy = 0.7692308, xz = 0.8021978, yz = 0.3736264, n = 13)
[1] "test of difference between two correlated  correlations"
t = -0.22  With probability =  0.83

This tells us that the correlation between var1 and var3 (r=0.80) was not significantly different than the correlation between var2 and var3 (r=77), n=13, p=0.83 (t-test).

Thanks to Jeromy Anglim!