*SPSS syntax example by www.spss-tutorials.com.

******CONFIDENCE INTERVALS FOR PEARSON CORRELATIONS******.

*Create some test data holding correlations, sample sizes and confidence levels for confidence intervals.

data list free/cor n conf.
begin data
0.83 50 0.95
0.325 15 0.95
0.657 15 0.9
0.37 15 0.99
end data.

*Basic significance test.
compute t = cor * sqrt((n - 2) / (1 - cor**2)).
compute df = n - 2.
if (cor > 0) p = 2 * (1 - cdf.t(t,df)).
if (cor < 0) p = 2 * cdf.t(t,df).

*FISHER Z-TRANFORMATION for Input Correlations.
compute #zcor = 0.5 * ln((1 + cor) / (1 - cor)).

*FIND Z Transformed Lower and Upper Boundaries.
compute #z = idf.normal(1 - 0.5 * (1 - conf),0,1).
compute #lz = #zcor - (n - 3)**-0.5 * #z.
compute #uz = #zcor + (n - 3)**-0.5 * #z.

*Convert Lower Z Boundary Back to Correlation.
compute lower_bound = 0.
compute #E_Z=#lz.
compute #fx_val=1.
compute #threshold = 0.00000001.
Loop if (abs(#fx_val) > #threshold).
compute lower_bound = lower_bound- (.5 * ln((lower_bound+1)/(1-lower_bound)) + lower_bound /(2*(n-1)) - #E_z) /( -1/ (lower_bound*lower_bound -1) + 1/(2*(n-1)) ).
if (lower_bound<=-1) lower_bound= -.999999999.
if (lower_bound>=1) lower_bound= .999999999.
compute #fx_val=.5 * ln((lower_bound+1)/(1-lower_bound)) +lower_bound/(2*(n-1)) - #E_z.
end loop.

*Convert Upper Z Boundary Back to Correlation.
compute upper_bound = 0.
compute #E_Z=#uz.
compute #fx_val=1.
compute #threshold = 0.00000001.
Loop if (abs(#fx_val) > #threshold).
compute upper_bound = upper_bound- (.5 * ln((upper_bound+1)/(1-upper_bound)) + upper_bound /(2*(n-1)) - #E_z) /( -1/ (upper_bound*upper_bound -1) + 1/(2*(n-1)) ).
if (upper_bound<=-1) upper_bound= -.999999999.
if (upper_bound>=1) upper_bound= .999999999.
compute #fx_val=.5 * ln((upper_bound+1)/(1-upper_bound)) +upper_bound/(2*(n-1)) - #E_z.
end loop.

*Apply Labels and Formats.

variable labels lower_bound "Lower Bound for Confidence Interval".
variable labels upper_bound "Upper Bound for Confidence Interval".
formats n df(f6).
execute.