Confidence Interval – How to Calculate for Spearman’s Rank Correlation

confidence intervalcorrelationspearman-rho

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)?

This page has the following example:

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?

Best Answer

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.

Related Question