Stan Math Library  2.14.0
reverse mode automatic differentiation
beta_binomial_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_BINOMIAL_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_BETA_BINOMIAL_RNG_HPP
3 
18 
19 namespace stan {
20  namespace math {
21 
22  template <class RNG>
23  inline int
25  double alpha,
26  double beta,
27  RNG& rng) {
28  static const char* function("beta_binomial_rng");
29 
30  check_nonnegative(function, "Population size parameter", N);
31  check_positive_finite(function,
32  "First prior sample size parameter", alpha);
33  check_positive_finite(function,
34  "Second prior sample size parameter", beta);
35 
36  double a = beta_rng(alpha, beta, rng);
37  while (a > 1 || a < 0)
38  a = beta_rng(alpha, beta, rng);
39  return binomial_rng(N, a, rng);
40  }
41 
42  }
43 }
44 #endif
double beta_rng(double alpha, double beta, RNG &rng)
Definition: beta_rng.hpp:30
int beta_binomial_rng(int N, double alpha, double beta, RNG &rng)
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
int binomial_rng(int N, double theta, RNG &rng)

     [ Stan Home Page ] © 2011–2016, Stan Development Team.