Stan Math Library: stan/math/prim/scal/prob/beta_binomial_rng.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/scal/err/check_consistent_sizes.hpp>
5 #include <stan/math/prim/scal/err/check_nonnegative.hpp>
6 #include <stan/math/prim/scal/err/check_positive_finite.hpp>
7 #include <stan/math/prim/scal/fun/constants.hpp>
8 #include <stan/math/prim/scal/fun/binomial_coefficient_log.hpp>
9 #include <stan/math/prim/scal/fun/digamma.hpp>
10 #include <stan/math/prim/scal/fun/lbeta.hpp>
11 #include <stan/math/prim/scal/fun/lgamma.hpp>
12 #include <stan/math/prim/scal/fun/value_of.hpp>
13 #include <stan/math/prim/scal/meta/include_summand.hpp>
14 #include <stan/math/prim/scal/prob/binomial_rng.hpp>
15 #include <stan/math/prim/scal/prob/beta_rng.hpp>
16 #include <stan/math/prim/scal/fun/F32.hpp>
17 #include <stan/math/prim/scal/fun/grad_F32.hpp>
18
19 namespace stan {
20
21 namespace math {
22
23 template <class RNG>
24 inline int
25 beta_binomial_rng(const int N,
26 const double alpha,
27 const double beta,
28 RNG& rng) {
29 static const char* function("stan::math::beta_binomial_rng");
30
31 using stan::math::check_positive_finite;
32 using stan::math::check_nonnegative;
33
34 check_nonnegative(function, "Population size parameter", N);
35 check_positive_finite(function,
36 "First prior sample size parameter", alpha);
37 check_positive_finite(function,
38 "Second prior sample size parameter", beta);
39
40 double a = stan::math::beta_rng(alpha, beta, rng);
41 while (a > 1 || a < 0)
42 a = stan::math::beta_rng(alpha, beta, rng);
43 return stan::math::binomial_rng(N, a, rng);
44 }
45 }
46 }
47 #endif
lgamma.hpp
stan::math::beta_rng
double beta_rng(const double alpha, const double beta, RNG &rng)
Definition: beta_rng.hpp:29
check_positive_finite.hpp
stan
Definition: log_sum_exp.hpp:8
digamma.hpp
stan::math::beta_binomial_rng
int beta_binomial_rng(const int N, const double alpha, const double beta, RNG &rng)
Definition: beta_binomial_rng.hpp:25
binomial_coefficient_log.hpp
F32.hpp
include_summand.hpp
check_nonnegative.hpp
beta_rng.hpp
grad_F32.hpp
constants.hpp
lbeta.hpp
stan::math::check_nonnegative
bool check_nonnegative(const char *function, const char *name, const T_y &y)
Return true if y is non-negative.
Definition: check_nonnegative.hpp:66
value_of.hpp
check_consistent_sizes.hpp
stan::math::binomial_rng
int binomial_rng(const int N, const double theta, RNG &rng)
Definition: binomial_rng.hpp:30
stan::math::check_positive_finite
bool check_positive_finite(const char *function, const char *name, const T_y &y)
Return true if y is positive and finite.
Definition: check_positive_finite.hpp:28
binomial_rng.hpp

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