Skip to content

Instantly share code, notes, and snippets.

@jdh30
Created November 21, 2022 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdh30/1c0b2130d51af9f5d047981a70f8de71 to your computer and use it in GitHub Desktop.
Save jdh30/1c0b2130d51af9f5d047981a70f8de71 to your computer and use it in GitHub Desktop.
Computes the Pearson's rank correlation coefficient
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