Skip to content

codeplea/incbeta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Genann logo

Incomplete Beta Function

incbeta.c contains only one function. It is the regularized incomplete beta function. It is released under the zlib license.

You'll need a compiler with lgamma to compile it. Any C99 complier should work.

More info here.

Example

    /* Call it with a, b, x. */
    double r = incbeta(10, 10, 0.3); /*0.03255*/

How does it work?

This solves the continued fraction using Lentz's algorithm.

I wrote up an article about how it works here.

Why would I use this?

Maybe you're trying to do a statistics test, and you don't want to pull in a huge dependency like the GNU Scientific Library just to get one function you need. Or maybe you don't want to use Cephes math library because it's not very clear how that's licensed. Maybe you don't want to steal code from Numerical Recipes because it is definitely not open-source.

So use this instead. It works, it's very small and easy, and it's released under the zlib license.

What can I do with it?

Well, it's used as a building block in a lot of statistics functions.

For example, you can use this to calculate Student's t cumulative distribution function like this:

double student_t_cdf(double t, double v) {
    /*The cumulative distribution function (CDF) for Student's t distribution*/
    double x = (t + sqrt(t * t + v)) / (2.0 * sqrt(t * t + v));
    double prob = incbeta(v/2.0, v/2.0, x);
    return prob;
}

About

Incomplete Beta Function (Student's t cumulative distribution function)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages