The Spearman Correlation of two sets of n numbers, say x_{j} and y_{j} (where j goes from 1 to n) is defined as the Pearson Correlation of the Ranks. If the numbers in each set are not repeated, then the Ranks for each set are just a reordering of the numbers 1, 2, 3, ... n.
Because the ranks are just the numbers 1, 2, 3, ... n, then the Mean of the Ranks isjust: [1] M = (1/n)(1+2+3+...+n) = (1/2) [ n(n+1)/2 ] = (n+1)/2
using the magic formula: 1+2+3+...+n = n(n+1)/2
For our n = 5 example, the numbers are 8, 17, 2, 5, 12 then their Ranks are 3, 1, 5, 4, 2 and the Mean of the Ranks is (5+1)/2 = 3. Furthermore, the Standard Deviation, S, of the Ranks can calculated like so (provided the ranks are not repeated): We know that S^{2} = (average of the squares)  (square of the average)
... see SD stuff,
[2] S^{2} = (1/n)Σ k^{2}  M^{2}
= (1/n)[ n(n+1)(2n+1)/6 ]  M^{2} = (n+1)(2n+1)/6  [(n+1)/2]^{2} = (n^{2}  1)/2
The Pearson Correlation for two sets of numbers (say u_{j} and v_{j}) is R, defined by [3] SD[u] SD[v] R
= (1/n)Σ (u_{j}M[u]) (v_{j}M[v])
However, if we're talking about Ranks, then both the uset and vset are just reordering of the same numbers 1, 2, 3, ... n (provided the ranks are not repeated!!) and that means that M[u] = M[v] = M and that SD[u] = SD[v] = S ... given by [2], above. Then we may calculate R, the Pearson Correlation of Ranks (that's the Spearman Correlation!) from: [4] S^{2}R
= (1/n)Σ (u_{j}M) (v_{j}M)
= (1/n)Σ u_{j}v_{j}
 (M/n)Σ u_{j}  (M/n)Σ v_{j}
+ (1/n)Σ M^{2}
= (1/n)Σ u_{j}v_{j}  M^{2}
Given the sequence of Ranks, we could use [4] to calculate the Spearman Correlation
(provided the ranks are not repeated!!).
Consider the average of the squares of the differences in the Ranks: [5] (1/n)Σ (u_{j}  v_{j})^{2} = (1/n)Σ u_{j}^{2} + (1/n)Σ v_{j}^{2}  (2/n)Σ u_{j}v_{j} = (2/n)Σ k^{2}  (2/n)Σ u_{j}v_{j} But (1/n)Σ k^{2} = S^{2} + M^{2} from [2], above and we have expressions for both S and S in terms of the number n ... so we can (eventually) write:
P.S. If the ranks are repeated (meaning the original variables are not all different), then just use the Pearson Correlation of Ranks
