10 template<
class Type> Type
lgamma(Type x);
14 #define TINY_AD_USE_TINY_VEC 1 15 #include "tiny_ad/tiny_ad.hpp" 21 #include "beta/pbeta.hpp" 22 TMB_BIND_ATOMIC(
pbeta,
29 #include "bessel/bessel.hpp" // Get namespace 'bessel_utils' 30 TMB_BIND_ATOMIC(bessel_k,
32 bessel_utils::bessel_k(x[0], x[1], 1.) )
37 #include "bessel/bessel.hpp" // Get namespace 'bessel_utils' 38 TMB_BIND_ATOMIC(bessel_i,
40 bessel_utils::bessel_i(x[0], x[1], 1.) )
45 #include "bessel/bessel.hpp" // Get namespace 'bessel_utils' 46 TMB_BIND_ATOMIC(bessel_j,
48 bessel_utils::bessel_j(x[0], x[1]) )
53 #include "bessel/bessel.hpp" // Get namespace 'bessel_utils' 54 TMB_BIND_ATOMIC(bessel_y,
56 bessel_utils::bessel_y(x[0], x[1]) )
61 #include "tweedie/tweedie.hpp" 62 TMB_BIND_ATOMIC(tweedie_logW,
64 tweedie_utils::tweedie_logW(x[0], x[1], x[2]) )
69 #include "robust/distributions.hpp" 70 TMB_BIND_ATOMIC(log_dnbinom_robust,
74 TMB_BIND_ATOMIC(log_dbinom_robust,
89 #include "compois/compois.hpp" 92 compois_utils::calc_logZ(x[0], x[1]) )
101 extern "C"
double Rf_qbeta(
double,
double,
double,
int,
int);
102 template <class Type>
103 Type
dbeta(Type x, Type shape1, Type shape2) {
106 (shape1 - 1.) * log(x) + (shape2 - 1.) * log(1. - x);
109 TMB_ATOMIC_STATIC_FUNCTION(
117 ty[0] = Rf_qbeta(tx[0], tx[1], tx[2], 1, 0);
124 px[0] = 1.0 / tmp * py[0];
125 CppAD::vector<Type> arg(4);
130 CppAD::vector<Type> D_shape =
pbeta(arg);
131 px[1] = -D_shape[1] / tmp * py[0];
132 px[2] = -D_shape[2] / tmp * py[0];
Type qbeta(Type p, Type shape1, Type shape2)
Quantile function of the beta distribution (following R argument convention).
Type pbeta(Type q, Type shape1, Type shape2)
Distribution function of the beta distribution (following R argument convention). ...
Type dbeta(Type x, Type shape1, Type shape2, int give_log)
Probability density function of the beta distribution.
Namespace with special functions and derivatives.
Type lgamma(Type x)
Logarithm of gamma function (following R argument convention).
Type dbinom_robust(Type k, Type size, Type logit_p, int give_log=0)
Density of binomial distribution parameterized via logit(prob)
Type dnbinom_robust(const Type &x, const Type &log_mu, const Type &log_var_minus_mu, int give_log=0)
Negative binomial probability function.
Type compois_calc_loglambda(Type logmean, Type nu)
Conway-Maxwell-Poisson. Calculate log(lambda) from log(mean).
Type logspace_add(Type logx, Type logy)
Addition in log-space.
Type logspace_sub(Type logx, Type logy)
Subtraction in log-space.
Type compois_calc_logZ(Type loglambda, Type nu)
Conway-Maxwell-Poisson log normalizing constant.