Last active
September 7, 2015 05:52
-
-
Save gavinwhyte/7023ccf7a272179bdaab to your computer and use it in GitHub Desktop.
Pearson Correlation 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
-- Create a new file, which we will call Main.hs | |
main :: IO () | |
main = do | |
let d1 = [3,3,3,4,4,4,5,5,5] | |
let d2 = [1,1,2,2,3,4,4,5,5] | |
let r = pearson d1 d2 | |
print r | |
pearson xs ys = (n * sumXY - sumX * sumY) / | |
sqrt ( (n * sumX2 - sumX*sumX) * | |
(n * sumY2 - sumY*sumY) ) | |
where n = fromIntegral (length xs) | |
sumX = sum xs | |
sumY = sum ys | |
sumX2 = sum $ zipWith (*) xs xs | |
sumY2 = sum $ zipWith (*) ys ys | |
sumXY = sum $ zipWith (*) xs ys | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thought you might like this...