Skip to content

Instantly share code, notes, and snippets.

@adampeg
Created February 10, 2017 15:39
#Mengs example
cors <- c(.63, .53, .54, -.03) # put correlation coefficients (Xs -> Y) in here
zs <- fisherz(cors)
rs <- fisherz2r(zs)
round(zs,2)
mz <- mean(zs)
zmz <- zs-mz
zmz2 <- zmz*zmz
n <- 15
r <- c(.63, .53, .54, -.03) # put correlation coefficients (Xs -> Y) in here
rc <- matrix(r.con(r,n),ncol=2)
t <- r*sqrt(n-2)/sqrt(1-r^2)
p <- (1-pt(t,n-2))/2
square <-r*r
r.rc <- data.frame(r=r,z=fisherz(r),lower=rc[,1],upper=rc[,2],t=t,p=p,rsquare=square,zmz=zmz, zmz2 = zmz2)
round(r.rc,3)
#average r square
avrsqur <- mean(square)
#sum of fishers z- mean fishers z
sumzmz <- sum(zmz2)
#enter median intercorrelation of Xs
mi <- (.37)
#find f
f <- (1-mi)/(2*(1-avrsqur))
f
#0.4158828, .4159 to 2dp as given in example
#find h
h <- (1-(f*avrsqur))/(1-avrsqur)
h
#1.187071, 1.1871 to 2dp as given in example
#find chi-square (k-1)
chisqu1 <- (n-3)*sumzmz
chisqu2 <- (1-mi)*h
chisqu <- chisqu1/chisqu2
chisqu
# 5.711426
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment