1 #ifndef STAN_MATH_PRIM_MAT_PROB_ORDERED_PROBIT_LPMF_HPP 2 #define STAN_MATH_PRIM_MAT_PROB_ORDERED_PROBIT_LPMF_HPP 39 template <
bool propto,
typename T_loc,
typename T_cut>
41 int y,
const T_loc& lambda,
42 const Eigen::Matrix<T_cut, Eigen::Dynamic, 1>& c) {
46 static const char*
function =
"ordered_probit";
52 check_greater(
function,
"Size of cut points parameter", c.size(), 0);
59 return log(
Phi(lambda - c[K - 2]));
61 return log(
Phi(lambda - c[y - 2]) -
Phi(lambda - c[y - 1]));
65 template <
typename T_loc,
typename T_cut>
67 int y,
const T_loc& lambda,
68 const Eigen::Matrix<T_cut, Eigen::Dynamic, 1>& c) {
69 return ordered_probit_lpmf<false>(y, lambda, c);
97 template <
bool propto,
typename T_loc,
typename T_cut>
99 const std::vector<int>& y,
100 const Eigen::Matrix<T_loc, Eigen::Dynamic, 1>& lambda,
101 const Eigen::Matrix<T_cut, Eigen::Dynamic, 1>& c) {
105 static const char*
function =
"ordered_probit";
107 int N = lambda.size();
108 int K = c.size() + 1;
114 check_greater(
function,
"Size of cut points parameter", c.size(), 0);
119 for (
int i = 0; i < N; ++i) {
121 logp_n +=
log1m(
Phi(lambda[i] - c[0]));
122 }
else if (y[i] == K) {
123 logp_n +=
log(
Phi(lambda[i] - c[K - 2]));
126 +=
log(
Phi(lambda[i] - c[y[i] - 2]) -
Phi(lambda[i] - c[y[i] - 1]));
132 template <
typename T_loc,
typename T_cut>
134 const std::vector<int>& y,
135 const Eigen::Matrix<T_loc, Eigen::Dynamic, 1>& lambda,
136 const Eigen::Matrix<T_cut, Eigen::Dynamic, 1>& c) {
137 return ordered_probit_lpmf<false>(y, lambda, c);
167 template <
bool propto,
typename T_loc,
typename T_cut>
169 const std::vector<int>& y,
170 const Eigen::Matrix<T_loc, Eigen::Dynamic, 1>& lambda,
171 const std::vector<Eigen::Matrix<T_cut, Eigen::Dynamic, 1> >& c) {
175 static const char*
function =
"ordered_probit";
177 int N = lambda.size();
182 for (
int i = 0; i < N; ++i) {
183 int K = c[i].size() + 1;
194 for (
int i = 0; i < N; ++i) {
195 int K = c[i].size() + 1;
198 logp_n +=
log1m(
Phi(lambda[i] - c[i][0]));
199 }
else if (y[i] == K) {
200 logp_n +=
log(
Phi(lambda[i] - c[i][K - 2]));
202 logp_n +=
log(
Phi(lambda[i] - c[i][y[i] - 2])
203 -
Phi(lambda[i] - c[i][y[i] - 1]));
209 template <
typename T_loc,
typename T_cut>
211 const std::vector<int>& y,
212 const Eigen::Matrix<T_loc, Eigen::Dynamic, 1>& lambda,
213 const std::vector<Eigen::Matrix<T_cut, Eigen::Dynamic, 1> >& c) {
214 return ordered_probit_lpmf<false>(y, lambda, c);
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
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.
return_type< T_loc, T_cut >::type ordered_probit_lpmf(int y, const T_loc &lambda, const Eigen::Matrix< T_cut, Eigen::Dynamic, 1 > &c)
Returns the (natural) log probability of the specified integer outcome given the continuous location ...
void check_ordered(const char *function, const char *name, const std::vector< T_y > &y)
Check if the specified vector is sorted into strictly increasing order.
fvar< T > log(const fvar< T > &x)
boost::math::tools::promote_args< double, typename scalar_type< T >::type, typename return_type< Types_pack... >::type >::type type
fvar< T > exp(const fvar< T > &x)
fvar< T > Phi(const fvar< T > &x)
int size(const std::vector< T > &x)
Return the size of the specified standard vector.
void check_greater(const char *function, const char *name, const T_y &y, const T_low &low)
Check if y is strictly greater than low.
void check_consistent_sizes(const char *function, const char *name1, const T1 &x1, const char *name2, const T2 &x2)
Check if the dimension of x1 is consistent with x2.
fvar< T > log1m(const fvar< T > &x)