Skip to content

Instantly share code, notes, and snippets.

@sTeamTraen
Last active September 19, 2022 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sTeamTraen/eea2d7754f39653cd1884e29df84953c to your computer and use it in GitHub Desktop.
Save sTeamTraen/eea2d7754f39653cd1884e29df84953c to your computer and use it in GitHub Desktop.
# Compare multiple correlations to see if they are similar.
# See http://home.ubalt.edu/ntsbarsh/business-stat/opre504.htm#rmulticorr
# By Nick Brown (nicholasjlbrown@gmail.com), September 2022. Licence: CC-0.
r_to_z <- function (r) {
(log(1 + r) - log(1 - r)) / 2
}
many_corr <- function (vec.z, vec.n) {
tot1 <- 0
tot2 <- 0
tot3 <- 0
for (i in 1:length(vec.z)) {
z <- vec.z[i]
nm3 <- vec.n[i] - 3
tot1 <- tot1 + (nm3 * (z ^ 2))
tot2 <- tot2 + (nm3 * z)
tot3 <- tot3 + nm3
}
tot1 - ((tot2 ^ 2) / tot3)
}
print_many_corr <- function (vec.r, vec.n) {
chisq <- many_corr(r_to_z(vec.r), vec.n)
cat("Chi-square statistic = ", sprintf("%.3f", chisq), "\n", sep="")
df <- length(vec.r) - 1
cat("DF = ", df, "\n", sep="")
p <- pchisq(chisq, df, lower.tail=FALSE)
cat("p value = ", sprintf("%.3f", p), "\n", sep="")
}
# Example from Granhag et al. 2013 "Eliciting intelligence from sources" 10.1111/lcrp.12015, p. 107
# "However, the three correlations did not differ significantly from each other"
r.granhag <- c(0.42, 0.41, 0.22)
n.granhag <- c(32, 31, 30)
print_many_corr(r.granhag, n.granhag)
# Example from http://home.ubalt.edu/ntsbarsh/business-stat/opre504.htm#rmulticorr
r.arsham <- c(0.72, 0.41, 0.57, 0.53, 0.62, 0.21, 0.68, 0.53, 0.49, 0.50)
n.arsham <- c(67, 93, 73, 98, 82, 39, 91, 27, 75, 49)
print_many_corr(r.arsham, n.arsham)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment