Created
January 21, 2016 01:40
-
-
Save sudipto80/dcda6103b945bf902821 to your computer and use it in GitHub Desktop.
Pearsons Coefficient
This file contains hidden or 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 x = [1.;2.;3.;4.;5.] | |
let y = [1.;2.;2.;3.;4.] | |
let z = [3;4] | |
let x_bar = List.average x | |
let y_bar = List.average y | |
let numerator = | |
List.zip x y | |
|> List.sumBy (fun item -> (fst item - x_bar)*(snd item - y_bar)) | |
let d1 = x |> List.sumBy(fun xi -> (xi - x_bar) ** 2.0) | |
let d2 = y |> List.sumBy(fun yi -> (yi - y_bar) ** 2.0) | |
let denominator = sqrt d1 * sqrt d2 | |
let pearsons = numerator / denominator | |
printfn "Pearsons Correlation Coefficient is %f" pearsons |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment