(pairs: List[Tuple[float, float]])
| 59 | |
| 60 | |
| 61 | def kendall_tau(pairs: List[Tuple[float, float]]) -> float: |
| 62 | concordant = 0 |
| 63 | discordant = 0 |
| 64 | for i in range(len(pairs)): |
| 65 | for j in range(i + 1, len(pairs)): |
| 66 | x_delta = pairs[i][0] - pairs[j][0] |
| 67 | y_delta = pairs[i][1] - pairs[j][1] |
| 68 | product = x_delta * y_delta |
| 69 | if product > 0: |
| 70 | concordant += 1 |
| 71 | elif product < 0: |
| 72 | discordant += 1 |
| 73 | total = concordant + discordant |
| 74 | if total <= 0: |
| 75 | return 0.0 |
| 76 | return (concordant - discordant) / total |
| 77 | |
| 78 | |
| 79 | def bootstrap_ci( |