ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cbetai.cpp
Go to the documentation of this file.
1 
7 #include <fvar.hpp>
8 #include <math.h>
9 
21 double betai(const double a,const double b,const double x,int maxit)
22 {
23  double bt;
24 
25  if (x < 0.0 || x > 1.0) cerr << "Bad x in routine betai" << endl;
26  if (x == 0.0 || x == 1.0) bt=0.0;
27  else
28  bt=exp(gammln(a+b)-gammln(a)-gammln(b)+a*log(x)+b*log(1.0-x));
29  if (x < (a+1.0)/(a+b+2.0))
30  return bt*betacf(a,b,x,maxit)/a;
31  else
32  return 1.0-bt*betacf(b,a,1.0-x,maxit)/b;
33 }
34 
35 
47 double pbeta(const double x, const double a, const double b, int maxit){
48  return betai(a,b,x,maxit);
49 }
double gammln(double xx)
Log gamma function.
Definition: combc.cpp:52
double pbeta(const double x, const double a, const double b, int maxit)
beta distribution function for constant objects (alias of ibeta function with same arguments order as...
Definition: cbetai.cpp:47
#define x
prnstream & endl(prnstream &)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
d3_array exp(const d3_array &arr3)
Returns d3_array results with computed exp from elements in arr3.
Definition: d3arr2a.cpp:28
double betai(const double a, const double b, const double x, int maxit)
Incomplete beta function for constant objects.
Definition: cbetai.cpp:21
Float betacf(Float a, Float b, Float x, int MAXIT)
Definition: betacf_val.hpp:13
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2a.cpp:13