TMB Documentation  v1.9.10
distributions_R.hpp
Go to the documentation of this file.
1 // Copyright (C) 2013-2015 Kasper Kristensen
2 // License: GPL-2
3 
11 template<class Type>
12 Type pnorm(Type q, Type mean = 0., Type sd = 1.){
13  CppAD::vector<Type> tx(1);
14  tx[0] = (q - mean) / sd;
15  return atomic::pnorm1(tx)[0];
16 }
19 
20 
23 template<class Type>
24 Type qnorm(Type p, Type mean = 0., Type sd = 1.){
25  CppAD::vector<Type> tx(1);
26  tx[0] = p;
27  return sd*atomic::qnorm1(tx)[0] + mean;
28 }
31 
32 
35 template<class Type>
36 Type pgamma(Type q, Type shape, Type scale = 1.){
37  CppAD::vector<Type> tx(4);
38  tx[0] = q/scale;
39  tx[1] = shape;
40  tx[2] = Type(0); // 0'order deriv
41  tx[3] = -lgamma(shape); // normalize
42  return atomic::D_incpl_gamma_shape(tx)[0];
43 }
45 
46 
49 template<class Type>
50 Type qgamma(Type q, Type shape, Type scale = 1.){
51  CppAD::vector<Type> tx(3);
52  tx[0] = q;
53  tx[1] = shape;
54  tx[2] = -lgamma(shape); // normalize
55  return atomic::inv_incpl_gamma(tx)[0] * scale;
56 }
58 
59 
62 template<class Type>
63 Type ppois(Type q, Type lambda){
64  CppAD::vector<Type> tx(2);
65  tx[0] = q;
66  tx[1] = lambda;
67  return atomic::ppois(tx)[0];
68 }
70 
71 
79 template<class Type>
80 Type pexp(Type x, Type rate)
81 {
82  return CppAD::CondExpGe(x,Type(0),1-exp(-rate*x),Type(0));
83 }
84 
85 // Vectorize pexp
87 
88 
93 template<class Type>
94 Type dexp(Type x, Type rate, int give_log=0)
95 {
96  if(!give_log)
97  return CppAD::CondExpGe(x,Type(0),rate*exp(-rate*x),Type(0));
98  else
99  return CppAD::CondExpGe(x,Type(0),log(rate)-rate*x,Type(-INFINITY));
100 }
101 
102 // Vectorize dexp
104 
105 
109 template <class Type>
110 Type qexp(Type p, Type rate)
111 {
112  return -log(1-p)/rate;
113 }
114 
115 // Vectorize qexp.
129 template<class Type>
130 Type pweibull(Type x, Type shape, Type scale)
131 {
132  return CppAD::CondExpGe(x,Type(0),1-exp(-pow(x/scale,shape)),Type(0));
133 }
134 
135 // Vectorize pweibull
137 
138 
144 template<class Type>
145 Type dweibull(Type x, Type shape, Type scale, int give_log=0)
146 {
147  if(!give_log)
148  return CppAD::CondExpGe(x,Type(0),shape/scale * pow(x/scale,shape-1) * exp(-pow(x/scale,shape)),Type(0));
149  else
150  return CppAD::CondExpGe(x,Type(0),log(shape) - log(scale) + (shape-1)*(log(x)-log(scale)) - pow(x/scale,shape),Type(-INFINITY));
151 }
152 
153 // Vectorize dweibull
155 
156 
162 template<class Type>
163 Type qweibull(Type p, Type shape, Type scale)
164 {
165  Type res = scale * pow( (-log(1-p)) , 1/shape );
166  res = CppAD::CondExpLt(p,Type(0),Type(0),res);
167  res = CppAD::CondExpGt(p,Type(1),Type(0),res);
168  return res;
169 }
170 
171 // Vectorize qweibull
182 template<class Type>
183 Type dbinom(Type k, Type size, Type prob, int give_log=0)
184 {
185  Type logres = lgamma(size + 1) - lgamma(k + 1) - lgamma(size - k + 1);
186  // Add 'k * log(prob)' only if k > 0
187  logres += CppAD::CondExpGt(k, Type(0), k * log(prob), Type(0) );
188  // Add '(size - k) * log(1 - prob)' only if size > k
189  logres += CppAD::CondExpGt(size, k, (size - k) * log(1 - prob), Type(0) );
190  if (!give_log) return exp(logres);
191  else return logres;
192 }
193 
194 // Vectorize dbinom
196 
197 
204 template<class Type>
205 Type dbinom_robust(Type k, Type size, Type logit_p, int give_log=0)
206 {
207  CppAD::vector<Type> tx(4);
208  tx[0] = k;
209  tx[1] = size;
210  tx[2] = logit_p;
211  tx[3] = 0;
212  Type ans = atomic::log_dbinom_robust(tx)[0]; /* without norm. constant */
213  if (size > 1) {
214  ans += lgamma(size+1.) - lgamma(k+1.) - lgamma(size-k+1.);
215  }
216  return ( give_log ? ans : exp(ans) );
217 }
219 
220 
226 template <class Type>
227 Type dbeta(Type x, Type shape1, Type shape2, int give_log)
228 {
229  Type res = exp(lgamma(shape1+shape2) - lgamma(shape1) - lgamma(shape2)) * pow(x,shape1-1) * pow(1-x,shape2-1);
230  if(!give_log)
231  return res;
232  else
233  return CppAD::CondExpEq(x,Type(0),log(res),lgamma(shape1+shape2) - lgamma(shape1) - lgamma(shape2) + (shape1-1)*log(x) + (shape2-1)*log(1-x));
234 }
235 
236 // Vectorize dbeta
238 
239 
245 template <class Type>
246 Type df(Type x, Type df1, Type df2, int give_log)
247 {
248  Type logres = lgamma((df1+df2)/2.) - lgamma(df1/2.) - lgamma(df2/2.) + df1/2.*log(Type(df1)/df2) + (df1/2.-1)*log(x) - (df1+df2)/2.*log(1+Type(df1)/df2*x);
249  if(!give_log) return exp(logres);
250  else return logres;
251 }
252 
253 //Vectorize df
255 
256 
262 template <class Type>
263 Type dlogis(Type x, Type location, Type scale, int give_log)
264 {
265  Type logres = -(x-location)/scale - log(scale) - 2*log(1+exp(-(x-location)/scale));
266  if(!give_log) return exp(logres);
267  else return logres;
268 }
269 
270 // Vectorize dlogis
272 
273 
278 template <class Type>
279 Type dsn(Type x, Type alpha, int give_log=0)
280 {
281 
282  if(!give_log) return 2 * dnorm(x,Type(0),Type(1),0) * pnorm(alpha*x);
283  else return log(2.0) + log(dnorm(x,Type(0),Type(1),0)) + log(pnorm(alpha*x));
284 }
285 
286 // Vectorize dsn
288 
289 
294 template <class Type>
295 Type dt(Type x, Type df, int give_log)
296 {
297  Type logres = lgamma((df+1)/2) - Type(1)/2*log(df*M_PI) -lgamma(df/2) - (df+1)/2*log(1+x*x/df);
298  if(!give_log) return exp(logres);
299  else return logres;
300 }
301 
302 // Vectorize dt
304 
305 
311 template <class Type>
312 Type dmultinom(vector<Type> x, vector<Type> p, int give_log=0)
313 {
314  vector<Type> xp1 = x+Type(1);
315  Type logres = lgamma(x.sum() + Type(1)) - lgamma(xp1).sum() + (x*log(p)).sum();
316  if(give_log) return logres;
317  else return exp(logres);
318 }
319 
338 template <class Type>
339 Type dSHASHo(Type x, Type mu, Type sigma, Type nu, Type tau, int give_log = 0)
340 {
341  // TODO : Replace log(x+sqrt(x^2+1)) by a better approximation for asinh(x).
342 
343  Type z = (x-mu)/sigma;
344  Type c = cosh(tau*log(z+sqrt(z*z+1))-nu);
345  Type r = sinh(tau*log(z+sqrt(z*z+1))-nu);
346  Type logres = -log(sigma) + log(tau) -0.5*log(2*M_PI) -0.5*log(1+(z*z)) +log(c) -0.5*(r*r);
347 
348  if(!give_log) return exp(logres);
349  else return logres;
350 }
351 
352 // Vectorize dSHASHo
354 
355 
367 template <class Type>
368 Type pSHASHo(Type q,Type mu,Type sigma,Type nu,Type tau,int give_log=0)
369 {
370  // TODO : Replace log(x+sqrt(x^2+1)) by a better approximation for asinh(x).
371 
372  Type z = (q-mu)/sigma;
373  Type r = sinh(tau * log(z+sqrt(z*z+1)) - nu);
374  Type p = pnorm(r);
375 
376  if (!give_log) return p;
377  else return log(p);
378 }
379 
380 // Vectorize pSHASHo
382 
383 
395 template <class Type>
396 Type qSHASHo(Type p, Type mu, Type sigma, Type nu, Type tau, int log_p = 0)
397 {
398  // TODO : Replace log(x+sqrt(x^2+1)) by a better approximation for asinh(x).
399 
400  if(!log_p) return mu + sigma*sinh((1/tau)* log(qnorm(p)+sqrt(qnorm(p)*qnorm(p)+1)) + (nu/tau));
401  else return mu + sigma*sinh((1/tau)*log(qnorm(exp(p))+sqrt(qnorm(exp(p))*qnorm(exp(p))+1))+(nu/tau));
402 }
403 
404 // Vectorize qSHASHo
406 
407 
416 template <class Type>
417 Type norm2SHASHo(Type x, Type mu, Type sigma, Type nu, Type tau, int log_p = 0)
418 {
419 
420  return qSHASHo(pnorm(x),mu,sigma,nu,tau,log_p);
421 }
422 
423 // Vectorize norm2SHASHo
432 template<class Type>
433 Type pbeta(Type q, Type shape1, Type shape2){
434  CppAD::vector<Type> tx(4);
435  tx[0] = q;
436  tx[1] = shape1;
437  tx[2] = shape2;
438  tx[3] = 0; // order
439  Type ans = atomic::pbeta(tx)[0];
440  return ans;
441 }
443 
444 
449 template<class Type>
450 Type qbeta(Type p, Type shape1, Type shape2){
451  CppAD::vector<Type> tx(3);
452  tx[0] = p;
453  tx[1] = shape1;
454  tx[2] = shape2;
455  Type ans = atomic::qbeta(tx)[0];
456  return ans;
457 }
459 
460 
464 template<class Type>
465 Type besselK(Type x, Type nu){
466  Type ans;
467  if(CppAD::Variable(nu)) {
468  CppAD::vector<Type> tx(3);
469  tx[0] = x;
470  tx[1] = nu;
471  tx[2] = 0;
472  ans = atomic::bessel_k(tx)[0];
473  } else {
474  CppAD::vector<Type> tx(2);
475  tx[0] = x;
476  tx[1] = nu;
477  ans = atomic::bessel_k_10(tx)[0];
478  }
479  return ans;
480 }
482 
483 
487 template<class Type>
488 Type besselI(Type x, Type nu){
489  Type ans;
490  if(CppAD::Variable(nu)) {
491  CppAD::vector<Type> tx(3);
492  tx[0] = x;
493  tx[1] = nu;
494  tx[2] = 0;
495  ans = atomic::bessel_i(tx)[0];
496  } else {
497  CppAD::vector<Type> tx(2);
498  tx[0] = x;
499  tx[1] = nu;
500  ans = atomic::bessel_i_10(tx)[0];
501  }
502  return ans;
503 }
505 
506 
510 template<class Type>
511 Type besselJ(Type x, Type nu){
512  CppAD::vector<Type> tx(3);
513  tx[0] = x;
514  tx[1] = nu;
515  tx[2] = 0;
516  Type ans = atomic::bessel_j(tx)[0];
517  return ans;
518 }
520 
521 
525 template<class Type>
526 Type besselY(Type x, Type nu){
527  CppAD::vector<Type> tx(3);
528  tx[0] = x;
529  tx[1] = nu;
530  tx[2] = 0;
531  Type ans = atomic::bessel_y(tx)[0];
532  return ans;
533 }
535 
536 
553 template<class Type>
554 Type dtweedie(Type y, Type mu, Type phi, Type p, int give_log = 0) {
555  Type p1 = p - 1.0, p2 = 2.0 - p;
556  Type ans = -pow(mu, p2) / (phi * p2); // log(prob(y=0))
557  if (y > 0 || CppAD::Variable(y)) {
558  CppAD::vector<Type> tx(4);
559  tx[0] = y;
560  tx[1] = phi;
561  tx[2] = p;
562  tx[3] = 0;
563  Type ans2 = atomic::tweedie_logW(tx)[0];
564  ans2 += -y / (phi * p1 * pow(mu, p1)) - log(y);
565  if (CppAD::Variable(y)) {
566  ans += CppAD::CondExpGt(y, Type(0), ans2, Type(0));
567  } else {
568  ans += ans2;
569  }
570  }
571  return ( give_log ? ans : exp(ans) );
572 }
574 
575 
576 
585 template<class Type>
586 Type compois_calc_logZ(Type loglambda, Type nu) {
587  CppAD::vector<Type> tx(3);
588  tx[0] = loglambda;
589  tx[1] = nu;
590  tx[2] = 0;
591  return atomic::compois_calc_logZ(tx)[0];
592 }
594 
595 
603 template<class Type>
604 Type compois_calc_loglambda(Type logmean, Type nu) {
605  CppAD::vector<Type> tx(3);
606  tx[0] = logmean;
607  tx[1] = nu;
608  tx[2] = 0;
609  return atomic::compois_calc_loglambda(tx)[0];
610 }
612 
613 
626 template<class T1, class T2, class T3>
627 T1 dcompois(T1 x, T2 mode, T3 nu, int give_log = 0) {
628  T2 loglambda = nu * log(mode);
629  T1 ans = x * loglambda - nu * lfactorial(x);
630  ans -= compois_calc_logZ(loglambda, nu);
631  return ( give_log ? ans : exp(ans) );
632 }
633 
646 template<class T1, class T2, class T3>
647 T1 dcompois2(T1 x, T2 mean, T3 nu, int give_log = 0) {
648  T2 logmean = log(mean);
649  T2 loglambda = compois_calc_loglambda(logmean, nu);
650  T1 ans = x * loglambda - nu * lfactorial(x);
651  ans -= compois_calc_logZ(loglambda, nu);
652  return ( give_log ? ans : exp(ans) );
653 }
654 
655 /********************************************************************/
656 /* SIMULATON CODE */
657 /********************************************************************/
658 
659 extern "C" {
660  double Rf_rnorm(double mu, double sigma);
661 }
663 template<class Type>
664 Type rnorm(Type mu, Type sigma)
665 {
666  return Rf_rnorm(asDouble(mu), asDouble(sigma));
667 }
670 
671 extern "C" {
672  double Rf_rpois(double mu);
673 }
675 template<class Type>
676 Type rpois(Type mu)
677 {
678  return Rf_rpois(asDouble(mu));
679 }
682 
683 extern "C" {
684  double Rf_runif(double a, double b);
685 }
687 template<class Type>
688 Type runif(Type a, Type b)
689 {
690  return Rf_runif(asDouble(a), asDouble(b));
691 }
694 
695 extern "C" {
696  double Rf_rbinom(double size, double prob);
697 }
699 template<class Type>
700 Type rbinom(Type size, Type prob)
701 {
702  return Rf_rbinom(asDouble(size), asDouble(prob));
703 }
706 
707 extern "C" {
708  double Rf_rgamma(double shape, double scale);
709 }
711 template<class Type>
712 Type rgamma(Type shape, Type scale)
713 {
714  return Rf_rgamma(asDouble(shape), asDouble(scale));
715 }
718 
719 extern "C" {
720  double Rf_rexp(double rate);
721 }
723 template<class Type>
724 Type rexp(Type rate)
725 {
726  return Rf_rexp(asDouble(rate));
727 }
728 
731 
732 extern "C" {
733  double Rf_rbeta(double shape1, double shape2);
734 }
736 template<class Type>
737 Type rbeta(Type shape1, Type shape2)
738 {
739  return Rf_rbeta(asDouble(shape1), asDouble(shape2));
740 }
741 
744 
745 extern "C" {
746  double Rf_rf(double df1, double df2);
747 }
749 template<class Type>
750 Type rf(Type df1, Type df2)
751 {
752  return Rf_rf(asDouble(df1), asDouble(df2));
753 }
754 
757 
758 extern "C" {
759  double Rf_rlogis(double location, double scale);
760 }
762 template<class Type>
763 Type rlogis(Type location, Type scale)
764 {
765  return Rf_rlogis(asDouble(location), asDouble(scale));
766 }
767 
770 
771 extern "C" {
772  double Rf_rt(double df);
773 }
775 template<class Type>
776 Type rt(Type df)
777 {
778  return Rf_rt(asDouble(df));
779 }
780 
783 
784 extern "C" {
785  double Rf_rweibull(double shape, double scale);
786 }
788 template<class Type>
789 Type rweibull(Type shape, Type scale)
790 {
791  return Rf_rweibull(asDouble(shape), asDouble(scale));
792 }
793 
796 
797 
798 template<class Type>
799 Type rcompois(Type mode, Type nu)
800 {
801  Type loglambda = nu * log(mode);
802  return atomic::compois_utils::simulate(asDouble(loglambda), asDouble(nu));
803 }
806 
807 
808 template<class Type>
809 Type rcompois2(Type mean, Type nu)
810 {
811  Type logmean = log(mean);
812  Type loglambda = compois_calc_loglambda(logmean, nu);
813  return atomic::compois_utils::simulate(asDouble(loglambda), asDouble(nu));
814 }
816 
817 // Note: Vectorize manually to avoid many identical calls to
818 // 'calc_loglambda'.
819 template<class Type>
820 vector<Type> rcompois2(int n, Type mean, Type nu)
821 {
822  Type logmean = log(mean);
823  Type loglambda = compois_calc_loglambda(logmean, nu);
824  Type mode = exp(loglambda / nu);
825  return rcompois(n, mode, nu);
826 }
827 
829 template<class Type>
830 Type rtweedie(Type mu, Type phi, Type p) {
831  // Copied from R function tweedie::rtweedie
832  Type lambda = pow(mu, 2. - p) / (phi * (2. - p));
833  Type alpha = (2. - p) / (1. - p);
834  Type gam = phi * (p - 1.) * pow(mu, p - 1.);
835  Type N = rpois(lambda);
836  Type ans = rgamma( -alpha * N /* shape */, gam /* scale */);
837  return ans;
838 }
#define VECTORIZE2_tt(FUN)
Vectorize 2-argument functions.
Definition: Vectorize.hpp:71
Type rexp(Type rate)
Simulate from an exponential distribution.
Type rcompois2(Type mean, Type nu)
Simulate from a Conway-Maxwell-Poisson distribution.
Type qbeta(Type p, Type shape1, Type shape2)
Quantile function of the beta distribution (following R argument convention).
Vector class used by TMB.
Definition: vector.hpp:17
Type pbeta(Type q, Type shape1, Type shape2)
Distribution function of the beta distribution (following R argument convention). ...
CppAD::vector< Type > pnorm1(CppAD::vector< Type > x)
Atomic version of standard normal distribution function. Derivative is known to be &#39;dnorm1&#39;...
Type ppois(Type q, Type lambda)
Distribution function of the poisson distribution (following R argument convention).
CppAD::vector< Type > inv_incpl_gamma(CppAD::vector< Type > x)
Atomic version of inverse of scaled incomplete gamma function. Given find such that where the 3 in...
Type pSHASHo(Type q, Type mu, Type sigma, Type nu, Type tau, int give_log=0)
Cumulative distribution function of the sinh-asinh distribution.
Type rcompois(Type mode, Type nu)
Simulate from a Conway-Maxwell-Poisson distribution.
#define VECTORIZE2_n(FUN)
Add the &#39;n&#39; integer argument to a simulation method with two arguments.
Definition: Vectorize.hpp:154
#define VECTORIZE3_n(FUN)
Add the &#39;n&#39; integer argument to a simulation method with three arguments.
Definition: Vectorize.hpp:164
Type dSHASHo(Type x, Type mu, Type sigma, Type nu, Type tau, int give_log=0)
Probability density function of the sinh-asinh distribution.
Type qnorm(Type p, Type mean=0., Type sd=1.)
Quantile function of the normal distribution (following R argument convention).
#define VECTORIZE1_t(FUN)
Vectorize 1-argument functions.
Definition: Vectorize.hpp:63
Type rtweedie(Type mu, Type phi, Type p)
Simulate from tweedie distribution.
Type qgamma(Type q, Type shape, Type scale=1.)
Quantile function of the gamma distribution (following R argument convention).
Type dbeta(Type x, Type shape1, Type shape2, int give_log)
Probability density function of the beta distribution.
CppAD::vector< Type > bessel_k_10(CppAD::vector< Type > x)
Atomic version of . Valid parameter range: .
Type df(Type x, Type df1, Type df2, int give_log)
Probability density function of the Fisher distribution.
Type dbinom(Type k, Type size, Type prob, int give_log=0)
Probability mass function of the binomial distribution.
Type dlogis(Type x, Type location, Type scale, int give_log)
Probability density function of the logistic distribution.
Type rlogis(Type location, Type scale)
Simulate from a logistic distribution.
Type dtweedie(Type y, Type mu, Type phi, Type p, int give_log=0)
dtweedie function (same as dtweedie.series from R package &#39;tweedie&#39;).
Type rf(Type df1, Type df2)
Simulate from an F distribution.
Type dnorm(Type x, Type mean, Type sd, int give_log=0)
Probability density function of the normal distribution.
Definition: dnorm.hpp:17
Type lfactorial(Type x)
Logarithm of factorial function (following R argument convention).
Definition: lgamma.hpp:24
Type besselY(Type x, Type nu)
besselY function (same as besselY from R).
Type dmultinom(vector< Type > x, vector< Type > p, int give_log=0)
Probability mass function of the multinomial distribution.
Type besselI(Type x, Type nu)
besselI function (same as besselI from R).
Type dexp(Type x, Type rate, int give_log=0)
Probability density function of the exponential distribution.
Type lgamma(Type x)
Logarithm of gamma function (following R argument convention).
Definition: lgamma.hpp:12
#define VECTORIZE6_ttttti(FUN)
Vectorize 6-argument functions.
Definition: Vectorize.hpp:133
#define VECTORIZE4_ttti(FUN)
Vectorize 4-argument functions.
Definition: Vectorize.hpp:105
Type dbinom_robust(Type k, Type size, Type logit_p, int give_log=0)
Density of binomial distribution parameterized via logit(prob)
Type rweibull(Type shape, Type scale)
Simulate from a Weibull distribution.
#define VECTORIZE5_tttti(FUN)
Vectorize 5-argument functions.
Definition: Vectorize.hpp:119
Type norm2SHASHo(Type x, Type mu, Type sigma, Type nu, Type tau, int log_p=0)
Transforms a normal variable into a sinh-asinh variable.
Type pweibull(Type x, Type shape, Type scale)
Cumulative distribution function of the Weibull distribution.
Type qexp(Type p, Type rate)
Inverse cumulative distribution function of the exponential distribution.
Type dt(Type x, Type df, int give_log)
Probability density function of the Student t-distribution.
Type pexp(Type x, Type rate)
Cumulative distribution function of the exponential distribution.
CppAD::vector< Type > bessel_i_10(CppAD::vector< Type > x)
Atomic version of . Valid parameter range: .
Type besselK(Type x, Type nu)
besselK function (same as besselK from R).
T1 dcompois(T1 x, T2 mode, T3 nu, int give_log=0)
Conway-Maxwell-Poisson. Calculate density.
Type compois_calc_loglambda(Type logmean, Type nu)
Conway-Maxwell-Poisson. Calculate log(lambda) from log(mean).
#define VECTORIZE1_n(FUN)
Add the &#39;n&#39; integer argument to a simulation method with one argument.
Definition: Vectorize.hpp:144
Type rpois(Type mu)
Simulate from a Poisson distribution.
Type rt(Type df)
Simulate from a Student&#39;s t distribution.
CppAD::vector< Type > qnorm1(CppAD::vector< Type > x)
Atomic version of standard normal quantile function. Derivative is expressed through &#39;dnorm1&#39;...
Type dsn(Type x, Type alpha, int give_log=0)
Probability density function of the skew-normal distribution.
CppAD::vector< Type > D_incpl_gamma_shape(CppAD::vector< Type > x)
Atomic version of scaled incomplete gamma function differentiated to any order wrt. shape parameter where the 4 input parameters are passed as a vector . Note that the normalized incomplete gamma function is obtained as the special case and . Valid parameter range: .
Type rgamma(Type shape, Type scale)
Simulate from a gamma distribution.
CppAD::vector< Type > ppois(CppAD::vector< Type > x)
Atomic version of poisson cdf . Valid parameter range: .
Type dweibull(Type x, Type shape, Type scale, int give_log=0)
Probability density function of the Weibull distribution.
Type sum(Vector< Type > x)
Definition: convenience.hpp:33
Type rbinom(Type size, Type prob)
Simulate from a binomial distribution.
Type rbeta(Type shape1, Type shape2)
Simulate from a beta distribution.
Type rnorm(Type mu, Type sigma)
Simulate from a normal distribution.
Type pnorm(Type q, Type mean=0., Type sd=1.)
Distribution function of the normal distribution (following R argument convention).
Type qweibull(Type p, Type shape, Type scale)
Inverse cumulative distribution function of the Weibull distribution.
Type besselJ(Type x, Type nu)
besselJ function (same as besselJ from R).
Type runif(Type a, Type b)
Simulate from a uniform distribution.
#define VECTORIZE3_tti(FUN)
Vectorize 3-argument functions.
Definition: Vectorize.hpp:81
Type compois_calc_logZ(Type loglambda, Type nu)
Conway-Maxwell-Poisson log normalizing constant.
T1 dcompois2(T1 x, T2 mean, T3 nu, int give_log=0)
Conway-Maxwell-Poisson. Calculate density parameterized via the mean.
#define VECTORIZE3_ttt(FUN)
Vectorize 3-argument functions.
Definition: Vectorize.hpp:91
Type qSHASHo(Type p, Type mu, Type sigma, Type nu, Type tau, int log_p=0)
Quantile function of the sinh-asinh distribution.
Type pgamma(Type q, Type shape, Type scale=1.)
Distribution function of the gamma distribution (following R argument convention).
License: GPL v2