probcomp/bayeslite

CORRELATION PVALUE throws ZeroDivsionError

Closed this issue · 2 comments

fsaad commented

https://github.com/probcomp/bayeslite/blob/master/src/bqlfn.py#L118

We only check for r=1 in L113, but correlation can be -1, which results in a crash in the specified line.

fsaad commented

@riastradh-probcomp

  • Shouldn't we use numpy.allclose instead of ==;
  • what is the rational for setting p = 0 if r is -1 or 1?

Well, oops.

No need to use numpy.allclose: if |r| < 1, then float(r^2) < |r| < 1, so there is no danger of division by zero in that case.

What's the limit as |r| ---> 1 of this function, namely 2 F(-|t|) where t = r sqrt[(n - 2)/(1 - r^2)] and F is the CDF of the Student's t distribution with n - 2 degrees of freedom? Clearly t grows without bound as |r| ---> 1, so -|t| goes to negative infinity, toward which F decays to zero -- hence we approximate p = 0 in that case.

(Check my back-of-the-envelope arithmetic.)