ADMB Documentation  11.1.2192
 All Classes Files Functions Variables Typedefs Friends Defines
dbeta.cpp
Go to the documentation of this file.
00001 #include "statsLib.h"
00002 
00039 dvariable dbeta( const dvariable& x, const double& shape1, const double& shape2 )
00040 {
00041   if( x<=0 || x>=1.0 )
00042   {
00043     cerr<<"x is <=0 or >=1.0 in "
00044       "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
00045     return 0;
00046   }
00047   
00048   if( shape1<=0 || shape2 <=0 )
00049   {
00050     cerr<<"shape1 or shape2 is <= 0 in "
00051       "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
00052     return 0;
00053   }
00054   
00055   double a=shape1;
00056   double b=shape2;
00057   return -1.* gammln(a+b)+(gammln(a)+gammln(b))-(a-1.)*log(x)-(b-1.)*log(1.-x);
00058 }
00059 
00060