Jeromy Anglim's Blog: Psychology and Statistics


Friday, November 7, 2008

Using R to test for significant differences between two nonindependent correlations

I was recently asked about a quick and easy way to see whether the correlation between IV1 and DV is statistically significantly different from IV2 and DV. The follow post set out how this analysis can be conducted in R. The instructions assume that you have never used R before and are running Windows.

1) Download and install R for windows

2) Install the psych package
Run the following line of code in the command prompt
install.packages("psych")

3) Load psych package
Run this code
library(psych)

4) Run the test
Enter code like this:

paired.r(.2,.3,.93,100)

This above code tests whether correlation of 0.20 is statistically different from 0.30 given that the two predictor variables are correlated 0.93, assuming a sample size of 100.

The output in R looks like this:
paired.r(.2,.3,.93,100)
$test
[1] "test of difference between two correlated correlations"
$t
[1] -2.832009
$p
[1] 0.005614689

It could be written up as:
The correlation between IV1 and DV (r = 0.30) was significantly larger than the correlation between IV2 and DV (r = 0.20), n=100, p=0.006.