haskell / statistics

A fast, high quality library for computing with statistics in Haskell.
http://hackage.haskell.org/package/statistics
BSD 2-Clause "Simplified" License
300 stars 68 forks source link

`spearman` returns NaN. #128

Open GregorySchwartz opened 7 years ago

GregorySchwartz commented 7 years ago

spearman should return Nothing rather than NaN:

spearman $ V.fromList [(1, 3), (5, 3)], or any case where one of the two variables is a constant.

Shimuuar commented 7 years ago

Good catch! Would you mind to provide fix for it?

GregorySchwartz commented 7 years ago

This would change correlation, pearson, and pearsonMatByRow to return Maybe as well. pearsonMatByRow may have issues as well if the Matrix type should have Nothing as elements rather than throwing out the entire matrix, because there is no instance for Unbox (Maybe a).

Shimuuar commented 7 years ago

Ohhh... It's going to be a big change. Feel free to share your opinion on the matter

Shimuuar commented 6 years ago

I starting to think that we should do such conversion and return Nothing when no result could be computed. We could do it incrementally and start by convertin correlation & pearson. And decide what to do with pearsonMatByRow later

GregorySchwartz commented 6 years ago

That sounds fine, but maybe return Nothing for pearsonMatByRow? The only issue is when finding bugs, it would be a tad more annoying to see which comparison is returning Nothing.

ocramz commented 6 years ago

I've started addressing this here: https://github.com/DataHaskell/statistics/tree/exceptions-not-error