# How to calculate a confidence interval for Spearman's rank correlation?

Wikipedia has a Fisher transform of the Spearman rank correlation to an approximate z-score. Perhaps that z-score is the difference from null hypothesis (rank correlation 0)?

4, 10, 3, 1, 9, 2, 6, 7, 8, 5
5, 8, 6, 2, 10, 3, 9, 4, 7, 1
rank correlation 0.684848
"95% CI for rho (Fisher's z transformed)= 0.097085 to 0.918443"


How do they use the Fisher transform to get the 95% confidence interval?

-

In a nutshell, a 95% confidence interval is given by
$$\tanh(\operatorname{arctanh}r\pm1.96/\sqrt{n-3}),$$ where $r$ is the estimate of the correlation and $n$ is the sample size.

Explanation: The Fisher transformation is arctanh. On the transformed scale, the sampling distribution of the estimate is approximately normal, so a 95% CI is found by taking the transformed estimate and adding and subtracting 1.96 times its standard error. The standard error is (approximately) $1/\sqrt{n-3}$.

EDIT: The example above in Python:

import math
r = 0.684848
num = 10
stderr = 1.0 / math.sqrt(num - 3)
delta = 1.96 * stderr
lower = math.tanh(math.atanh(r) - delta)
upper = math.tanh(math.atanh(r) + delta)
print "lower %.6f upper %.6f" % (lower, upper)


gives

lower 0.097071 upper 0.918445


which agrees with your example to 4 decimal places.

-
One question: how does the 1.06 in en.wikipedia.org/wiki/… relate to your answer? –  dfrankow Nov 26 '11 at 18:44
You've got me there! I don't know to be honest; i just tried it with and without and it matched the example results you gave much better without. –  onestop Nov 26 '11 at 20:43
@dfrankow I have accepted that edit, but this is not a perfect use of this feature -- the better idea is to add such text to the question. –  mbq Nov 27 '11 at 9:54
@dfrankow About the 1.06 value: It seems Wikipedia is referring to Fieller et al.'s Biometrika paper where the estimate of the population variance of $\hat\zeta=\text{tanh}^{-1}\hat\theta$ ($\hat\theta$ is the correlation estimate) is defined as $\sigma^2_{\hat\zeta}\approx 1.06/(n-3)$, but see Bonnett and Wright, Sample size requirements for estimating pearson, kendall and spearman correlations, Psychometrika 65(1):23, 2000. –  chl Nov 27 '11 at 10:31