Revision 1618

trunk/contrib/statslib/statsLib.h (revision 1618)
40 40
dvariable dbinom(const prevariable& x,const dvar_vector& n,const dvar_vector& p);
41 41
dvariable dbinom(const dvar_vector& x,const prevariable& n,const dvar_vector& p);
42 42
dvariable dbinom(const dvar_vector& x,const dvar_vector& n,const prevariable& p);
43
df1b2variable dbinom( const df1b2variable& x,const double& n,const double& p );
44
df1b2variable dbinom( const df1b2variable& x,const df1b2variable& n,const double& p );
45
df1b2variable dbinom( const df1b2variable& x,const df1b2variable& n,const df1b2variable& p );
46
df1b2variable dbinom(const df1b2vector& x,const df1b2vector& n,const df1b2vector& p);
47
df1b2variable dbinom(const df1b2variable& x,const df1b2vector& n,const df1b2vector& p);
48
df1b2variable dbinom(const df1b2vector& x,const df1b2variable& n,const df1b2vector& p);
49
df1b2variable dbinom(const df1b2vector& x,const df1b2vector& n,const df1b2variable& p);
43 50

  
44 51
// Negative binomial distribution
45
dvariable dnbinom(const double& x,const prevariable& mu, const prevariable& size);
52
dvariable dnbinom(const double& x,const prevariable& mu, const prevariable& k);
46 53
df1b2variable dnbinom(const double& x, const df1b2variable& mu, const df1b2variable& k);
47 54
df1b2variable dnbinom(const dvector& x, const df1b2vector& mu, const df1b2variable& k);
48 55
df1b2variable dnbinom(const dvector& x, const df1b2vector& mu, const df1b2vector& k);
49 56
dvariable dnbinom(const dvector& x, const dvar_vector& mu, const prevariable& k);
50 57
dvariable dnbinom(const dvector& x, const dvar_vector& mu, const dvar_vector& k);
51 58

  
59
// Negative binomial distribution (other parametarization)
60
dvariable dnbinom_tau(const double& x,const prevariable& mu, const prevariable& tau);
61
df1b2variable dnbinom_tau(const double& x, const df1b2variable& mu, const df1b2variable& tau);
62
df1b2variable dnbinom_tau(const dvector& x, const df1b2vector& mu, const df1b2variable& tau);
63
df1b2variable dnbinom_tau(const dvector& x, const df1b2vector& mu, const df1b2vector& tau);
64
dvariable dnbinom_tau(const dvector& x, const dvar_vector& mu, const prevariable& tau);
65
dvariable dnbinom_tau(const dvector& x, const dvar_vector& mu, const dvar_vector& tau);
66

  
52 67
// Zero Inflated Negative binomial distribution
53 68
df1b2variable dzinbinom(const double& x, const df1b2variable& mu, const df1b2variable& k, const df1b2variable& p);
54 69
dvariable dzinbinom(const double& x, const prevariable& mu, const prevariable& k, const prevariable& p);
trunk/contrib/statslib/dnbinom_tau.cpp (revision 1618)
1
#include "statsLib.h"
2
#include <df1b2fun.h>
3
#include <adrndeff.h> 
4

  
5

  
6
/** negative log likelihood of negative binomial with mean and tau 
7
\brief Negative binomial with mean=mu and variance = mu*tau
8
\author  Mollie Brooks
9
\param x observed count
10
\param mu is the predicted mean
11
\param tau is the overdispersion parameter like in the quasi-poisson. should be >1
12
\return negative log likelihood \f$ -( \ln(\Gamma(x+k))-\ln(\Gamma(k))-\ln(x!)+k\ln(k)+x\ln(\mu)-(k+x)\ln(k+\mu) )\f$ 
13
 where \f$ k=\mu/(10^{-120}+\tau-1.0) \f$
14
\ingroup STATLIB
15
**/
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
	}
26
	RETURN_ARRAYS_INCREMENT();
27
	dvariable loglike;
28

  
29
	loglike =  log_negbinomial_density(x, mu, tau);
30

  
31
	RETURN_ARRAYS_DECREMENT();
32
	return(-loglike);
33
}
34

  
35
/** negative log likelihood of negative binomial with mean and tau 
36
\brief Negative binomial with mean=mu and variance = mu*tau
37
\author Mollie Brooks
38
\param x observed count
39
\param mu is the predicted mean
40
\param tau is the overdispersion parameter like in the quasi-poisson. should be >1
41
\return negative log likelihood \f$ -( \ln(\Gamma(x+k))-\ln(\Gamma(k))-\ln(x!)+k\ln(k)+x\ln(\mu)-(k+x)\ln(k+\mu) )\f$
42
where \f$ k=\mu/(10^{-120}+\tau-1.0) \f$
43
\ingroup STATLIB
44
**/
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
	}
55
	RETURN_ARRAYS_INCREMENT();
56
	df1b2variable loglike;
57
	loglike = log_negbinomial_density(x, mu, tau);
58

  
59
	RETURN_ARRAYS_DECREMENT();
60
	return(-loglike);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff