﻿/*========================================================= File name: 6_Williams_test.txt Written by: Karl L. Wuensch, WuenschK@ECU.edu Date: 10-September-2012. =========================================================== The user wants the difference r12 - r13. Let r12 = correlation between father's height and mother's height. Let r13 = correlation between father's height and mother's weight. Therefore, r23 = correlation between mother's height and mother's weight. Compare r12 and r13 in each of the 4 areas. */ data williams; input r12 r13 r23 n alpha Note \$25.; R=(1-r12**2-r13**2-r23**2)+2*r12*r13*r23; diff=r12-r13; t=diff*SQRT(((n-1)*(1+r23))/(2*((n-1)/(n-3))*R+((r12+r13)**2/4)*(1-r23)**3)); SEdiff=1/SQRT(((n-1)*(1+r23))/(2*((n-1)/(n-3))*R+((r12+r13)**2/4)*(1-r23)**3)); df=n-3; tneg=0-abs(t); p=2*probt(tneg,df); *Use method of Zou (2007, p. 409) to compute CI for rho12 - rho13; num=(r23-.5*r12*r13)*(1-r12**2-r13**2-r23**2)+r23**3; denom=(1-r12**2)*(1-r13**2); corr12_13=num/denom; cump=1-alpha/2; CV=PROBIT(cump); *CV = critical value of z; SE=SQRT(1/(n-3)); rprime12=0.5*log(abs((1+r12)/(1-r12))); L12p=rprime12 - CV*SE; * lower limit of 95% CI for rho-prime; U12p=rprime12 + CV*SE; * upper limit of 95% CI for rho-prime; L12=(exp(2*L12p)-1)/(exp(2*L12p)+1); U12=(exp(2*U12p)-1)/(exp(2*U12p)+1); rprime13=0.5*log(abs((1+r13)/(1-r13))); L13p=rprime13-CV*SE; * lower limit of 95% CI for rho-prime; U13p=rprime13+CV*SE; * upper limit of 95% CI for rho-prime; L13=(exp(2*L13p)-1)/(exp(2*L13p)+1); U13=(exp(2*U13p)-1)/(exp(2*U13p)+1); Label L12='Lower CI rho12'; Label L13='Lower CI rho13'; Label U12='Upper CI rho12'; Label U13='Upper CI rho13'; CI_Lower=r12-r13-SQRT((r12-L12)**2+(U13-r13)**2-2*corr12_13*(r12-L12)*(U13-r13)); CI_Upper=r12-r13+SQRT((U12-r12)**2+(r13-L13)**2-2*corr12_13*(U12-r12)*(r13-L13)); CARDS; .164 -.189 .624 24 .05 Burbank .198 .065 .040 49 .05 Lancaster .412 .114 .487 19 .05 Long Beach .366 .071 .364 58 .05 Glendora .366 .071 .364 58 .01 Glendora .396 .179 .088 66 .05 Zou (2007) Example 2 ; proc print Label; var r12 L12 U12 r13 L13 U13 alpha Note; ID; Title 'Confidence Intervals for rho-12 and rho-13'; run; proc print; var r12 r13 t df p CI_Lower CI_Upper alpha Note; ID; title 'Williams'' test'; run;