ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
dnbinom_tau.cpp
Go to the documentation of this file.
00001 #include "statsLib.h"
00002 #include <df1b2fun.h>
00003 #include <adrndeff.h> 
00004 
00005 
00016 dvariable dnbinom_tau(const double& x, const prevariable& mu, const prevariable& tau)
00017 {
00018   //x is the observed count
00019   //mu is the predicted mean
00020   //tau is the overdispersion parameter
00021   if (value(tau)<1.0)
00022   {
00023     cerr<<"tau is <=1.0 in dnbinom_tau()";
00024     return(0.0);
00025   }
00026   RETURN_ARRAYS_INCREMENT();
00027   dvariable loglike;
00028 
00029   loglike =  log_negbinomial_density(x, mu, tau);
00030 
00031   RETURN_ARRAYS_DECREMENT();
00032   return(-loglike);
00033 }
00034 
00045 df1b2variable dnbinom_tau(const double& x, const df1b2variable& mu, const df1b2variable& tau)
00046 {
00047   //x is the observed count
00048   //mu is the predicted mean
00049   //tau is the overdispersion parameter
00050   if (value(tau)<1.0)
00051   {
00052     cerr<<"tau is <=1.0 in dnbinom_tau()";
00053     return(0.0);
00054   }
00055   RETURN_ARRAYS_INCREMENT();
00056   df1b2variable loglike;
00057   loglike = log_negbinomial_density(x, mu, tau);
00058 
00059   RETURN_ARRAYS_DECREMENT();
00060   return(-loglike);
00061 }
00062 
00073 df1b2variable dnbinom_tau(const dvector& x, const df1b2vector& mu, const df1b2variable& tau)
00074 {
00075   //the observed counts are in x
00076   //mu is the predicted mean
00077   //tau is the overdispersion parameter
00078   if (value(tau)<1.0)
00079   {
00080     cerr<<"tau is <=1.0 in dnbinom_tau()";
00081     return(0.0);
00082   }
00083   RETURN_ARRAYS_INCREMENT();
00084   int i,imin,imax;
00085   imin=x.indexmin();
00086   imax=x.indexmax();
00087   df1b2variable loglike;
00088   loglike=0.;
00089   for(i = imin; i<=imax; i++)
00090   { 
00091     loglike += log_negbinomial_density(x(i), mu(i), tau);
00092   }
00093   RETURN_ARRAYS_DECREMENT();
00094   return(-loglike);
00095 }
00106 df1b2variable dnbinom_tau(const dvector& x, const df1b2vector& mu, const df1b2vector& tau)
00107 {
00108   //the observed counts are in x
00109   //mu is the predicted mean
00110   //tau is the overdispersion parameter
00111 
00112   RETURN_ARRAYS_INCREMENT();
00113   int i,imin,imax;
00114   imin=x.indexmin();
00115   imax=x.indexmax();
00116   df1b2variable loglike;
00117   loglike=0.;
00118  
00119   for(i = imin; i<=imax; i++)
00120   {
00121     if (value(tau(i))<1.0)
00122     {
00123       cerr<<"tau("<<i<<") is <=1.0 in dnbinom_tau()";
00124       return(0.0);
00125     }
00126     loglike += log_negbinomial_density(x(i), mu(i), tau(i));
00127   }
00128   RETURN_ARRAYS_DECREMENT();
00129   return(-loglike);
00130 }
00142 dvariable dnbinom_tau(const dvector& x, const dvar_vector& mu, const prevariable& tau)
00143 {
00144   //the observed counts are in x
00145   //mu is the predicted mean
00146   //tau is the overdispersion parameter
00147   if (value(tau)<1.0)
00148   {
00149     cerr<<"tau is <=1.0 in dnbinom_tau()";
00150     return(0.0);
00151   }
00152   RETURN_ARRAYS_INCREMENT();
00153   int i,imin,imax;
00154   imin=x.indexmin();
00155   imax=x.indexmax();
00156   dvariable loglike = 0.;
00157 
00158   for(i = imin; i<=imax; i++)
00159   {
00160     loglike += log_negbinomial_density(x(i), mu(i), tau);
00161   }
00162   RETURN_ARRAYS_DECREMENT();
00163   return(-loglike);
00164 }
00175 dvariable dnbinom_tau(const dvector& x, const dvar_vector& mu, const dvar_vector& tau)
00176 {
00177   //the observed counts are in x
00178   //mu is the predicted mean
00179   //tau is the overdispersion parameter
00180   RETURN_ARRAYS_INCREMENT();
00181   int i,imin,imax;
00182   imin=x.indexmin();
00183   imax=x.indexmax();
00184   dvariable loglike;
00185   loglike=0.;
00186 
00187   for(i = imin; i<=imax; i++)
00188   {
00189     if (value(tau(i))<1.0)
00190     {
00191       cerr<<"tau("<<i<<") is <=1.0 in dnbinom_tau()";
00192       return(0.0);
00193     }
00194     
00195     loglike += log_negbinomial_density(x(i), mu(i), tau(i));
00196   }
00197   RETURN_ARRAYS_DECREMENT();
00198   return(-loglike);
00199 }
00200 
00201