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

John C Frain |r@|nj @end|ng |rom gm@||@com
Thu Mar 23 22:26:37 CET 2023

1. estimate r
2. do the z transformation - z is a simple function of r - z has an
approximate standard normal distribution.
3. use the normal distribution tables to decide on the significance of z
or of differences between two z's.

I don't see the need for packages.
John C Frain
3 Aranleigh Park
Rathfarnham
Dublin 14
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
https://jcfrain.wordpress.com/
https://jcfraincv19.wordpress.com/

mailto:frainj using tcd.ie
mailto:frainj using gmail.com

On Thu, 23 Mar 2023 at 09:30, Luigi Marongiu <marongiu.luigi using gmail.com>
wrote:

> Thank you, but this now sounds more difficult: what would be the point
> in having these ready-made functions if I have to do it manually?
> Anyway, How would I implement the last part?
>
> On Thu, Mar 23, 2023 at 1:23 AM Ebert,Timothy Aaron <tebert using ufl.edu>
> wrote:
> >
> > If you are open to other options:
> > The null hypothesis is that there is no difference.
> >    If I have two equations y=x and y=z and there is no difference then
> it would not matter if an observation was from x or z.
> >    Randomize the x and z observations. For each randomization calculate
> a correlation for y=x and for y=z.
> >    At each iteration calculate the absolute value of the difference in
> the correlations.
> >    Generate a frequency distribution from 100,000+ randomizations.
> >    Find the observed difference in the frequency from random
> distributions.
> >    What proportion of observations are as large or larger than the
> observed. This is your p-value.
> >
> > Tim
> >
> > -----Original Message-----
> > From: R-help <r-help-bounces using r-project.org> On Behalf Of Luigi Marongiu
> > Sent: Wednesday, March 22, 2023 5:12 PM
> > To: r-help <r-help using r-project.org>
> > Subject: [R] How to test the difference between paired correlations?
> >
> > [External Email]
> >
> > 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".
> > [
> ]
> > 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,
> >         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
> >
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >
> > and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Best regards,
> Luigi
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help