1#ifndef STAN_MATH_PRIM_PROB_BERNOULLI_LOGIT_GLM_RNG_HPP
2#define STAN_MATH_PRIM_PROB_BERNOULLI_LOGIT_GLM_RNG_HPP
11#include <boost/random/bernoulli_distribution.hpp>
12#include <boost/random/variate_generator.hpp>
42template <
typename T_x,
typename T_alpha,
typename T_beta,
class RNG>
44 const T_x& x,
const T_alpha& alpha,
const T_beta&
beta, RNG& rng) {
45 using boost::bernoulli_distribution;
46 using boost::variate_generator;
51 const size_t N = x.cols();
52 const size_t M = x.rows();
54 static constexpr const char* function =
"bernoulli_logit_glm_rng";
58 T_alpha_ref alpha_ref = alpha;
59 T_beta_ref beta_ref =
beta;
60 check_finite(function,
"Matrix of independent variables", x_ref);
66 Eigen::VectorXd x_beta;
68 x_beta = x_ref * beta_vector;
70 x_beta = (x_ref.array() * forward_as<double>(beta_vector)).rowwise().sum();
77 for (
size_t m = 0; m < M; ++m) {
78 double theta_m = alpha_vec[m] + x_beta(m);
79 variate_generator<RNG&, bernoulli_distribution<>>
bernoulli_rng(
80 rng, bernoulli_distribution<>(
inv_logit(theta_m)));
typename helper::type type
VectorBuilder allocates type T1 values to be used as intermediate values.
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
VectorBuilder< true, int, T_alpha >::type bernoulli_logit_glm_rng(const T_x &x, const T_alpha &alpha, const T_beta &beta, RNG &rng)
Returns a draw from the Generalized Linear Model (GLM) with Bernoulli distribution and logit link fun...
auto as_column_vector_or_scalar(T &&a)
as_column_vector_or_scalar of a kernel generator expression.
VectorBuilder< true, int, T_theta >::type bernoulli_rng(const T_theta &theta, RNG &rng)
Return a Bernoulli random variate with specified chance of success parameter using the specified rand...
void check_consistent_size(const char *function, const char *name, const T &x, size_t expected_size)
Check if x is consistent with size expected_size.
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
fvar< T > inv_logit(const fvar< T > &x)
Returns the inverse logit function applied to the argument.
fvar< T > beta(const fvar< T > &x1, const fvar< T > &x2)
Return fvar with the beta function applied to the specified arguments and its gradient.
typename ref_type_if< true, T >::type ref_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
If the input type T is either an eigen matrix with 1 column or 1 row at compile time or a standard ve...