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