1 #ifndef __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__DISCRETE__BETA_BINOMIAL_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__DISCRETE__BETA_BINOMIAL_HPP__
16 template <
bool propto,
28 static const char*
function =
"stan::prob::beta_binomial_log(%1%)";
45 if (!
check_nonnegative(
function, N,
"Population size parameter", &logp, Policy()))
47 if (!
check_finite(
function, alpha,
"First prior sample size parameter", &logp,
50 if (!
check_positive(
function, alpha,
"First prior sample size parameter",
53 if (!
check_finite(
function, beta,
"Second prior sample size parameter",
56 if (!
check_positive(
function, beta,
"Second prior sample size parameter",
61 "Successes variable",
"Population size parameter",
"First prior sample size parameter",
"Second prior sample size parameter",
73 size_t size =
max_size(n, N, alpha, beta);
75 for (
size_t i = 0; i < size; i++) {
76 if (n_vec[i] < 0 || n_vec[i] > N_vec[i])
83 for (
size_t i = 0; i < size; i++) {
87 logp +=
lbeta(n_vec[i] + alpha_vec[i], N_vec[i] - n_vec[i] + beta_vec[i])
88 -
lbeta(alpha_vec[i],beta_vec[i]);
93 template <
bool propto,
100 const T_size1& alpha,
const T_size2& beta) {
101 return beta_binomial_log<propto>(n,N,alpha,beta,
105 template <
typename T_n,
113 const T_size1& alpha,
const T_size2& beta,
115 return beta_binomial_log<false>(n,N,alpha,beta,Policy());
118 template <
typename T_n,
124 const T_size1& alpha,
const T_size2& beta) {
125 return beta_binomial_log<false>(n,N,alpha,beta,
double value_of(T x)
Return the value of the specified scalar argument converted to a double value.
boost::math::tools::promote_args< T1, T2 >::type lbeta(T1 a, T2 b)
Return the log of the beta function applied to the specified arguments.
boost::math::tools::promote_args< T_N, T_n >::type binomial_coefficient_log(T_N N, T_n n)
Return the log of the binomial coefficient for the specified arguments.
bool check_consistent_sizes(const char *function, const T1 &x1, const T2 &x2, const char *name1, const char *name2, T_result *result, const Policy &)
bool check_positive(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
bool check_finite(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
Checks if the variable y is finite.
bool check_nonnegative(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
boost::math::policies::policy default_policy
Default error-handling policy from Boost.
return_type< T_size1, T_size2 >::type beta_binomial_log(const T_n &n, const T_N &N, const T_size1 &alpha, const T_size2 &beta, const Policy &)
Probability, optimization and sampling library.
size_t length(const T &x)
size_t max_size(const T1 &x1, const T2 &x2)
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
boost::math::tools::promote_args< typename scalar_type< T1 >::type, typename scalar_type< T2 >::type, typename scalar_type< T3 >::type, typename scalar_type< T4 >::type, typename scalar_type< T5 >::type, typename scalar_type< T6 >::type >::type type