1 #ifndef __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__STUDENT_T_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__STUDENT_T_HPP__
40 template <
bool propto,
typename T_y,
typename T_dof,
41 typename T_loc,
typename T_scale,
47 static const char*
function =
"stan::prob::student_t_log(%1%)";
64 if (!
check_not_nan(
function, y,
"Random variable", &logp, Policy()))
66 if(!
check_finite(
function, nu,
"Degrees of freedom parameter", &logp, Policy()))
68 if(!
check_positive(
function, nu,
"Degrees of freedom parameter", &logp, Policy()))
83 "Random variable",
"Degrees of freedom parameter",
"Location parameter",
"Scale parameter",
95 size_t N =
max_size(y, nu, mu, sigma);
102 for (
size_t n = 0; n < N; n++) {
104 logp +=
lgamma( (nu_vec[n] + 1.0) / 2.0) -
lgamma(nu_vec[n] / 2.0);
106 logp += NEG_LOG_SQRT_PI;
108 logp -= 0.5 *
log(nu_vec[n]);
110 logp -=
log(sigma_vec[n]);
112 logp -= ((nu_vec[n] + 1.0) / 2.0)
113 *
log1p(
square(((y_vec[n] - mu_vec[n]) / sigma_vec[n])) / nu_vec[n]);
118 template <
bool propto,
119 typename T_y,
typename T_dof,
typename T_loc,
typename T_scale>
123 const T_scale& sigma) {
127 template <
typename T_y,
typename T_dof,
typename T_loc,
typename T_scale,
132 const T_scale& sigma,
134 return student_t_log<false>(y,nu,mu,sigma,Policy());
137 template <
typename T_y,
typename T_dof,
typename T_loc,
typename T_scale>
141 const T_scale& sigma) {
var square(const var &x)
Return the square of the input variable.
var log1p(const stan::agrad::var &a)
The log (1 + x) function for variables (C99).
var lgamma(const stan::agrad::var &a)
The log gamma function for variables (C99).
var log(const var &a)
Return the natural log of the specified variable (cmath).
T square(T x)
Return the square of the specified argument.
bool check_not_nan(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
Checks if the variable y is nan.
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.
boost::math::policies::policy default_policy
Default error-handling policy from Boost.
return_type< T_y, T_dof, T_loc, T_scale >::type student_t_log(const T_y &y, const T_dof &nu, const T_loc &mu, const T_scale &sigma, const Policy &)
The log of the Student-t density for the given y, nu, mean, and scale parameter.
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