1 #ifndef STAN_MATH_PRIM_FUN_INC_BETA_DDZ_HPP
2 #define STAN_MATH_PRIM_FUN_INC_BETA_DDZ_HPP
3
4 #include <stan/math/prim/meta.hpp>
5 #include <stan/math/prim/fun/exp.hpp>
6 #include <stan/math/prim/fun/lgamma.hpp>
7 #include <stan/math/prim/fun/log.hpp>
8 #include <boost/math/special_functions/beta.hpp>
9 #include <cmath>
10
11 namespace stan {
12 namespace math {
13
14 /**
15 * Returns the partial derivative of the regularized
16 * incomplete beta function, I_{z}(a, b) with respect to z.
17 *
18 * @tparam T scalar types of arguments
19 * @param a first argument
20 * @param b second argument
21 * @param z upper bound of the integral
22 * @return partial derivative of the incomplete beta with respect to z
23 *
24 * @pre a > 0
25 * @pre b > 0
26 * @pre 0 < z <= 1
27 */
28 template <typename T>
inc_beta_ddz(T a,T b,T z)29 T inc_beta_ddz(T a, T b, T z) {
30 using std::exp;
31 using std::log;
32 return exp((b - 1) * log(1 - z) + (a - 1) * log(z) + lgamma(a + b) - lgamma(a)
33 - lgamma(b));
34 }
35
36 template <>
inc_beta_ddz(double a,double b,double z)37 inline double inc_beta_ddz(double a, double b, double z) {
38 using boost::math::ibeta_derivative;
39 return ibeta_derivative(a, b, z);
40 }
41
42 } // namespace math
43 } // namespace stan
44 #endif
45