Inverse Incomplete Beta Function


bruss
08-09-2006, 12:58 PM
Hi, my name is Brian Russell. I live and work in Calgary, Alberta and just joined this forum, which is great because I have a question.

I am currently putting together code using NR in C++ that I successfully implemented using MathCad. The problem is to compute both forward and inverse Student's t CDF values. I realize from Chapter 6 that the forward problem requires using the incomplete beta function. However, to compute the inverse CDF I need the inverse incomplete beta function. Is this in NR and I have just missed it? Or has someone figured out a neat way to compute it (perhaps table lookup) from the forward function?

euandean
10-13-2006, 09:58 AM
I was having the same issue and there is nothing I could find that calculates this. In the end I came up with this.

Assuming that you have an implementation of the incomplete beta function. The following code calculates the Inverse Beta function. It produces results very close to the Excel BetaInv function

/// <summary>
/// Returns the inverse of the cumulative beta probability density function.
/// </summary>
/// <param name="p">Probability associated with the beta distribution.</param>
/// <param name="alpha">Parameter of the distribution.</param>
/// <param name="beta">Parameter of the distribution.</param>
/// <param name="A">Optional lower bound to the interval of x.</param>
/// <param name="B">Optional upper bound to the interval of x.</param>
/// <returns>Inverse of the cumulative beta probability density function for a given probability</returns>

public double InverseBeta(double p, double alpha, double beta, double A, double B)
{
double x = 0;
double a = 0;
double b = 1;
double precision = Math.Pow(10, -6); // converge until there is 6 decimal places precision

while ((b - a) > precision)
{
x = (a + b) / 2;
if (IncompleteBetaFunction(alpha, beta, x) > p)
{
b = x;
}
else
{
a = x;
}}

if ((B > 0) && (A > 0))
{
x = x * (B - A) + A;
}
return x;
}