[R] How to test the difference between paired correlations?

Luigi Marongiu m@rong|u@|u|g| @end|ng |rom gm@||@com
Wed Mar 22 22:12:23 CET 2023


Hello,
I have three numerical variables and I would like to test if their
correlation is significantly different.
I have seen that there is a package that "Test the difference between
two (paired or unpaired) correlations".
[https://www.personality-project.org/r/html/paired.r.html]
However, there is the need to convert the correlations to "z scores
using the Fisher r-z transform". I have seen that there is another
package that does that
[https://search.r-project.org/CRAN/refmans/DescTools/html/FisherZ.html].
Yet, I do not understand how to process the data. Shall I pass the raw
data or the correlations directly?

I have made the following working example:
```
# define data
v1 <- c(62.480,  59.492,  74.060,  88.519,  91.417,  53.907,  64.202,  62.426,
        54.406,  88.117)
v2 <- c(56.814, 42.005, 56.074, 65.990, 81.572, 53.855, 50.335, 63.537, 41.713,
        78.265)
v3 <- c(54.170,  64.224,  57.569,  85.089, 104.056,  48.713,  61.239,  60.290,
        67.308,  71.179)
# visual exploration
par(mfrow=c(2, 1))
plot(v2~v1, ylim=c(min(c(v1,v2,v3)), max(c(v1,v2,v3))),
     xlim=c(min(c(v1,v2,v3)), max(c(v1,v2,v3))),
     main="V1 vs V2")
abline(lm(v2~v1))
plot(v3~v1, ylim=c(min(c(v1,v2,v3)), max(c(v1,v2,v3))),
     xlim=c(min(c(v1,v2,v3)), max(c(v1,v2,v3))),
     main="V1 vs V3")
abline(lm(v3~v1))
## test differences in correlation
# convert raw data into z-scores
library(psych)
library(DescTools)
FisherZ(v1) # I cannot convert the raw data into z scores (same for
the other variables):
> [1] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
> Warning message:
> In log((1 + rho)/(1 - rho)) : NaNs produced
# convert correlations into z scores
# (the correlation score of 0.79 has been converted into 1.08; is this correct?)
FisherZ(lm(v2~v1)$coefficients[2])
>      v1
> 1.081667
lm(v2~v1)$coefficients[2]
>       v1
> 0.7938164
# apply test
v1_v2 = FisherZ(lm(v2~v1)$coefficients[2])
v1_v3 = FisherZ(lm(v3~v1)$coefficients[2])
paired.r(v1_v2, v1_v3, yz=NULL, length(v1), n2=NULL, twotailed=TRUE)
> Call: paired.r(xy = v1_v2, xz = v1_v3, yz = NULL, n = length(v1), n2 = NULL,
>    twotailed = TRUE)
> [1] "test of difference between two independent correlations"
> z = NaN  With probability =  NaNWarning messages:
> 1: In log((1 + xy)/(1 - xy)) : NaNs produced
> 2: In log((1 + xz)/(1 - xz)) : NaNs produced
```

What is the right way to run this test?
Shall I apply also yz?
Thank you

-- 
Best regards,
Luigi



More information about the R-help mailing list