math icon indicating copy to clipboard operation
math copied to clipboard

Add `log_inc_beta` function

Open andrjohns opened this issue 1 year ago • 5 comments

Description

The Binomial (LC)CDF functions are defined using the inc_beta function, however this can underflow to 0 for large inputs. By using the relationship with the Gauss Hypergeometric function, we can calculate inc_beta on the log scale: https://stats.stackexchange.com/a/148700

This provides greater resistance to underflow: https://godbolt.org/z/Pxn8MMYTv

Current Version:

v4.4.0

andrjohns avatar Jul 10 '22 19:07 andrjohns

Be careful with this as it does lose a lot of precision for very small x values. See discussion at https://bugs.r-project.org/show_bug.cgi?id=16332#c7. We'll have to branch across different values of x.

spinkney avatar Jul 14 '22 14:07 spinkney

Umm, when I tested this in R it wasn't good but boost's implementation in c++ is good in a wide range of x values.

spinkney avatar Jul 14 '22 14:07 spinkney

Hmm, well it's not the easy fix I was hoping for, but it's a start!

Once we've got the 2F1 in I'll start investigating where the underflow could be coming from

andrjohns avatar Jul 15 '22 06:07 andrjohns

But I also only brought this up for the beta/binomial CDFs (numerical stability for copulas), so let me know if there's a better or more robust approach that avoids all of these headaches!

andrjohns avatar Jul 15 '22 06:07 andrjohns

I think what you have will work! Looking forward to more stable cdfs!

spinkney avatar Jul 17 '22 23:07 spinkney