Created
November 21, 2022 12:00
-
-
Save jdh30/1c0b2130d51af9f5d047981a70f8de71 to your computer and use it in GitHub Desktop.
Computes the Pearson's rank correlation coefficient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let pearsonsCorrelationCoefficient xys = | |
let n = Array.length xys in | |
let ∑xy, ∑x, ∑y, ∑x2, ∑y2 = | |
Array.fold [(∑xy, ∑x, ∑y, ∑x2, ∑y2), (x, y) → | |
∑xy+x*y, ∑x+x, ∑y+y, ∑x2+x*x, ∑y2+y*y] | |
(0, 0, 0, 0, 0) xys in | |
(n*∑xy-∑x*∑y)/(√(n*∑x2-∑x*∑x)*√(n*∑y2-∑y*∑y)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment