/* File name: 1_Pearson_r.txt Written by: Karl L. Wuensch, WuenschK@ECU.edu Date: 8-September-2012. ===================================================== Test the null hypothesis that rho = a specified value and compute a confidence interval for rho using a confidence level specified by the user. NOTE: When the null hypothesis (H0) states that rho = 0, a t-test is used; but when H0 states that rho = a non-zero value, a z-test on r-prime is used (where r-prime is obtained via Fisher's r-to-z transformation). Regardless of the value of rho, the confidence interval on rho is obtained by computing a CI on rho-prime, and then using the inverse of the r-to-z transformation. Use correlations between father's height and father's weight from the 4 areas to test the null hypothesis that rho = .65. In the INPUT statement below: r = observed value of Pearson r rho = population correlation according to the null hypothesis n = sample size alpha = value used to set the confidence level for the CI, with Confidence Level = (1-alpha)*100 Note = a brief description of the data in that row. Users can replace the data lines (between CARDS and PROC) with their own data. **********************************************************/ data rho; input r rho n alpha Note \$30.; rprime=0.5*log(abs((1+r)/(1-r))); rhoprime=0.5*log(abs((1+rho)/(1-rho))); SE=SQRT(1/(n-3)); *Compute confidence interval for rho; cump=1-alpha/2; *CV = critical value of z; CV = PROBIT(cump); LLprime = rprime - CV*SE; ULprime = rprime + CV*SE; *LL=(exp(L)-exp(LLprime*-1))/(exp(L)+exp(LLprime*-1)); *UL=(exp(U)-exp(ULprime*-1))/(exp(U)+exp(ULprime*-1)); CI_Lower=(exp(2*LLprime)-1 )/(exp(2*LLprime)+ 1); CI_Upper=(exp(2*ULprime)-1 )/(exp(2*ULprime)+ 1); z=(rprime-rhoprime)/SE; zneg = 0-abs(z); p_z=2*PROBNORM(zneg); If rho=0 then Do; df=n-2; t=r*SQRT(df)/SQRT(1-r**2); tneg=0-abs(t); p_t=2*probt(tneg,df); end; CARDS; .628 .000 24 .05 Burbank .418 .000 49 .05 Lancaster .438 .000 19 .05 Long Beach .589 .000 58 .05 Glendora .628 .650 24 .05 Burbank .628 .650 24 .01 Burbank, .01 .418 .650 49 .05 Lancaster .418 .650 49 .01 Lancaster, .01 .438 .650 19 .05 Long Beach .438 .650 19 .01 Long Beach, .01 .589 .650 58 .05 Glendora .589 .650 58 .01 Glendora, .01 ; PROC print; var r rho n t df p_t z p_z alpha CI_Lower CI_Upper Note; ID; title 'Test H0: rho = value, with CI'; run; /* If rho = 0, TestVal = t, otherwise TestVal = z (and df is missing). * Confidence level for CI = (1-alpha)*100. * Notice that when p > alpha, the (1-alpha)*100% CI * includes the value of rho specified by the null hypothesis. * But when p < alpha, the (1-alpha)*100% CI does not include * the value of rho specified by H0. */