ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dnbinom_tau.cpp
Go to the documentation of this file.
1 #include "statsLib.h"
2 #include <df1b2fun.h>
3 #include <adrndeff.h>
4 
5 
16 dvariable dnbinom_tau(const double& x, const prevariable& mu, const prevariable& tau)
17 {
18  //x is the observed count
19  //mu is the predicted mean
20  //tau is the overdispersion parameter
21  if (value(tau)<1.0)
22  {
23  cerr<<"tau is <=1.0 in dnbinom_tau()";
24  return(0.0);
25  }
27  dvariable loglike;
28 
29  loglike = log_negbinomial_density(x, mu, tau);
30 
32  return(-loglike);
33 }
34 
45 df1b2variable dnbinom_tau(const double& x, const df1b2variable& mu, const df1b2variable& tau)
46 {
47  //x is the observed count
48  //mu is the predicted mean
49  //tau is the overdispersion parameter
50  if (value(tau)<1.0)
51  {
52  cerr<<"tau is <=1.0 in dnbinom_tau()";
53  return(0.0);
54  }
56  df1b2variable loglike;
57  loglike = log_negbinomial_density(x, mu, tau);
58 
60  return(-loglike);
61 }
62 
74 {
75  //the observed counts are in x
76  //mu is the predicted mean
77  //tau is the overdispersion parameter
78  if (value(tau)<1.0)
79  {
80  cerr<<"tau is <=1.0 in dnbinom_tau()";
81  return(0.0);
82  }
84  int i,imin,imax;
85  imin=x.indexmin();
86  imax=x.indexmax();
87  df1b2variable loglike;
88  loglike=0.;
89  for(i = imin; i<=imax; i++)
90  {
91  loglike += log_negbinomial_density(x(i), mu(i), tau);
92  }
94  return(-loglike);
95 }
107 {
108  //the observed counts are in x
109  //mu is the predicted mean
110  //tau is the overdispersion parameter
111 
113  int i,imin,imax;
114  imin=x.indexmin();
115  imax=x.indexmax();
116  df1b2variable loglike;
117  loglike=0.;
118 
119  for(i = imin; i<=imax; i++)
120  {
121  if (value(tau(i))<1.0)
122  {
123  cerr<<"tau("<<i<<") is <=1.0 in dnbinom_tau()";
124  return(0.0);
125  }
126  loglike += log_negbinomial_density(x(i), mu(i), tau(i));
127  }
129  return(-loglike);
130 }
142 dvariable dnbinom_tau(const dvector& x, const dvar_vector& mu, const prevariable& tau)
143 {
144  //the observed counts are in x
145  //mu is the predicted mean
146  //tau is the overdispersion parameter
147  if (value(tau)<1.0)
148  {
149  cerr<<"tau is <=1.0 in dnbinom_tau()";
150  return(0.0);
151  }
153  int i,imin,imax;
154  imin=x.indexmin();
155  imax=x.indexmax();
156  dvariable loglike = 0.;
157 
158  for(i = imin; i<=imax; i++)
159  {
160  loglike += log_negbinomial_density(x(i), mu(i), tau);
161  }
163  return(-loglike);
164 }
175 dvariable dnbinom_tau(const dvector& x, const dvar_vector& mu, const dvar_vector& tau)
176 {
177  //the observed counts are in x
178  //mu is the predicted mean
179  //tau is the overdispersion parameter
181  int i,imin,imax;
182  imin=x.indexmin();
183  imax=x.indexmax();
184  dvariable loglike;
185  loglike=0.;
186 
187  for(i = imin; i<=imax; i++)
188  {
189  if (value(tau(i))<1.0)
190  {
191  cerr<<"tau("<<i<<") is <=1.0 in dnbinom_tau()";
192  return(0.0);
193  }
194 
195  loglike += log_negbinomial_density(x(i), mu(i), tau(i));
196  }
198  return(-loglike);
199 }
200 
201 
Base class for dvariable.
Definition: fvar.hpp:1315
Description not yet available.
void RETURN_ARRAYS_DECREMENT(void)
Decrements gradient_structure::RETURN_ARRAYS_PTR.
Definition: gradstrc.cpp:507
#define x
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
dvariable dnbinom_tau(const double &x, const prevariable &mu, const prevariable &tau)
negative log likelihood of negative binomial with mean and tau
Definition: dnbinom_tau.cpp:16
Description not yet available.
Definition: df1b2fun.h:953
ADMB variable vector.
Definition: fvar.hpp:2172
Description not yet available.
Definition: df1b2fun.h:266
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
Library of statistic functions.
Description not yet available.
void RETURN_ARRAYS_INCREMENT(void)
Increments gradient_structure::RETURN_ARRAYS_PTR.
Definition: gradstrc.cpp:474
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
double log_negbinomial_density(double x, double mu, double tau)
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518