ADMB Documentation  11.1.2503
 All Classes Files Functions Variables Typedefs Friends Defines
dbeta.cpp
Go to the documentation of this file.
00001 #include "statsLib.h"
00002 
00037 dvariable dbeta( const dvariable& x, const double& shape1, const double& shape2 )
00038 {
00039   if( x<=0 || x>=1.0 )
00040   {
00041     cerr<<"x is <=0 or >=1.0 in "
00042       "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
00043     return 0;
00044   }
00045   
00046   if( shape1<=0 || shape2 <=0 )
00047   {
00048     cerr<<"shape1 or shape2 is <= 0 in "
00049       "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
00050     return 0;
00051   }
00052   
00053   double a=shape1;
00054   double b=shape2;
00055   return -1.* gammln(a+b)+(gammln(a)+gammln(b))-(a-1.)*log(x)-(b-1.)*log(1.-x);
00056 }
00057 
00058 dvariable dbeta( const dvariable& x, const dvariable& shape1, const dvariable& shape2 )
00059 {
00060   if( x<=0 || x>=1.0 )
00061   {
00062     cerr<<"x is <=0 or >=1.0 in "
00063       "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
00064     return 0;
00065   }
00066   
00067   if( shape1<=0 || shape2 <=0 )
00068   {
00069     cerr<<"shape1 or shape2 is <= 0 in "
00070       "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
00071     return 0;
00072   }
00073   
00074   dvariable a=shape1;
00075   dvariable b=shape2;
00076   return -1.* gammln(a+b)+(gammln(a)+gammln(b))-(a-1.)*log(x)-(b-1.)*log(1.-x);
00077 }
00078 
00079 dvariable dbeta( const dvariable& x, const prevariable& shape1, const prevariable& shape2 )
00080 {
00081   if( x<=0 || x>=1.0 )
00082   {
00083     cerr<<"x is <=0 or >=1.0 in "
00084       "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
00085     return 0;
00086   }
00087   
00088   if( shape1<=0 || shape2 <=0 )
00089   {
00090     cerr<<"shape1 or shape2 is <= 0 in "
00091       "dbeta( const dvariable& x, const double& shape1, const double& shape2 )\n";
00092     return 0;
00093   }
00094   
00095   dvariable a=shape1;
00096   dvariable b=shape2;
00097   return -1.* gammln(a+b)+(gammln(a)+gammln(b))-(a-1.)*log(x)-(b-1.)*log(1.-x);
00098 }
00099