(1) | \rho_{xy} = 1 - \frac{6}{n(n^2-1)} \sum_i \big( rg(x_i)-rg(y_i) \big)^2 |
where rg(x_i) is the rank of element x_i, i.e. index number in a low-to-high sorted array:
(2) | \{ x \} = \{ x_1, x_2, x_3 ... x_n \} \rightarrow \{ rg(x) \} = \{ x_{i_1}, x_{i_2}, x_{i_3} ... x_{i_n} \}, \, {\rm где} \, x_{i_1} \leq x_{i_2} \leq x_{i_3} ... \leq x_{i_n} |