1#ifndef STAN_MATH_PRIM_PROB_STUDENT_T_QF_HPP
2#define STAN_MATH_PRIM_PROB_STUDENT_T_QF_HPP
28template <
typename T_p,
typename T_nu,
typename T_mu,
typename T_sigma,
29 require_all_stan_scalar_t<T_p, T_nu, T_mu, T_sigma>* =
nullptr,
30 require_all_arithmetic_t<T_p, T_nu, T_mu, T_sigma>* =
nullptr>
31inline double student_t_qf(
const T_p& p,
const T_nu& nu,
const T_mu& mu,
32 const T_sigma& sigma) {
33 static constexpr const char* function =
"student_t_qf";
36 check_bounded(function,
"Probability parameter", p, 0.0, 1.0);
40 }
else if (p == 1.0) {
42 }
else if (p == 0.5) {
46 const double p_val_flip = p < 0.5 ? p : 1.0 - p;
47 const double p_sign = p < 0.5 ? -1.0 : 1.0;
48 const auto ibeta_arg =
inv_inc_beta(0.5 * nu, 0.5, 2 * p_val_flip);
50 return mu + p_sign * sigma *
sqrt(nu) *
sqrt(-1.0 + 1.0 / ibeta_arg);
69template <
typename T_p,
typename T_nu,
typename T_mu,
typename T_sigma,
71inline auto student_t_qf(
const T_p& p,
const T_nu& nu,
const T_mu& mu,
72 const T_sigma& sigma) {
74 static constexpr const char* function =
"student_t_qf";
75 const size_t max_size_all =
max_size(p, nu, mu, sigma);
76 T_container result(max_size_all);
88 for (
size_t i = 0; i < max_size_all; ++i) {
89 result[i] =
student_t_qf(p_vec[i], nu_vec[i], mu_vec[i], sigma_vec[i]);
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
require_any_t< is_vector< std::decay_t< Types > >... > require_any_vector_t
Require any of the types satisfy is_vector.
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
void check_bounded(const char *function, const char *name, const T_y &y, const T_low &low, const T_high &high)
Check if the value is between the low and high values, inclusively.
static constexpr double NEGATIVE_INFTY
Negative infinity.
fvar< T > sqrt(const fvar< T > &x)
auto student_t_qf(const T_p &p, const T_nu &nu, const T_mu &mu, const T_sigma &sigma)
fvar< partials_return_t< T1, T2, T3 > > inv_inc_beta(const T1 &a, const T2 &b, const T3 &p)
The inverse of the normalized incomplete beta function of a, b, with probability p.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
static constexpr double INFTY
Positive infinity.
typename ref_type_if< true, T >::type ref_type_t
typename common_container_type< Ts... >::type common_container_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...