@@ -9,7 +9,7 @@ namespace stan {
99namespace math {
1010
1111/* * \ingroup prob_dists
12- * Return a beta-negative binomial random variate with given number of
12+ * Return a beta-negative binomial random variate with the given number of
1313 * successes, prior success, and prior failure parameters, using the given
1414 * random number generator.
1515 *
@@ -22,17 +22,16 @@ namespace math {
2222 * @tparam RNG type of random number generator
2323 *
2424 * @param r (Sequence of) number of successes parameter(s)
25- * @param alpha (Sequence of) positive success parameter(s)
26- * @param beta (Sequence of) positive failure parameter(s)
25+ * @param alpha (Sequence of) prior success parameter(s)
26+ * @param beta (Sequence of) prior failure parameter(s)
2727 * @param rng random number generator
28- * @return (Sequence of) beta-binomial random variate(s)
29- * @throw std::domain_error if r is negative, or alpha or beta are nonpositive
28+ * @return (Sequence of) beta-negative binomial random variate(s)
29+ * @throw std::domain_error if r, alpha, or beta are nonpositive
3030 * @throw std::invalid_argument if non-scalar arguments are of different sizes
3131 */
32- template <typename T_r, typename T_alpha, typename T_beta, class RNG >
33- inline typename VectorBuilder<true , int , T_r, T_alpha, T_beta>::type
34- beta_neg_binomial_rng (const T_r &r, const T_alpha &alpha, const T_beta &beta,
35- RNG &rng) {
32+ template <typename T_r, typename T_alpha, typename T_beta, typename RNG>
33+ inline auto beta_neg_binomial_rng (const T_r &r, const T_alpha &alpha,
34+ const T_beta &beta, RNG &rng) {
3635 using T_r_ref = ref_type_t <T_r>;
3736 using T_alpha_ref = ref_type_t <T_alpha>;
3837 using T_beta_ref = ref_type_t <T_beta>;
@@ -55,8 +54,8 @@ beta_neg_binomial_rng(const T_r &r, const T_alpha &alpha, const T_beta &beta,
5554 size_t size_p = stan::math::size (p);
5655 VectorBuilder<true , double , T_p> odds_ratio_p (size_p);
5756 for (size_t n = 0 ; n < size_p; ++n) {
58- odds_ratio_p[n] = stan::math::exp ( stan::math::log (p_vec. val (n))
59- - stan::math::log (( 1 - p_vec.val (n) )));
57+ odds_ratio_p[n]
58+ = stan::math::exp ( stan::math:: log (p_vec. val (n)) - log1m ( p_vec.val (n)));
6059 }
6160
6261 return neg_binomial_rng (r_ref, odds_ratio_p.data (), rng);
0 commit comments