1 #ifndef STAN_MATH_PRIM_MAT_PROB_BERNOULLI_LOGIT_GLM_RNG_HPP 2 #define STAN_MATH_PRIM_MAT_PROB_BERNOULLI_LOGIT_GLM_RNG_HPP 10 #include <boost/random/bernoulli_distribution.hpp> 11 #include <boost/random/variate_generator.hpp> 41 template <
typename T_x,
typename T_alpha,
typename T_beta,
class RNG>
43 const T_x &x,
const T_alpha &alpha,
const T_beta &
beta, RNG &rng) {
44 using boost::bernoulli_distribution;
45 using boost::variate_generator;
47 static const char *
function =
"bernoulli_logit_glm_rng";
49 const size_t N = x.col(0).size();
50 const size_t M = x.row(0).size();
52 check_finite(
function,
"Matrix of independent variables", x);
59 Eigen::VectorXd beta_vector(M);
60 for (
int i = 0; i < M; ++i)
61 beta_vector[i] = beta_vec[i];
63 Eigen::VectorXd x_beta = x * beta_vector;
69 for (
size_t n = 0; n < N; ++n) {
70 double theta_n = alpha_vec[n] + x_beta(n);
71 variate_generator<RNG &, bernoulli_distribution<>>
bernoulli_rng(
72 rng, bernoulli_distribution<>(
inv_logit(theta_n)));
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
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...
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...
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
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.
void check_consistent_size(const char *function, const char *name, const T &x, size_t expected_size)
Check if the dimension of x is consistent, which is defined to be expected_size if x is a vector or 1...
VectorBuilder allocates type T1 values to be used as intermediate values.