Skip to content

Add log_inc_beta function #2790

Description

@andrjohns

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

Activity

  1. spinkney commented on Jul 14, 2022

    @spinkney
    Member

    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.

  2. spinkney commented on Jul 14, 2022

    @spinkney
    Member

    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.

  3. andrjohns commented on Jul 15, 2022

    @andrjohns
    CollaboratorAuthor

    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

  4. andrjohns commented on Jul 15, 2022

    @andrjohns
    CollaboratorAuthor

    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!

  5. spinkney commented on Jul 17, 2022

    @spinkney
    Member

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

  6. avehtari commented on Oct 8, 2026

    @avehtari
    Member

    #3433 improves stability, but below DBL_MIN log_inc_beta is still needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions