Numerical Recipes Forum  

Go Back   Numerical Recipes Forum > Obsolete Editions Forum > Methods: Chapters 3, 4, 5, and 6

Reply
 
Thread Tools Display Modes
  #1  
Old 08-09-2006, 12:58 PM
bruss bruss is offline
Registered User
 
Join Date: Aug 2006
Location: Calgary, Alberta
Posts: 1
Inverse Incomplete Beta Function

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?
Reply With Quote
  #2  
Old 10-13-2006, 09:58 AM
euandean euandean is offline
Registered User
 
Join Date: Oct 2006
Posts: 1
Calculating the Inverse Beta Function.

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;
}
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 11:59 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.