ADMB Documentation  11.1.1916
 All Classes Files Functions Variables Typedefs Friends Defines
df1b2negb.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: df1b2negb.cpp 1619 2014-02-10 21:44:48Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #define HOME_VERSION
00012 #include "df1b2fun.h"
00013 
00024 /*
00025   df1b2variable log_negbinomial_density(double x,const df1b2variable& mu,
00026     const df1b2variable& tau)
00027   {
00028     if (value(tau)<=1.0)
00029     {
00030       cerr << "tau <=1 in log_negbinomial_density " << endl;
00031       ad_exit(1);
00032     }
00033     df1b2variable r=mu/(tau-1.0);
00034     df1b2variable tmp;
00035     tmp=gammln(x+r)-gammln(r) -gammln(x+1)
00036       +r*log(r)+x*log(mu)-(r+x)*log(r+mu);
00037     return tmp;
00038   }
00039 */
00040 
00041 
00051 df1b2variable negbinomial_density(double x,const df1b2variable& mu,
00052     const df1b2variable& tau)
00053   {
00054     if (value(tau)-1<0.0)
00055     {
00056       cerr << "tau <=1 in log_negbinomial_density " << endl;
00057       ad_exit(1);
00058     }
00059     df1b2variable r=mu/(1.e-120+tau-1.0);
00060     df1b2variable tmp;
00061     tmp=exp(gammln(x+r)-gammln(r) -gammln(x+1)
00062       +r*log(r)+x*log(mu)-(r+x)*log(r+mu));
00063     return tmp;
00064   }
00065 
00074   df1b2variable log_density_poisson(double x,const df1b2variable& mu)
00075   {
00076     return -mu+x*log(mu)-gammln(x+1);
00077   }
00078