Skip to content

Instantly share code, notes, and snippets.

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 adampeg/7a99c0e4032703e713b8a621313bfbb6 to your computer and use it in GitHub Desktop.
Save adampeg/7a99c0e4032703e713b8a621313bfbb6 to your computer and use it in GitHub Desktop.
#Confidence intervals around meta-analysed Pearson's rs
#equation 4 from Bonett, D. G. (2008).
#Meta-analytic interval estimation for bivariate correlations.
#Psychological methods, 13(3), 173.
#WHAT YOU NEED TO ENTER: Correlation coefficients (cors) and sample size (ns) for each coefficient, plus number of coefficients (m)
#Script for following along with example on p. 177
#input correlation coefficients
cors <-c(.40,.65,.60,.45)
#input sample sizes
ns <-c(55, 190, 65, 35)
n3 <- ns-3
corsq <- cors*cors
corsq2 <- 1-corsq
corsq3 <- (corsq2)^2
corsq4 <- corsq3/n3
r.rc <- data.frame(cors = cors, ns = ns, n3 = n3, corsq = corsq, corsq2 = corsq2, corsq3 = corsq3, corsq4 = corsq4)
round(r.rc,3)
#input number of correlation coefficients HERE (m)
m <- 4
mmin2 <-m^-2
#estimated variance p hat
v <- sum(corsq4)*mmin2
# = .00261
#point estimate p hat (just mean average of coefficients)
pe <-mean(cors)
#=.525
#get tanh-1 (p hat)
numertan1 <- (1+pe)
numertan2 <- (1-pe)
numertan3 <- log(numertan1, base = exp(1))
numertan4 <- log(numertan2, base = exp(1))
numertan5 <- numertan3 - numertan4
tanh1 <- numertan5/2
tanh1
# = .583
#get estimated variance of tanh-1 (p hat)
dvartanh <- (1-(pe^2))^2
vartanh <- v/dvartanh
vartanh
# = .00498
#Lower 95% confidence interval
lci1 <- vartanh^.5
lci2 <-1.96*lci1
lci3 <- tanh1-lci2
LCI <-tanh(lci3)
LCI
# = .41766
#Upper 95% confidence interval
uci1 <- vartanh^.5
uci2 <-1.96*uci1
uci3 <- tanh1+uci2
UCI <-tanh(uci3)
UCI
# = .61788
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment