Marc,
Off the top my head (i.e. this could all be horribly wrong), I think
Anderson gave an asymptotic version for such a test, whereby under the
null hypothesis, the difference between Fisher's z for each sample, z1 -
z2, is normal with zero mean. If I recall correctly, the 1984 edition
gave a test statistic something like:
$\frac{\vert z_{1} - z_{2} \rvert}{ \sqrt{\frac{1}{N_{1} - 3} +
\frac{1}{N_{2} - 3}}}$,
as the test. I ***think*** N = n+1. Assuming that part is correct,
it can be coded up quite simply (and crudely and hopefully correctly)
as:
## estimate Fisher's z for the sample
fishz <- function(x1,x2){
r <- cor(x1,x2)
z <- 0.5 * log( (1+r)/(1-r) )
}
## apply the correlation test
cortest <- function(x1,x2,x3,x4){
numer <- abs(fishz(x1,x2) - fishz(x3,x4) )
denom <- sqrt( 1/( length(x1) - 2) + 1/( length(x2) - 2) )
test.stat <- numer / denom
return(test.stat)
}
A quick demo with some simulated data:
require(MASS)
X1 <- mvrnorm(1000, c(0,0), matrix(c(1,0.7,0.7,1),2,2))
X2 <- mvrnorm(1000, c(0,0), matrix(c(1,0.9,0.9,1),2,2))
cortest(X1[,1], X1[,2], X2[,1], X2[,2])
Is above 1.96 indicating they are different
X2 <- mvrnorm(1000, c(0,0), matrix(c(1,0.7,0.7,1),2,2))
cortest(X1[,1], X1[,2], X2[,1], X2[,2])
Is below 1.96 indicating they are not different. All that needs to be
done for these pair is to get the pooled estimate of the populations
Fisher's z $ \frac{ (N_{1} - 3)z_{1} + (N_{2} - 3)z_{2}}{N_{1} + N_{2} -
6}$ and solve fisher's z to get an estimate of rho.
Just dabbling around with this suggests either I've missed something, or
that we need quite a large sample size before the asymptotics are any
use. If this is of any use I'll double check on N.
Paul
-=-=-=-=-=-=-=-=-=-=-=-Paul Hewson
Lecturer in Statistics
School of Mathematics and Statistics
University of Plymouth
Drake Circus
Plymouth PL4 8AA
tel (01752) 232778 (Campus)
tel (01752) 764437 (Tamar Science Park)
fax (01752) 232780
email: paul.hewson at plymouth.ac.uk
web: http://www.plymouth.ac.uk/staff/phewson
-=-=-=-=-=-=-=-=-=-=-=-
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Marc Bernard
Sent: 27 September 2006 14:42
To: r-help at stat.math.ethz.ch
Subject: [R] Testing the equality of correlations
Dear All,
I wonder if there is any implemented statistical test in R to test
the equality between many correlations. As an example, let X1, X2, X3
X4 be four random variables. let
Phi(X1,X2) , Phi(X1,X3) and Phi(X1,X4) be the corresponding
correlations.
How to test Phi(X1,X2) = Phi(X1,X3) = P(X1,X4)?
Many thanks in advance,
Bernard
---------------------------------
[[alternative HTML version deleted]]
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.