Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Significance test on the difference of two correlation coefficient

How do you test if two correlation coefficients are signficantly different - in GNU R?

That is, if the effect between the same variables (e.g., age and income) is different in two different populations (subsamples).

For background information see How do I compare correlation coefficients of the same variables across different groups and Significance test on the difference of Spearman's correlation coefficient (both at CrossValidated).

like image 597
BurninLeo Avatar asked Jan 25 '13 09:01

BurninLeo


Video Answer


1 Answers

Here is a ready-to-use function for GNU R if you want to compare multiple pairs of coefficients (based on Significance of the difference between two correlation coefficients and Quantitative Analysis and Politics, PDF):

cor.diff.test = function(r1, r2, n1, n2, alternative = c("two.sided", "less", "greater")) {

  Z1 = 0.5 * log( (1+r1)/(1-r1) )
  Z2 = 0.5 * log( (1+r2)/(1-r2) )

  diff = Z1 - Z2
  SEdiff = sqrt( 1 / (n1 - 3) + 1 / (n2 - 3))
  diff.Z = diff / SEdiff

  if (alternative == "less") {
    return(pnorm(diff.Z, lower.tail=F))
  } else if (alternative == "greater") {
    return(pnorm(-diff.Z, lower.tail=F))
  } else if (alternative == "two.sided") {
    return(2 * pnorm( abs(diff.Z), lower.tail=F))
  } else {
    warning(paste("Invalid alterantive", alternative), domain=NA)
    return(NA)
  }
}
like image 93
BurninLeo Avatar answered Nov 10 '22 01:11

BurninLeo