// Code generated by Stan version 2.21.0

#include <stan/model/model_header.hpp>

namespace model133b1e24db9f_8998817c4487de2904df0d3a87b5b712_namespace {

using std::istream;
using std::string;
using std::stringstream;
using std::vector;
using stan::io::dump;
using stan::math::lgamma;
using stan::model::prob_grad;
using namespace stan::math;

static int current_statement_begin__;

stan::io::program_reader prog_reader__() {
    stan::io::program_reader reader;
    reader.add_event(0, 0, "start", "model133b1e24db9f_8998817c4487de2904df0d3a87b5b712");
    reader.add_event(83, 81, "end", "model133b1e24db9f_8998817c4487de2904df0d3a87b5b712");
    return reader;
}

template <bool propto, typename T1__, typename T2__, typename T3__>
typename boost::math::tools::promote_args<T1__, T2__, T3__>::type
sratio_logit_lpmf(const int& y,
                      const T1__& mu,
                      const T2__& disc,
                      const Eigen::Matrix<T3__, Eigen::Dynamic, 1>& thres, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T1__, T2__, T3__>::type local_scalar_t__;
    typedef local_scalar_t__ fun_return_scalar_t__;
    const static bool propto__ = true;
    (void) propto__;
        local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
        (void) DUMMY_VAR__;  // suppress unused var warning

    int current_statement_begin__ = -1;
    try {
        {
        current_statement_begin__ = 13;
        int nthres(0);
        (void) nthres;  // dummy to suppress unused var warning
        stan::math::fill(nthres, std::numeric_limits<int>::min());
        stan::math::assign(nthres,num_elements(thres));

        current_statement_begin__ = 14;
        validate_non_negative_index("p", "(nthres + 1)", (nthres + 1));
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> p((nthres + 1));
        stan::math::initialize(p, DUMMY_VAR__);
        stan::math::fill(p, DUMMY_VAR__);

        current_statement_begin__ = 15;
        validate_non_negative_index("q", "nthres", nthres);
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> q(nthres);
        stan::math::initialize(q, DUMMY_VAR__);
        stan::math::fill(q, DUMMY_VAR__);

        current_statement_begin__ = 16;
        int k(0);
        (void) k;  // dummy to suppress unused var warning
        stan::math::fill(k, std::numeric_limits<int>::min());
        stan::math::assign(k,1);


        current_statement_begin__ = 17;
        while (as_bool(logical_lte(k, std::min(y, nthres)))) {

            current_statement_begin__ = 18;
            stan::model::assign(q, 
                        stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                        log1m_inv_logit((disc * (get_base1(thres, k, "thres", 1) - mu))), 
                        "assigning variable q");
            current_statement_begin__ = 19;
            stan::model::assign(p, 
                        stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                        log1m_exp(get_base1(q, k, "q", 1)), 
                        "assigning variable p");
            current_statement_begin__ = 20;
            for (int kk = 1; kk <= (k - 1); ++kk) {
                current_statement_begin__ = 20;
                stan::model::assign(p, 
                            stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                            (get_base1(p, k, "p", 1) + get_base1(q, kk, "q", 1)), 
                            "assigning variable p");
            }
            current_statement_begin__ = 21;
            stan::math::assign(k, (k + 1));
        }
        current_statement_begin__ = 23;
        if (as_bool(logical_eq(y, (nthres + 1)))) {

            current_statement_begin__ = 24;
            stan::model::assign(p, 
                        stan::model::cons_list(stan::model::index_uni((nthres + 1)), stan::model::nil_index_list()), 
                        sum(q), 
                        "assigning variable p");
        }
        current_statement_begin__ = 26;
        return stan::math::promote_scalar<fun_return_scalar_t__>(get_base1(p, y, "p", 1));
        }
    } catch (const std::exception& e) {
        stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
        // Next line prevents compiler griping about no return
        throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
    }
}
template <typename T1__, typename T2__, typename T3__>
typename boost::math::tools::promote_args<T1__, T2__, T3__>::type
sratio_logit_lpmf(const int& y,
                      const T1__& mu,
                      const T2__& disc,
                      const Eigen::Matrix<T3__, Eigen::Dynamic, 1>& thres, std::ostream* pstream__) {
    return sratio_logit_lpmf<false>(y,mu,disc,thres, pstream__);
}


struct sratio_logit_lpmf_functor__ {
    template <bool propto, typename T1__, typename T2__, typename T3__>
        typename boost::math::tools::promote_args<T1__, T2__, T3__>::type
    operator()(const int& y,
                      const T1__& mu,
                      const T2__& disc,
                      const Eigen::Matrix<T3__, Eigen::Dynamic, 1>& thres, std::ostream* pstream__) const {
        return sratio_logit_lpmf(y, mu, disc, thres, pstream__);
    }
};

template <bool propto, typename T1__, typename T2__, typename T3__>
typename boost::math::tools::promote_args<T1__, T2__, T3__>::type
sratio_logit_merged_lpmf(const int& y,
                             const T1__& mu,
                             const T2__& disc,
                             const Eigen::Matrix<T3__, Eigen::Dynamic, 1>& thres,
                             const std::vector<int>& j, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T1__, T2__, T3__>::type local_scalar_t__;
    typedef local_scalar_t__ fun_return_scalar_t__;
    const static bool propto__ = true;
    (void) propto__;
        local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
        (void) DUMMY_VAR__;  // suppress unused var warning

    int current_statement_begin__ = -1;
    try {

        current_statement_begin__ = 39;
        return stan::math::promote_scalar<fun_return_scalar_t__>(sratio_logit_lpmf(y, mu, disc, stan::model::rvalue(thres, stan::model::cons_list(stan::model::index_min_max(get_base1(j, 1, "j", 1), get_base1(j, 2, "j", 1)), stan::model::nil_index_list()), "thres"), pstream__));
    } catch (const std::exception& e) {
        stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
        // Next line prevents compiler griping about no return
        throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
    }
}
template <typename T1__, typename T2__, typename T3__>
typename boost::math::tools::promote_args<T1__, T2__, T3__>::type
sratio_logit_merged_lpmf(const int& y,
                             const T1__& mu,
                             const T2__& disc,
                             const Eigen::Matrix<T3__, Eigen::Dynamic, 1>& thres,
                             const std::vector<int>& j, std::ostream* pstream__) {
    return sratio_logit_merged_lpmf<false>(y,mu,disc,thres,j, pstream__);
}


struct sratio_logit_merged_lpmf_functor__ {
    template <bool propto, typename T1__, typename T2__, typename T3__>
        typename boost::math::tools::promote_args<T1__, T2__, T3__>::type
    operator()(const int& y,
                             const T1__& mu,
                             const T2__& disc,
                             const Eigen::Matrix<T3__, Eigen::Dynamic, 1>& thres,
                             const std::vector<int>& j, std::ostream* pstream__) const {
        return sratio_logit_merged_lpmf(y, mu, disc, thres, j, pstream__);
    }
};

class model133b1e24db9f_8998817c4487de2904df0d3a87b5b712
  : public stan::model::model_base_crtp<model133b1e24db9f_8998817c4487de2904df0d3a87b5b712> {
private:
        int N;
        std::vector<int> Y;
        int nthres;
        int K;
        matrix_d X;
        int prior_only;
        int Kc;
        matrix_d Xc;
        vector_d means_X;
public:
    model133b1e24db9f_8998817c4487de2904df0d3a87b5b712(rstan::io::rlist_ref_var_context& context__,
        std::ostream* pstream__ = 0)
        : model_base_crtp(0) {
        ctor_body(context__, 0, pstream__);
    }

    model133b1e24db9f_8998817c4487de2904df0d3a87b5b712(stan::io::var_context& context__,
        unsigned int random_seed__,
        std::ostream* pstream__ = 0)
        : model_base_crtp(0) {
        ctor_body(context__, random_seed__, pstream__);
    }

    void ctor_body(stan::io::var_context& context__,
                   unsigned int random_seed__,
                   std::ostream* pstream__) {
        typedef double local_scalar_t__;

        boost::ecuyer1988 base_rng__ =
          stan::services::util::create_rng(random_seed__, 0);
        (void) base_rng__;  // suppress unused var warning

        current_statement_begin__ = -1;

        static const char* function__ = "model133b1e24db9f_8998817c4487de2904df0d3a87b5b712_namespace::model133b1e24db9f_8998817c4487de2904df0d3a87b5b712";
        (void) function__;  // dummy to suppress unused var warning
        size_t pos__;
        (void) pos__;  // dummy to suppress unused var warning
        std::vector<int> vals_i__;
        std::vector<double> vals_r__;
        local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
        (void) DUMMY_VAR__;  // suppress unused var warning

        try {
            // initialize data block variables from context__
            current_statement_begin__ = 43;
            context__.validate_dims("data initialization", "N", "int", context__.to_vec());
            N = int(0);
            vals_i__ = context__.vals_i("N");
            pos__ = 0;
            N = vals_i__[pos__++];
            check_greater_or_equal(function__, "N", N, 1);

            current_statement_begin__ = 44;
            validate_non_negative_index("Y", "N", N);
            context__.validate_dims("data initialization", "Y", "int", context__.to_vec(N));
            Y = std::vector<int>(N, int(0));
            vals_i__ = context__.vals_i("Y");
            pos__ = 0;
            size_t Y_k_0_max__ = N;
            for (size_t k_0__ = 0; k_0__ < Y_k_0_max__; ++k_0__) {
                Y[k_0__] = vals_i__[pos__++];
            }

            current_statement_begin__ = 45;
            context__.validate_dims("data initialization", "nthres", "int", context__.to_vec());
            nthres = int(0);
            vals_i__ = context__.vals_i("nthres");
            pos__ = 0;
            nthres = vals_i__[pos__++];
            check_greater_or_equal(function__, "nthres", nthres, 2);

            current_statement_begin__ = 46;
            context__.validate_dims("data initialization", "K", "int", context__.to_vec());
            K = int(0);
            vals_i__ = context__.vals_i("K");
            pos__ = 0;
            K = vals_i__[pos__++];
            check_greater_or_equal(function__, "K", K, 1);

            current_statement_begin__ = 47;
            validate_non_negative_index("X", "N", N);
            validate_non_negative_index("X", "K", K);
            context__.validate_dims("data initialization", "X", "matrix_d", context__.to_vec(N,K));
            X = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>(N, K);
            vals_r__ = context__.vals_r("X");
            pos__ = 0;
            size_t X_j_2_max__ = K;
            size_t X_j_1_max__ = N;
            for (size_t j_2__ = 0; j_2__ < X_j_2_max__; ++j_2__) {
                for (size_t j_1__ = 0; j_1__ < X_j_1_max__; ++j_1__) {
                    X(j_1__, j_2__) = vals_r__[pos__++];
                }
            }

            current_statement_begin__ = 48;
            context__.validate_dims("data initialization", "prior_only", "int", context__.to_vec());
            prior_only = int(0);
            vals_i__ = context__.vals_i("prior_only");
            pos__ = 0;
            prior_only = vals_i__[pos__++];


            // initialize transformed data variables
            current_statement_begin__ = 51;
            Kc = int(0);
            stan::math::fill(Kc, std::numeric_limits<int>::min());
            stan::math::assign(Kc,K);

            current_statement_begin__ = 52;
            validate_non_negative_index("Xc", "N", N);
            validate_non_negative_index("Xc", "Kc", Kc);
            Xc = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>(N, Kc);
            stan::math::fill(Xc, DUMMY_VAR__);

            current_statement_begin__ = 53;
            validate_non_negative_index("means_X", "Kc", Kc);
            means_X = Eigen::Matrix<double, Eigen::Dynamic, 1>(Kc);
            stan::math::fill(means_X, DUMMY_VAR__);

            // execute transformed data statements
            current_statement_begin__ = 54;
            for (int i = 1; i <= K; ++i) {

                current_statement_begin__ = 55;
                stan::model::assign(means_X, 
                            stan::model::cons_list(stan::model::index_uni(i), stan::model::nil_index_list()), 
                            mean(stan::model::rvalue(X, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(i), stan::model::nil_index_list())), "X")), 
                            "assigning variable means_X");
                current_statement_begin__ = 56;
                stan::model::assign(Xc, 
                            stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(i), stan::model::nil_index_list())), 
                            subtract(stan::model::rvalue(X, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(i), stan::model::nil_index_list())), "X"), get_base1(means_X, i, "means_X", 1)), 
                            "assigning variable Xc");
            }

            // validate transformed data

            // validate, set parameter ranges
            num_params_r__ = 0U;
            param_ranges_i__.clear();
            current_statement_begin__ = 60;
            validate_non_negative_index("b", "Kc", Kc);
            num_params_r__ += Kc;
            current_statement_begin__ = 61;
            validate_non_negative_index("Intercept", "nthres", nthres);
            num_params_r__ += nthres;
        } catch (const std::exception& e) {
            stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
            // Next line prevents compiler griping about no return
            throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
        }
    }

    ~model133b1e24db9f_8998817c4487de2904df0d3a87b5b712() { }


    void transform_inits(const stan::io::var_context& context__,
                         std::vector<int>& params_i__,
                         std::vector<double>& params_r__,
                         std::ostream* pstream__) const {
        typedef double local_scalar_t__;
        stan::io::writer<double> writer__(params_r__, params_i__);
        size_t pos__;
        (void) pos__; // dummy call to supress warning
        std::vector<double> vals_r__;
        std::vector<int> vals_i__;

        current_statement_begin__ = 60;
        if (!(context__.contains_r("b")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable b missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("b");
        pos__ = 0U;
        validate_non_negative_index("b", "Kc", Kc);
        context__.validate_dims("parameter initialization", "b", "vector_d", context__.to_vec(Kc));
        Eigen::Matrix<double, Eigen::Dynamic, 1> b(Kc);
        size_t b_j_1_max__ = Kc;
        for (size_t j_1__ = 0; j_1__ < b_j_1_max__; ++j_1__) {
            b(j_1__) = vals_r__[pos__++];
        }
        try {
            writer__.vector_unconstrain(b);
        } catch (const std::exception& e) {
            stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable b: ") + e.what()), current_statement_begin__, prog_reader__());
        }

        current_statement_begin__ = 61;
        if (!(context__.contains_r("Intercept")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable Intercept missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("Intercept");
        pos__ = 0U;
        validate_non_negative_index("Intercept", "nthres", nthres);
        context__.validate_dims("parameter initialization", "Intercept", "vector_d", context__.to_vec(nthres));
        Eigen::Matrix<double, Eigen::Dynamic, 1> Intercept(nthres);
        size_t Intercept_j_1_max__ = nthres;
        for (size_t j_1__ = 0; j_1__ < Intercept_j_1_max__; ++j_1__) {
            Intercept(j_1__) = vals_r__[pos__++];
        }
        try {
            writer__.vector_unconstrain(Intercept);
        } catch (const std::exception& e) {
            stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable Intercept: ") + e.what()), current_statement_begin__, prog_reader__());
        }

        params_r__ = writer__.data_r();
        params_i__ = writer__.data_i();
    }

    void transform_inits(const stan::io::var_context& context,
                         Eigen::Matrix<double, Eigen::Dynamic, 1>& params_r,
                         std::ostream* pstream__) const {
      std::vector<double> params_r_vec;
      std::vector<int> params_i_vec;
      transform_inits(context, params_i_vec, params_r_vec, pstream__);
      params_r.resize(params_r_vec.size());
      for (int i = 0; i < params_r.size(); ++i)
        params_r(i) = params_r_vec[i];
    }


    template <bool propto__, bool jacobian__, typename T__>
    T__ log_prob(std::vector<T__>& params_r__,
                 std::vector<int>& params_i__,
                 std::ostream* pstream__ = 0) const {

        typedef T__ local_scalar_t__;

        local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
        (void) DUMMY_VAR__;  // dummy to suppress unused var warning

        T__ lp__(0.0);
        stan::math::accumulator<T__> lp_accum__;
        try {
            stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);

            // model parameters
            current_statement_begin__ = 60;
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> b;
            (void) b;  // dummy to suppress unused var warning
            if (jacobian__)
                b = in__.vector_constrain(Kc, lp__);
            else
                b = in__.vector_constrain(Kc);

            current_statement_begin__ = 61;
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> Intercept;
            (void) Intercept;  // dummy to suppress unused var warning
            if (jacobian__)
                Intercept = in__.vector_constrain(nthres, lp__);
            else
                Intercept = in__.vector_constrain(nthres);

            // transformed parameters
            current_statement_begin__ = 64;
            local_scalar_t__ disc;
            (void) disc;  // dummy to suppress unused var warning
            stan::math::initialize(disc, DUMMY_VAR__);
            stan::math::fill(disc, DUMMY_VAR__);
            stan::math::assign(disc,1);

            // validate transformed parameters
            const char* function__ = "validate transformed params";
            (void) function__;  // dummy to suppress unused var warning

            current_statement_begin__ = 64;
            if (stan::math::is_uninitialized(disc)) {
                std::stringstream msg__;
                msg__ << "Undefined transformed parameter: disc";
                stan::lang::rethrow_located(std::runtime_error(std::string("Error initializing variable disc: ") + msg__.str()), current_statement_begin__, prog_reader__());
            }
            check_greater_or_equal(function__, "disc", disc, 0);


            // model body

            current_statement_begin__ = 68;
            if (as_bool(logical_negation(prior_only))) {
                {
                current_statement_begin__ = 70;
                validate_non_negative_index("mu", "N", N);
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> mu(N);
                stan::math::initialize(mu, DUMMY_VAR__);
                stan::math::fill(mu, DUMMY_VAR__);
                stan::math::assign(mu,multiply(Xc, b));


                current_statement_begin__ = 71;
                for (int n = 1; n <= N; ++n) {

                    current_statement_begin__ = 72;
                    lp_accum__.add(sratio_logit_lpmf(get_base1(Y, n, "Y", 1), get_base1(mu, n, "mu", 1), disc, Intercept, pstream__));
                }
                }
            }
            current_statement_begin__ = 76;
            lp_accum__.add(student_t_log(Intercept, 3, 0, 2.5));

        } catch (const std::exception& e) {
            stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
            // Next line prevents compiler griping about no return
            throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
        }

        lp_accum__.add(lp__);
        return lp_accum__.sum();

    } // log_prob()

    template <bool propto, bool jacobian, typename T_>
    T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
               std::ostream* pstream = 0) const {
      std::vector<T_> vec_params_r;
      vec_params_r.reserve(params_r.size());
      for (int i = 0; i < params_r.size(); ++i)
        vec_params_r.push_back(params_r(i));
      std::vector<int> vec_params_i;
      return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
    }


    void get_param_names(std::vector<std::string>& names__) const {
        names__.resize(0);
        names__.push_back("b");
        names__.push_back("Intercept");
        names__.push_back("disc");
        names__.push_back("b_Intercept");
    }


    void get_dims(std::vector<std::vector<size_t> >& dimss__) const {
        dimss__.resize(0);
        std::vector<size_t> dims__;
        dims__.resize(0);
        dims__.push_back(Kc);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(nthres);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(nthres);
        dimss__.push_back(dims__);
    }

    template <typename RNG>
    void write_array(RNG& base_rng__,
                     std::vector<double>& params_r__,
                     std::vector<int>& params_i__,
                     std::vector<double>& vars__,
                     bool include_tparams__ = true,
                     bool include_gqs__ = true,
                     std::ostream* pstream__ = 0) const {
        typedef double local_scalar_t__;

        vars__.resize(0);
        stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
        static const char* function__ = "model133b1e24db9f_8998817c4487de2904df0d3a87b5b712_namespace::write_array";
        (void) function__;  // dummy to suppress unused var warning

        // read-transform, write parameters
        Eigen::Matrix<double, Eigen::Dynamic, 1> b = in__.vector_constrain(Kc);
        size_t b_j_1_max__ = Kc;
        for (size_t j_1__ = 0; j_1__ < b_j_1_max__; ++j_1__) {
            vars__.push_back(b(j_1__));
        }

        Eigen::Matrix<double, Eigen::Dynamic, 1> Intercept = in__.vector_constrain(nthres);
        size_t Intercept_j_1_max__ = nthres;
        for (size_t j_1__ = 0; j_1__ < Intercept_j_1_max__; ++j_1__) {
            vars__.push_back(Intercept(j_1__));
        }

        double lp__ = 0.0;
        (void) lp__;  // dummy to suppress unused var warning
        stan::math::accumulator<double> lp_accum__;

        local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
        (void) DUMMY_VAR__;  // suppress unused var warning

        if (!include_tparams__ && !include_gqs__) return;

        try {
            // declare and define transformed parameters
            current_statement_begin__ = 64;
            double disc;
            (void) disc;  // dummy to suppress unused var warning
            stan::math::initialize(disc, DUMMY_VAR__);
            stan::math::fill(disc, DUMMY_VAR__);
            stan::math::assign(disc,1);

            if (!include_gqs__ && !include_tparams__) return;
            // validate transformed parameters
            const char* function__ = "validate transformed params";
            (void) function__;  // dummy to suppress unused var warning

            current_statement_begin__ = 64;
            check_greater_or_equal(function__, "disc", disc, 0);

            // write transformed parameters
            if (include_tparams__) {
                vars__.push_back(disc);
            }
            if (!include_gqs__) return;
            // declare and define generated quantities
            current_statement_begin__ = 80;
            validate_non_negative_index("b_Intercept", "nthres", nthres);
            Eigen::Matrix<double, Eigen::Dynamic, 1> b_Intercept(nthres);
            stan::math::initialize(b_Intercept, DUMMY_VAR__);
            stan::math::fill(b_Intercept, DUMMY_VAR__);
            stan::math::assign(b_Intercept,add(Intercept, dot_product(means_X, b)));

            // validate, write generated quantities
            current_statement_begin__ = 80;
            size_t b_Intercept_j_1_max__ = nthres;
            for (size_t j_1__ = 0; j_1__ < b_Intercept_j_1_max__; ++j_1__) {
                vars__.push_back(b_Intercept(j_1__));
            }

        } catch (const std::exception& e) {
            stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
            // Next line prevents compiler griping about no return
            throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
        }
    }

    template <typename RNG>
    void write_array(RNG& base_rng,
                     Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
                     Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
                     bool include_tparams = true,
                     bool include_gqs = true,
                     std::ostream* pstream = 0) const {
      std::vector<double> params_r_vec(params_r.size());
      for (int i = 0; i < params_r.size(); ++i)
        params_r_vec[i] = params_r(i);
      std::vector<double> vars_vec;
      std::vector<int> params_i_vec;
      write_array(base_rng, params_r_vec, params_i_vec, vars_vec, include_tparams, include_gqs, pstream);
      vars.resize(vars_vec.size());
      for (int i = 0; i < vars.size(); ++i)
        vars(i) = vars_vec[i];
    }

    std::string model_name() const {
        return "model133b1e24db9f_8998817c4487de2904df0d3a87b5b712";
    }


    void constrained_param_names(std::vector<std::string>& param_names__,
                                 bool include_tparams__ = true,
                                 bool include_gqs__ = true) const {
        std::stringstream param_name_stream__;
        size_t b_j_1_max__ = Kc;
        for (size_t j_1__ = 0; j_1__ < b_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "b" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t Intercept_j_1_max__ = nthres;
        for (size_t j_1__ = 0; j_1__ < Intercept_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "Intercept" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }

        if (!include_gqs__ && !include_tparams__) return;

        if (include_tparams__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "disc";
            param_names__.push_back(param_name_stream__.str());
        }

        if (!include_gqs__) return;
        size_t b_Intercept_j_1_max__ = nthres;
        for (size_t j_1__ = 0; j_1__ < b_Intercept_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "b_Intercept" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
    }


    void unconstrained_param_names(std::vector<std::string>& param_names__,
                                   bool include_tparams__ = true,
                                   bool include_gqs__ = true) const {
        std::stringstream param_name_stream__;
        size_t b_j_1_max__ = Kc;
        for (size_t j_1__ = 0; j_1__ < b_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "b" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t Intercept_j_1_max__ = nthres;
        for (size_t j_1__ = 0; j_1__ < Intercept_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "Intercept" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }

        if (!include_gqs__ && !include_tparams__) return;

        if (include_tparams__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "disc";
            param_names__.push_back(param_name_stream__.str());
        }

        if (!include_gqs__) return;
        size_t b_Intercept_j_1_max__ = nthres;
        for (size_t j_1__ = 0; j_1__ < b_Intercept_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "b_Intercept" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
    }

}; // model

}  // namespace

typedef model133b1e24db9f_8998817c4487de2904df0d3a87b5b712_namespace::model133b1e24db9f_8998817c4487de2904df0d3a87b5b712 stan_model;

#ifndef USING_R

stan::model::model_base& new_model(
        stan::io::var_context& data_context,
        unsigned int seed,
        std::ostream* msg_stream) {
  stan_model* m = new stan_model(data_context, seed, msg_stream);
  return *m;
}

#endif