[R] How to test the difference between paired correlations?
m@rong|u@|u|g| @end|ng |rom gm@||@com
Wed Mar 22 22:12:23 CET 2023
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".
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
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,
v2 <- c(56.814, 42.005, 56.074, 65.990, 81.572, 53.855, 50.335, 63.537, 41.713,
v3 <- c(54.170, 64.224, 57.569, 85.089, 104.056, 48.713, 61.239, 60.290,
# visual exploration
plot(v2~v1, ylim=c(min(c(v1,v2,v3)), max(c(v1,v2,v3))),
main="V1 vs V2")
plot(v3~v1, ylim=c(min(c(v1,v2,v3)), max(c(v1,v2,v3))),
main="V1 vs V3")
## test differences in correlation
# convert raw data into z-scores
FisherZ(v1) # I cannot convert the raw data into z scores (same for
the other variables):
>  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?)
# apply test
v1_v2 = FisherZ(lm(v2~v1)$coefficients)
v1_v3 = FisherZ(lm(v3~v1)$coefficients)
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)
>  "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?
More information about the R-help