// Code generated by Stan version 2.19.1

#include <stan/model/model_header.hpp>

namespace model_count_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", "model_count");
    reader.add_event(0, 0, "include", "/pre/Columbia_copyright.stan");
    reader.add_event(0, 0, "start", "/pre/Columbia_copyright.stan");
    reader.add_event(3, 3, "end", "/pre/Columbia_copyright.stan");
    reader.add_event(3, 1, "restart", "model_count");
    reader.add_event(3, 1, "include", "/pre/license.stan");
    reader.add_event(3, 0, "start", "/pre/license.stan");
    reader.add_event(17, 14, "end", "/pre/license.stan");
    reader.add_event(17, 2, "restart", "model_count");
    reader.add_event(20, 5, "include", "/functions/common_functions.stan");
    reader.add_event(20, 0, "start", "/functions/common_functions.stan");
    reader.add_event(319, 299, "end", "/functions/common_functions.stan");
    reader.add_event(319, 6, "restart", "model_count");
    reader.add_event(319, 6, "include", "/functions/count_likelihoods.stan");
    reader.add_event(319, 0, "start", "/functions/count_likelihoods.stan");
    reader.add_event(372, 53, "end", "/functions/count_likelihoods.stan");
    reader.add_event(372, 7, "restart", "model_count");
    reader.add_event(375, 10, "include", "/data/NKX.stan");
    reader.add_event(375, 0, "start", "/data/NKX.stan");
    reader.add_event(395, 20, "end", "/data/NKX.stan");
    reader.add_event(395, 11, "restart", "model_count");
    reader.add_event(397, 13, "include", "/data/data_glm.stan");
    reader.add_event(397, 0, "start", "/data/data_glm.stan");
    reader.add_event(417, 20, "end", "/data/data_glm.stan");
    reader.add_event(417, 14, "restart", "model_count");
    reader.add_event(418, 15, "include", "/data/weights_offset.stan");
    reader.add_event(418, 0, "start", "/data/weights_offset.stan");
    reader.add_event(425, 7, "end", "/data/weights_offset.stan");
    reader.add_event(425, 16, "restart", "model_count");
    reader.add_event(427, 18, "include", "/data/hyperparameters.stan");
    reader.add_event(427, 0, "start", "/data/hyperparameters.stan");
    reader.add_event(445, 18, "end", "/data/hyperparameters.stan");
    reader.add_event(445, 19, "restart", "model_count");
    reader.add_event(446, 20, "include", "/data/glmer_stuff.stan");
    reader.add_event(446, 0, "start", "/data/glmer_stuff.stan");
    reader.add_event(461, 15, "end", "/data/glmer_stuff.stan");
    reader.add_event(461, 21, "restart", "model_count");
    reader.add_event(462, 22, "include", "/data/glmer_stuff2.stan");
    reader.add_event(462, 0, "start", "/data/glmer_stuff2.stan");
    reader.add_event(467, 5, "end", "/data/glmer_stuff2.stan");
    reader.add_event(467, 23, "restart", "model_count");
    reader.add_event(476, 32, "include", "/tdata/tdata_glm.stan");
    reader.add_event(476, 0, "start", "/tdata/tdata_glm.stan");
    reader.add_event(497, 21, "end", "/tdata/tdata_glm.stan");
    reader.add_event(497, 33, "restart", "model_count");
    reader.add_event(505, 41, "include", "/parameters/parameters_glm.stan");
    reader.add_event(505, 0, "start", "/parameters/parameters_glm.stan");
    reader.add_event(518, 13, "end", "/parameters/parameters_glm.stan");
    reader.add_event(518, 42, "restart", "model_count");
    reader.add_event(524, 48, "include", "/tparameters/tparameters_glm.stan");
    reader.add_event(524, 0, "start", "/tparameters/tparameters_glm.stan");
    reader.add_event(569, 45, "end", "/tparameters/tparameters_glm.stan");
    reader.add_event(569, 49, "restart", "model_count");
    reader.add_event(617, 97, "include", "/model/make_eta.stan");
    reader.add_event(617, 0, "start", "/model/make_eta.stan");
    reader.add_event(625, 8, "end", "/model/make_eta.stan");
    reader.add_event(625, 98, "restart", "model_count");
    reader.add_event(626, 99, "include", "/model/eta_add_Zb.stan");
    reader.add_event(626, 0, "start", "/model/eta_add_Zb.stan");
    reader.add_event(628, 2, "end", "/model/eta_add_Zb.stan");
    reader.add_event(628, 100, "restart", "model_count");
    reader.add_event(634, 106, "include", "/model/eta_no_intercept.stan");
    reader.add_event(634, 0, "start", "/model/eta_no_intercept.stan");
    reader.add_event(636, 2, "end", "/model/eta_no_intercept.stan");
    reader.add_event(636, 107, "restart", "model_count");
    reader.add_event(676, 147, "include", "/model/priors_glm.stan");
    reader.add_event(676, 0, "start", "/model/priors_glm.stan");
    reader.add_event(736, 60, "end", "/model/priors_glm.stan");
    reader.add_event(736, 148, "restart", "model_count");
    reader.add_event(756, 168, "include", "/model/make_eta.stan");
    reader.add_event(756, 0, "start", "/model/make_eta.stan");
    reader.add_event(764, 8, "end", "/model/make_eta.stan");
    reader.add_event(764, 169, "restart", "model_count");
    reader.add_event(765, 170, "include", "/model/eta_add_Zb.stan");
    reader.add_event(765, 0, "start", "/model/eta_add_Zb.stan");
    reader.add_event(767, 2, "end", "/model/eta_add_Zb.stan");
    reader.add_event(767, 171, "restart", "model_count");
    reader.add_event(777, 181, "include", "/model/eta_no_intercept.stan");
    reader.add_event(777, 0, "start", "/model/eta_no_intercept.stan");
    reader.add_event(779, 2, "end", "/model/eta_no_intercept.stan");
    reader.add_event(779, 182, "restart", "model_count");
    reader.add_event(807, 208, "end", "model_count");
    return reader;
}

template <typename T2__, typename T3__, typename T4__, typename T5__, typename T6__, typename T7__>
Eigen::Matrix<typename boost::math::tools::promote_args<T2__, T3__, T4__, T5__, typename boost::math::tools::promote_args<T6__, T7__>::type>::type, Eigen::Dynamic, 1>
make_theta_L(const int& len_theta_L,
                 const std::vector<int>& p,
                 const T2__& dispersion,
                 const Eigen::Matrix<T3__, Eigen::Dynamic, 1>& tau,
                 const Eigen::Matrix<T4__, Eigen::Dynamic, 1>& scale,
                 const Eigen::Matrix<T5__, Eigen::Dynamic, 1>& zeta,
                 const Eigen::Matrix<T6__, Eigen::Dynamic, 1>& rho,
                 const Eigen::Matrix<T7__, Eigen::Dynamic, 1>& z_T, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T2__, T3__, T4__, T5__, typename boost::math::tools::promote_args<T6__, T7__>::type>::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__ = 42;
        validate_non_negative_index("theta_L", "len_theta_L", len_theta_L);
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> theta_L(len_theta_L);
        stan::math::initialize(theta_L, DUMMY_VAR__);
        stan::math::fill(theta_L, DUMMY_VAR__);

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

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

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

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


        current_statement_begin__ = 49;
        for (int i = 1; i <= size(p); ++i) {
            {
            current_statement_begin__ = 50;
            int nc(0);
            (void) nc;  // dummy to suppress unused var warning
            stan::math::fill(nc, std::numeric_limits<int>::min());
            stan::math::assign(nc,get_base1(p, i, "p", 1));


            current_statement_begin__ = 51;
            if (as_bool(logical_eq(nc, 1))) {

                current_statement_begin__ = 52;
                stan::model::assign(theta_L, 
                            stan::model::cons_list(stan::model::index_uni(theta_L_mark), stan::model::nil_index_list()), 
                            ((get_base1(tau, i, "tau", 1) * get_base1(scale, i, "scale", 1)) * dispersion), 
                            "assigning variable theta_L");
                current_statement_begin__ = 54;
                stan::math::assign(theta_L_mark, (theta_L_mark + 1));
            } else {
                {
                current_statement_begin__ = 57;
                validate_non_negative_index("T_i", "nc", nc);
                validate_non_negative_index("T_i", "nc", nc);
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, Eigen::Dynamic> T_i(nc, nc);
                stan::math::initialize(T_i, DUMMY_VAR__);
                stan::math::fill(T_i, DUMMY_VAR__);

                current_statement_begin__ = 58;
                local_scalar_t__ std_dev(DUMMY_VAR__);
                (void) std_dev;  // dummy to suppress unused var warning
                stan::math::initialize(std_dev, DUMMY_VAR__);
                stan::math::fill(std_dev, DUMMY_VAR__);

                current_statement_begin__ = 59;
                local_scalar_t__ T21(DUMMY_VAR__);
                (void) T21;  // dummy to suppress unused var warning
                stan::math::initialize(T21, DUMMY_VAR__);
                stan::math::fill(T21, DUMMY_VAR__);

                current_statement_begin__ = 60;
                local_scalar_t__ trace_T_i(DUMMY_VAR__);
                (void) trace_T_i;  // dummy to suppress unused var warning
                stan::math::initialize(trace_T_i, DUMMY_VAR__);
                stan::math::fill(trace_T_i, DUMMY_VAR__);
                stan::math::assign(trace_T_i,(square(((get_base1(tau, i, "tau", 1) * get_base1(scale, i, "scale", 1)) * dispersion)) * nc));

                current_statement_begin__ = 61;
                validate_non_negative_index("pi", "nc", nc);
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> pi(nc);
                stan::math::initialize(pi, DUMMY_VAR__);
                stan::math::fill(pi, DUMMY_VAR__);
                stan::math::assign(pi,segment(zeta, zeta_mark, nc));


                current_statement_begin__ = 62;
                stan::math::assign(pi, divide(pi, sum(pi)));
                current_statement_begin__ = 65;
                stan::math::assign(zeta_mark, (zeta_mark + nc));
                current_statement_begin__ = 66;
                stan::math::assign(std_dev, stan::math::sqrt((get_base1(pi, 1, "pi", 1) * trace_T_i)));
                current_statement_begin__ = 67;
                stan::model::assign(T_i, 
                            stan::model::cons_list(stan::model::index_uni(1), stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list())), 
                            std_dev, 
                            "assigning variable T_i");
                current_statement_begin__ = 70;
                stan::math::assign(std_dev, stan::math::sqrt((get_base1(pi, 2, "pi", 1) * trace_T_i)));
                current_statement_begin__ = 71;
                stan::math::assign(T21, ((2.0 * get_base1(rho, rho_mark, "rho", 1)) - 1.0));
                current_statement_begin__ = 72;
                stan::math::assign(rho_mark, (rho_mark + 1));
                current_statement_begin__ = 73;
                stan::model::assign(T_i, 
                            stan::model::cons_list(stan::model::index_uni(2), stan::model::cons_list(stan::model::index_uni(2), stan::model::nil_index_list())), 
                            (std_dev * stan::math::sqrt((1.0 - square(T21)))), 
                            "assigning variable T_i");
                current_statement_begin__ = 74;
                stan::model::assign(T_i, 
                            stan::model::cons_list(stan::model::index_uni(2), stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list())), 
                            (std_dev * T21), 
                            "assigning variable T_i");
                current_statement_begin__ = 76;
                for (int r = 2; r <= (nc - 1); ++r) {
                    {
                    current_statement_begin__ = 77;
                    int rp1(0);
                    (void) rp1;  // dummy to suppress unused var warning
                    stan::math::fill(rp1, std::numeric_limits<int>::min());
                    stan::math::assign(rp1,(r + 1));

                    current_statement_begin__ = 78;
                    validate_non_negative_index("T_row", "r", r);
                    Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> T_row(r);
                    stan::math::initialize(T_row, DUMMY_VAR__);
                    stan::math::fill(T_row, DUMMY_VAR__);
                    stan::math::assign(T_row,segment(z_T, z_T_mark, r));

                    current_statement_begin__ = 79;
                    local_scalar_t__ scale_factor(DUMMY_VAR__);
                    (void) scale_factor;  // dummy to suppress unused var warning
                    stan::math::initialize(scale_factor, DUMMY_VAR__);
                    stan::math::fill(scale_factor, DUMMY_VAR__);
                    stan::math::assign(scale_factor,(stan::math::sqrt((get_base1(rho, rho_mark, "rho", 1) / dot_self(T_row))) * std_dev));


                    current_statement_begin__ = 80;
                    stan::math::assign(z_T_mark, (z_T_mark + r));
                    current_statement_begin__ = 81;
                    stan::math::assign(std_dev, stan::math::sqrt((get_base1(pi, rp1, "pi", 1) * trace_T_i)));
                    current_statement_begin__ = 82;
                    for (int c = 1; c <= r; ++c) {
                        current_statement_begin__ = 82;
                        stan::model::assign(T_i, 
                                    stan::model::cons_list(stan::model::index_uni(rp1), stan::model::cons_list(stan::model::index_uni(c), stan::model::nil_index_list())), 
                                    (get_base1(T_row, c, "T_row", 1) * scale_factor), 
                                    "assigning variable T_i");
                    }
                    current_statement_begin__ = 83;
                    stan::model::assign(T_i, 
                                stan::model::cons_list(stan::model::index_uni(rp1), stan::model::cons_list(stan::model::index_uni(rp1), stan::model::nil_index_list())), 
                                (stan::math::sqrt((1.0 - get_base1(rho, rho_mark, "rho", 1))) * std_dev), 
                                "assigning variable T_i");
                    current_statement_begin__ = 84;
                    stan::math::assign(rho_mark, (rho_mark + 1));
                    }
                }
                current_statement_begin__ = 88;
                for (int c = 1; c <= nc; ++c) {
                    current_statement_begin__ = 88;
                    for (int r = c; r <= nc; ++r) {

                        current_statement_begin__ = 89;
                        stan::model::assign(theta_L, 
                                    stan::model::cons_list(stan::model::index_uni(theta_L_mark), stan::model::nil_index_list()), 
                                    get_base1(T_i, r, c, "T_i", 1), 
                                    "assigning variable theta_L");
                        current_statement_begin__ = 90;
                        stan::math::assign(theta_L_mark, (theta_L_mark + 1));
                    }
                }
                }
            }
            }
        }
        current_statement_begin__ = 94;
        return stan::math::promote_scalar<fun_return_scalar_t__>(theta_L);
        }
    } 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 ***");
    }
}


struct make_theta_L_functor__ {
    template <typename T2__, typename T3__, typename T4__, typename T5__, typename T6__, typename T7__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T2__, T3__, T4__, T5__, typename boost::math::tools::promote_args<T6__, T7__>::type>::type, Eigen::Dynamic, 1>
    operator()(const int& len_theta_L,
                 const std::vector<int>& p,
                 const T2__& dispersion,
                 const Eigen::Matrix<T3__, Eigen::Dynamic, 1>& tau,
                 const Eigen::Matrix<T4__, Eigen::Dynamic, 1>& scale,
                 const Eigen::Matrix<T5__, Eigen::Dynamic, 1>& zeta,
                 const Eigen::Matrix<T6__, Eigen::Dynamic, 1>& rho,
                 const Eigen::Matrix<T7__, Eigen::Dynamic, 1>& z_T, std::ostream* pstream__) const {
        return make_theta_L(len_theta_L, p, dispersion, tau, scale, zeta, rho, z_T, pstream__);
    }
};

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
make_b(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& z_b,
           const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& theta_L,
           const std::vector<int>& p,
           const std::vector<int>& l, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, T1__>::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__ = 109;
        validate_non_negative_index("b", "rows(z_b)", rows(z_b));
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> b(rows(z_b));
        stan::math::initialize(b, DUMMY_VAR__);
        stan::math::fill(b, DUMMY_VAR__);

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

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


        current_statement_begin__ = 112;
        for (int i = 1; i <= size(p); ++i) {
            {
            current_statement_begin__ = 113;
            int nc(0);
            (void) nc;  // dummy to suppress unused var warning
            stan::math::fill(nc, std::numeric_limits<int>::min());
            stan::math::assign(nc,get_base1(p, i, "p", 1));


            current_statement_begin__ = 114;
            if (as_bool(logical_eq(nc, 1))) {
                {
                current_statement_begin__ = 115;
                local_scalar_t__ theta_L_start(DUMMY_VAR__);
                (void) theta_L_start;  // dummy to suppress unused var warning
                stan::math::initialize(theta_L_start, DUMMY_VAR__);
                stan::math::fill(theta_L_start, DUMMY_VAR__);
                stan::math::assign(theta_L_start,get_base1(theta_L, theta_L_mark, "theta_L", 1));


                current_statement_begin__ = 116;
                for (int s = b_mark; s <= ((b_mark + get_base1(l, i, "l", 1)) - 1); ++s) {
                    current_statement_begin__ = 117;
                    stan::model::assign(b, 
                                stan::model::cons_list(stan::model::index_uni(s), stan::model::nil_index_list()), 
                                (theta_L_start * get_base1(z_b, s, "z_b", 1)), 
                                "assigning variable b");
                }
                current_statement_begin__ = 118;
                stan::math::assign(b_mark, (b_mark + get_base1(l, i, "l", 1)));
                current_statement_begin__ = 119;
                stan::math::assign(theta_L_mark, (theta_L_mark + 1));
                }
            } else {
                {
                current_statement_begin__ = 122;
                validate_non_negative_index("T_i", "nc", nc);
                validate_non_negative_index("T_i", "nc", nc);
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, Eigen::Dynamic> T_i(nc, nc);
                stan::math::initialize(T_i, DUMMY_VAR__);
                stan::math::fill(T_i, DUMMY_VAR__);
                stan::math::assign(T_i,rep_matrix(0, nc, nc));


                current_statement_begin__ = 123;
                for (int c = 1; c <= nc; ++c) {

                    current_statement_begin__ = 124;
                    stan::model::assign(T_i, 
                                stan::model::cons_list(stan::model::index_uni(c), stan::model::cons_list(stan::model::index_uni(c), stan::model::nil_index_list())), 
                                get_base1(theta_L, theta_L_mark, "theta_L", 1), 
                                "assigning variable T_i");
                    current_statement_begin__ = 125;
                    stan::math::assign(theta_L_mark, (theta_L_mark + 1));
                    current_statement_begin__ = 126;
                    for (int r = (c + 1); r <= nc; ++r) {

                        current_statement_begin__ = 127;
                        stan::model::assign(T_i, 
                                    stan::model::cons_list(stan::model::index_uni(r), stan::model::cons_list(stan::model::index_uni(c), stan::model::nil_index_list())), 
                                    get_base1(theta_L, theta_L_mark, "theta_L", 1), 
                                    "assigning variable T_i");
                        current_statement_begin__ = 128;
                        stan::math::assign(theta_L_mark, (theta_L_mark + 1));
                    }
                }
                current_statement_begin__ = 131;
                for (int j = 1; j <= get_base1(l, i, "l", 1); ++j) {
                    {
                    current_statement_begin__ = 132;
                    validate_non_negative_index("temp", "nc", nc);
                    Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> temp(nc);
                    stan::math::initialize(temp, DUMMY_VAR__);
                    stan::math::fill(temp, DUMMY_VAR__);
                    stan::math::assign(temp,multiply(T_i, segment(z_b, b_mark, nc)));


                    current_statement_begin__ = 133;
                    stan::math::assign(b_mark, (b_mark - 1));
                    current_statement_begin__ = 134;
                    for (int s = 1; s <= nc; ++s) {
                        current_statement_begin__ = 134;
                        stan::model::assign(b, 
                                    stan::model::cons_list(stan::model::index_uni((b_mark + s)), stan::model::nil_index_list()), 
                                    get_base1(temp, s, "temp", 1), 
                                    "assigning variable b");
                    }
                    current_statement_begin__ = 135;
                    stan::math::assign(b_mark, (b_mark + (nc + 1)));
                    }
                }
                }
            }
            }
        }
        current_statement_begin__ = 139;
        return stan::math::promote_scalar<fun_return_scalar_t__>(b);
        }
    } 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 ***");
    }
}


struct make_b_functor__ {
    template <typename T0__, typename T1__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& z_b,
           const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& theta_L,
           const std::vector<int>& p,
           const std::vector<int>& l, std::ostream* pstream__) const {
        return make_b(z_b, theta_L, p, l, pstream__);
    }
};

template <typename T0__, typename T1__, typename T2__, typename T3__, typename T4__, typename T5__, typename T6__, typename T7__, typename T_lp__, typename T_lp_accum__>
typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__, T5__, T6__, T7__, T_lp__>::type>::type
decov_lp(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& z_b,
             const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& z_T,
             const Eigen::Matrix<T2__, Eigen::Dynamic, 1>& rho,
             const Eigen::Matrix<T3__, Eigen::Dynamic, 1>& zeta,
             const Eigen::Matrix<T4__, Eigen::Dynamic, 1>& tau,
             const std::vector<T5__>& regularization,
             const std::vector<T6__>& delta,
             const Eigen::Matrix<T7__, Eigen::Dynamic, 1>& shape,
             const int& t,
             const std::vector<int>& p, T_lp__& lp__, T_lp_accum__& lp_accum__, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__, T5__, T6__, T7__, T_lp__>::type>::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__ = 160;
        int pos_reg(0);
        (void) pos_reg;  // dummy to suppress unused var warning
        stan::math::fill(pos_reg, std::numeric_limits<int>::min());
        stan::math::assign(pos_reg,1);

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


        current_statement_begin__ = 162;
        lp_accum__.add(normal_log(z_b, 0, 1));
        current_statement_begin__ = 163;
        lp_accum__.add(normal_log(z_T, 0, 1));
        current_statement_begin__ = 164;
        for (int i = 1; i <= t; ++i) {
            current_statement_begin__ = 164;
            if (as_bool(logical_gt(get_base1(p, i, "p", 1), 1))) {
                {
                current_statement_begin__ = 165;
                validate_non_negative_index("shape1", "(get_base1(p, i, \"p\", 1) - 1)", (get_base1(p, i, "p", 1) - 1));
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> shape1((get_base1(p, i, "p", 1) - 1));
                stan::math::initialize(shape1, DUMMY_VAR__);
                stan::math::fill(shape1, DUMMY_VAR__);

                current_statement_begin__ = 166;
                validate_non_negative_index("shape2", "(get_base1(p, i, \"p\", 1) - 1)", (get_base1(p, i, "p", 1) - 1));
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> shape2((get_base1(p, i, "p", 1) - 1));
                stan::math::initialize(shape2, DUMMY_VAR__);
                stan::math::fill(shape2, DUMMY_VAR__);

                current_statement_begin__ = 167;
                local_scalar_t__ nu(DUMMY_VAR__);
                (void) nu;  // dummy to suppress unused var warning
                stan::math::initialize(nu, DUMMY_VAR__);
                stan::math::fill(nu, DUMMY_VAR__);
                stan::math::assign(nu,(get_base1(regularization, pos_reg, "regularization", 1) + (0.5 * (get_base1(p, i, "p", 1) - 2))));


                current_statement_begin__ = 168;
                stan::math::assign(pos_reg, (pos_reg + 1));
                current_statement_begin__ = 169;
                stan::model::assign(shape1, 
                            stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list()), 
                            nu, 
                            "assigning variable shape1");
                current_statement_begin__ = 170;
                stan::model::assign(shape2, 
                            stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list()), 
                            nu, 
                            "assigning variable shape2");
                current_statement_begin__ = 171;
                for (int j = 2; j <= (get_base1(p, i, "p", 1) - 1); ++j) {

                    current_statement_begin__ = 172;
                    stan::math::assign(nu, (nu - 0.5));
                    current_statement_begin__ = 173;
                    stan::model::assign(shape1, 
                                stan::model::cons_list(stan::model::index_uni(j), stan::model::nil_index_list()), 
                                (0.5 * j), 
                                "assigning variable shape1");
                    current_statement_begin__ = 174;
                    stan::model::assign(shape2, 
                                stan::model::cons_list(stan::model::index_uni(j), stan::model::nil_index_list()), 
                                nu, 
                                "assigning variable shape2");
                }
                current_statement_begin__ = 176;
                lp_accum__.add(beta_log(stan::model::rvalue(rho, stan::model::cons_list(stan::model::index_min_max(pos_rho, ((pos_rho + get_base1(p, i, "p", 1)) - 2)), stan::model::nil_index_list()), "rho"), shape1, shape2));
                current_statement_begin__ = 177;
                stan::math::assign(pos_rho, (pos_rho + (get_base1(p, i, "p", 1) - 1)));
                }
            }
        }
        current_statement_begin__ = 179;
        lp_accum__.add(gamma_log(zeta, delta, 1));
        current_statement_begin__ = 180;
        lp_accum__.add(gamma_log(tau, shape, 1));
        current_statement_begin__ = 181;
        return stan::math::promote_scalar<fun_return_scalar_t__>(get_lp(lp__, lp_accum__));
        }
    } 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 ***");
    }
}


struct decov_lp_functor__ {
    template <typename T0__, typename T1__, typename T2__, typename T3__, typename T4__, typename T5__, typename T6__, typename T7__, typename T_lp__, typename T_lp_accum__>
        typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__, T5__, T6__, T7__, T_lp__>::type>::type
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& z_b,
             const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& z_T,
             const Eigen::Matrix<T2__, Eigen::Dynamic, 1>& rho,
             const Eigen::Matrix<T3__, Eigen::Dynamic, 1>& zeta,
             const Eigen::Matrix<T4__, Eigen::Dynamic, 1>& tau,
             const std::vector<T5__>& regularization,
             const std::vector<T6__>& delta,
             const Eigen::Matrix<T7__, Eigen::Dynamic, 1>& shape,
             const int& t,
             const std::vector<int>& p, T_lp__& lp__, T_lp_accum__& lp_accum__, std::ostream* pstream__) const {
        return decov_lp(z_b, z_T, rho, zeta, tau, regularization, delta, shape, t, p, lp__, lp_accum__, pstream__);
    }
};

template <typename T0__, typename T1__, typename T2__, typename T3__, typename T4__, typename T5__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__, T5__>::type>::type, Eigen::Dynamic, 1>
hs_prior(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& z_beta,
             const std::vector<T1__>& global,
             const std::vector<Eigen::Matrix<T2__, Eigen::Dynamic, 1> >& local,
             const T3__& global_prior_scale,
             const T4__& error_scale,
             const T5__& c2, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__, T5__>::type>::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__ = 197;
        int K(0);
        (void) K;  // dummy to suppress unused var warning
        stan::math::fill(K, std::numeric_limits<int>::min());
        stan::math::assign(K,rows(z_beta));

        current_statement_begin__ = 198;
        validate_non_negative_index("lambda", "K", K);
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> lambda(K);
        stan::math::initialize(lambda, DUMMY_VAR__);
        stan::math::fill(lambda, DUMMY_VAR__);
        stan::math::assign(lambda,elt_multiply(get_base1(local, 1, "local", 1), stan::math::sqrt(get_base1(local, 2, "local", 1))));

        current_statement_begin__ = 199;
        local_scalar_t__ tau(DUMMY_VAR__);
        (void) tau;  // dummy to suppress unused var warning
        stan::math::initialize(tau, DUMMY_VAR__);
        stan::math::fill(tau, DUMMY_VAR__);
        stan::math::assign(tau,(((get_base1(global, 1, "global", 1) * stan::math::sqrt(get_base1(global, 2, "global", 1))) * global_prior_scale) * error_scale));

        current_statement_begin__ = 200;
        validate_non_negative_index("lambda2", "K", K);
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> lambda2(K);
        stan::math::initialize(lambda2, DUMMY_VAR__);
        stan::math::fill(lambda2, DUMMY_VAR__);
        stan::math::assign(lambda2,square(lambda));

        current_statement_begin__ = 201;
        validate_non_negative_index("lambda_tilde", "K", K);
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> lambda_tilde(K);
        stan::math::initialize(lambda_tilde, DUMMY_VAR__);
        stan::math::fill(lambda_tilde, DUMMY_VAR__);
        stan::math::assign(lambda_tilde,stan::math::sqrt(elt_divide(multiply(c2, lambda2), add(c2, multiply(square(tau), lambda2)))));


        current_statement_begin__ = 202;
        return stan::math::promote_scalar<fun_return_scalar_t__>(multiply(elt_multiply(z_beta, lambda_tilde), tau));
        }
    } 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 ***");
    }
}


struct hs_prior_functor__ {
    template <typename T0__, typename T1__, typename T2__, typename T3__, typename T4__, typename T5__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__, T5__>::type>::type, Eigen::Dynamic, 1>
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& z_beta,
             const std::vector<T1__>& global,
             const std::vector<Eigen::Matrix<T2__, Eigen::Dynamic, 1> >& local,
             const T3__& global_prior_scale,
             const T4__& error_scale,
             const T5__& c2, std::ostream* pstream__) const {
        return hs_prior(z_beta, global, local, global_prior_scale, error_scale, c2, pstream__);
    }
};

template <typename T0__, typename T1__, typename T2__, typename T3__, typename T4__, typename T5__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__, T5__>::type>::type, Eigen::Dynamic, 1>
hsplus_prior(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& z_beta,
                 const std::vector<T1__>& global,
                 const std::vector<Eigen::Matrix<T2__, Eigen::Dynamic, 1> >& local,
                 const T3__& global_prior_scale,
                 const T4__& error_scale,
                 const T5__& c2, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__, T5__>::type>::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__ = 218;
        int K(0);
        (void) K;  // dummy to suppress unused var warning
        stan::math::fill(K, std::numeric_limits<int>::min());
        stan::math::assign(K,rows(z_beta));

        current_statement_begin__ = 219;
        validate_non_negative_index("lambda", "K", K);
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> lambda(K);
        stan::math::initialize(lambda, DUMMY_VAR__);
        stan::math::fill(lambda, DUMMY_VAR__);
        stan::math::assign(lambda,elt_multiply(get_base1(local, 1, "local", 1), stan::math::sqrt(get_base1(local, 2, "local", 1))));

        current_statement_begin__ = 220;
        validate_non_negative_index("eta", "K", K);
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> eta(K);
        stan::math::initialize(eta, DUMMY_VAR__);
        stan::math::fill(eta, DUMMY_VAR__);
        stan::math::assign(eta,elt_multiply(get_base1(local, 3, "local", 1), stan::math::sqrt(get_base1(local, 4, "local", 1))));

        current_statement_begin__ = 221;
        local_scalar_t__ tau(DUMMY_VAR__);
        (void) tau;  // dummy to suppress unused var warning
        stan::math::initialize(tau, DUMMY_VAR__);
        stan::math::fill(tau, DUMMY_VAR__);
        stan::math::assign(tau,(((get_base1(global, 1, "global", 1) * stan::math::sqrt(get_base1(global, 2, "global", 1))) * global_prior_scale) * error_scale));

        current_statement_begin__ = 222;
        validate_non_negative_index("lambda_eta2", "K", K);
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> lambda_eta2(K);
        stan::math::initialize(lambda_eta2, DUMMY_VAR__);
        stan::math::fill(lambda_eta2, DUMMY_VAR__);
        stan::math::assign(lambda_eta2,square(elt_multiply(lambda, eta)));

        current_statement_begin__ = 223;
        validate_non_negative_index("lambda_tilde", "K", K);
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> lambda_tilde(K);
        stan::math::initialize(lambda_tilde, DUMMY_VAR__);
        stan::math::fill(lambda_tilde, DUMMY_VAR__);
        stan::math::assign(lambda_tilde,stan::math::sqrt(elt_divide(multiply(c2, lambda_eta2), add(c2, multiply(square(tau), lambda_eta2)))));


        current_statement_begin__ = 225;
        return stan::math::promote_scalar<fun_return_scalar_t__>(multiply(elt_multiply(z_beta, lambda_tilde), tau));
        }
    } 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 ***");
    }
}


struct hsplus_prior_functor__ {
    template <typename T0__, typename T1__, typename T2__, typename T3__, typename T4__, typename T5__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__, T5__>::type>::type, Eigen::Dynamic, 1>
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& z_beta,
                 const std::vector<T1__>& global,
                 const std::vector<Eigen::Matrix<T2__, Eigen::Dynamic, 1> >& local,
                 const T3__& global_prior_scale,
                 const T4__& error_scale,
                 const T5__& c2, std::ostream* pstream__) const {
        return hsplus_prior(z_beta, global, local, global_prior_scale, error_scale, c2, pstream__);
    }
};

template <typename T0__, typename T1__>
typename boost::math::tools::promote_args<T0__, T1__>::type
CFt(const T0__& z,
        const T1__& df, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, T1__>::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__ = 239;
        local_scalar_t__ z2(DUMMY_VAR__);
        (void) z2;  // dummy to suppress unused var warning
        stan::math::initialize(z2, DUMMY_VAR__);
        stan::math::fill(z2, DUMMY_VAR__);
        stan::math::assign(z2,square(z));

        current_statement_begin__ = 240;
        local_scalar_t__ z3(DUMMY_VAR__);
        (void) z3;  // dummy to suppress unused var warning
        stan::math::initialize(z3, DUMMY_VAR__);
        stan::math::fill(z3, DUMMY_VAR__);
        stan::math::assign(z3,(z2 * z));

        current_statement_begin__ = 241;
        local_scalar_t__ z5(DUMMY_VAR__);
        (void) z5;  // dummy to suppress unused var warning
        stan::math::initialize(z5, DUMMY_VAR__);
        stan::math::fill(z5, DUMMY_VAR__);
        stan::math::assign(z5,(z2 * z3));

        current_statement_begin__ = 242;
        local_scalar_t__ z7(DUMMY_VAR__);
        (void) z7;  // dummy to suppress unused var warning
        stan::math::initialize(z7, DUMMY_VAR__);
        stan::math::fill(z7, DUMMY_VAR__);
        stan::math::assign(z7,(z2 * z5));

        current_statement_begin__ = 243;
        local_scalar_t__ z9(DUMMY_VAR__);
        (void) z9;  // dummy to suppress unused var warning
        stan::math::initialize(z9, DUMMY_VAR__);
        stan::math::fill(z9, DUMMY_VAR__);
        stan::math::assign(z9,(z2 * z7));

        current_statement_begin__ = 244;
        local_scalar_t__ df2(DUMMY_VAR__);
        (void) df2;  // dummy to suppress unused var warning
        stan::math::initialize(df2, DUMMY_VAR__);
        stan::math::fill(df2, DUMMY_VAR__);
        stan::math::assign(df2,square(df));

        current_statement_begin__ = 245;
        local_scalar_t__ df3(DUMMY_VAR__);
        (void) df3;  // dummy to suppress unused var warning
        stan::math::initialize(df3, DUMMY_VAR__);
        stan::math::fill(df3, DUMMY_VAR__);
        stan::math::assign(df3,(df2 * df));

        current_statement_begin__ = 246;
        local_scalar_t__ df4(DUMMY_VAR__);
        (void) df4;  // dummy to suppress unused var warning
        stan::math::initialize(df4, DUMMY_VAR__);
        stan::math::fill(df4, DUMMY_VAR__);
        stan::math::assign(df4,(df2 * df2));


        current_statement_begin__ = 247;
        return stan::math::promote_scalar<fun_return_scalar_t__>(((((z + ((z3 + z) / (4 * df))) + ((((5 * z5) + (16 * z3)) + (3 * z)) / (96 * df2))) + (((((3 * z7) + (19 * z5)) + (17 * z3)) - (15 * z)) / (384 * df3))) + ((((((79 * z9) + (776 * z7)) + (1482 * z5)) - (1920 * z3)) - (945 * z)) / (92160 * df4))));
        }
    } 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 ***");
    }
}


struct CFt_functor__ {
    template <typename T0__, typename T1__>
        typename boost::math::tools::promote_args<T0__, T1__>::type
    operator()(const T0__& z,
        const T1__& df, std::ostream* pstream__) const {
        return CFt(z, df, pstream__);
    }
};

std::vector<std::vector<int> >
make_V(const int& N,
           const int& t,
           const std::vector<int>& v, std::ostream* pstream__) {
    typedef double local_scalar_t__;
    typedef int 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__ = 261;
        validate_non_negative_index("V", "t", t);
        validate_non_negative_index("V", "N", N);
        std::vector<std::vector<int  >  > V(t, std::vector<int>(N, int(0)));
        stan::math::fill(V, std::numeric_limits<int>::min());

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


        current_statement_begin__ = 263;
        if (as_bool(logical_gt(t, 0))) {
            current_statement_begin__ = 263;
            for (int j = 1; j <= N; ++j) {
                current_statement_begin__ = 263;
                for (int i = 1; i <= t; ++i) {

                    current_statement_begin__ = 264;
                    stan::model::assign(V, 
                                stan::model::cons_list(stan::model::index_uni(i), stan::model::cons_list(stan::model::index_uni(j), stan::model::nil_index_list())), 
                                (get_base1(v, pos, "v", 1) + 1), 
                                "assigning variable V");
                    current_statement_begin__ = 265;
                    stan::math::assign(pos, (pos + 1));
                }
            }
        }
        current_statement_begin__ = 267;
        return stan::math::promote_scalar<fun_return_scalar_t__>(V);
        }
    } 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 ***");
    }
}


struct make_V_functor__ {
            std::vector<std::vector<int> >
    operator()(const int& N,
           const int& t,
           const std::vector<int>& v, std::ostream* pstream__) const {
        return make_V(N, t, v, pstream__);
    }
};

template <typename T2__, typename T5__>
Eigen::Matrix<typename boost::math::tools::promote_args<T2__, T5__>::type, Eigen::Dynamic, 1>
csr_matrix_times_vector2(const int& m,
                             const int& n,
                             const Eigen::Matrix<T2__, Eigen::Dynamic, 1>& w,
                             const std::vector<int>& v,
                             const std::vector<int>& u,
                             const Eigen::Matrix<T5__, Eigen::Dynamic, 1>& b, std::ostream* pstream__);

double
make_lower(const int& family,
               const int& link, std::ostream* pstream__) {
    typedef double 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__ = 301;
        if (as_bool(logical_eq(family, 1))) {
            current_statement_begin__ = 301;
            return stan::math::promote_scalar<fun_return_scalar_t__>(stan::math::negative_infinity());
        }
        current_statement_begin__ = 302;
        if (as_bool(logical_lte(family, 3))) {

            current_statement_begin__ = 303;
            if (as_bool(logical_eq(link, 2))) {
                current_statement_begin__ = 303;
                return stan::math::promote_scalar<fun_return_scalar_t__>(stan::math::negative_infinity());
            }
            current_statement_begin__ = 304;
            return stan::math::promote_scalar<fun_return_scalar_t__>(0);
        }
        current_statement_begin__ = 306;
        return stan::math::promote_scalar<fun_return_scalar_t__>(stan::math::negative_infinity());
    } 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 ***");
    }
}


struct make_lower_functor__ {
            double
    operator()(const int& family,
               const int& link, std::ostream* pstream__) const {
        return make_lower(family, link, pstream__);
    }
};

double
make_upper(const int& family,
               const int& link, std::ostream* pstream__) {
    typedef double 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__ = 317;
        if (as_bool((primitive_value(logical_eq(family, 4)) && primitive_value(logical_eq(link, 5))))) {
            current_statement_begin__ = 317;
            return stan::math::promote_scalar<fun_return_scalar_t__>(0);
        }
        current_statement_begin__ = 318;
        return stan::math::promote_scalar<fun_return_scalar_t__>(stan::math::positive_infinity());
    } 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 ***");
    }
}


struct make_upper_functor__ {
            double
    operator()(const int& family,
               const int& link, std::ostream* pstream__) const {
        return make_upper(family, link, pstream__);
    }
};

template <typename T0__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__>::type, Eigen::Dynamic, 1>
linkinv_count(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& eta,
                  const int& link, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__>::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__ = 329;
        if (as_bool(logical_eq(link, 1))) {
            current_statement_begin__ = 329;
            return stan::math::promote_scalar<fun_return_scalar_t__>(stan::math::exp(eta));
        } else if (as_bool(logical_eq(link, 2))) {
            current_statement_begin__ = 330;
            return stan::math::promote_scalar<fun_return_scalar_t__>(eta);
        } else if (as_bool(logical_eq(link, 3))) {
            current_statement_begin__ = 331;
            return stan::math::promote_scalar<fun_return_scalar_t__>(square(eta));
        } else {
            current_statement_begin__ = 332;
            std::stringstream errmsg_stream__;
            errmsg_stream__ << "Invalid link";
            throw std::domain_error(errmsg_stream__.str());
        }
        current_statement_begin__ = 333;
        return stan::math::promote_scalar<fun_return_scalar_t__>(eta);
    } 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 ***");
    }
}


struct linkinv_count_functor__ {
    template <typename T0__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T0__>::type, Eigen::Dynamic, 1>
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& eta,
                  const int& link, std::ostream* pstream__) const {
        return linkinv_count(eta, link, pstream__);
    }
};

template <typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T1__>::type, Eigen::Dynamic, 1>
pw_pois(const std::vector<int>& y,
            const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
            const int& link, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T1__>::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__ = 345;
        int N(0);
        (void) N;  // dummy to suppress unused var warning
        stan::math::fill(N, std::numeric_limits<int>::min());
        stan::math::assign(N,rows(eta));

        current_statement_begin__ = 346;
        validate_non_negative_index("ll", "N", N);
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> ll(N);
        stan::math::initialize(ll, DUMMY_VAR__);
        stan::math::fill(ll, DUMMY_VAR__);


        current_statement_begin__ = 347;
        if (as_bool(logical_eq(link, 1))) {
            current_statement_begin__ = 348;
            for (int n = 1; n <= N; ++n) {
                current_statement_begin__ = 348;
                stan::model::assign(ll, 
                            stan::model::cons_list(stan::model::index_uni(n), stan::model::nil_index_list()), 
                            poisson_log_log(get_base1(y, n, "y", 1), get_base1(eta, n, "eta", 1)), 
                            "assigning variable ll");
            }
        } else if (as_bool(logical_lte(link, 3))) {
            {
            current_statement_begin__ = 350;
            validate_non_negative_index("phi", "N", N);
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> phi(N);
            stan::math::initialize(phi, DUMMY_VAR__);
            stan::math::fill(phi, DUMMY_VAR__);
            stan::math::assign(phi,linkinv_count(eta, link, pstream__));


            current_statement_begin__ = 351;
            for (int n = 1; n <= N; ++n) {
                current_statement_begin__ = 351;
                stan::model::assign(ll, 
                            stan::model::cons_list(stan::model::index_uni(n), stan::model::nil_index_list()), 
                            poisson_log(get_base1(y, n, "y", 1), get_base1(phi, n, "phi", 1)), 
                            "assigning variable ll");
            }
            }
        } else {
            current_statement_begin__ = 353;
            std::stringstream errmsg_stream__;
            errmsg_stream__ << "Invalid link";
            throw std::domain_error(errmsg_stream__.str());
        }
        current_statement_begin__ = 354;
        return stan::math::promote_scalar<fun_return_scalar_t__>(ll);
        }
    } 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 ***");
    }
}


struct pw_pois_functor__ {
    template <typename T1__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T1__>::type, Eigen::Dynamic, 1>
    operator()(const std::vector<int>& y,
            const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
            const int& link, std::ostream* pstream__) const {
        return pw_pois(y, eta, link, pstream__);
    }
};

template <typename T1__, typename T2__>
Eigen::Matrix<typename boost::math::tools::promote_args<T1__, T2__>::type, Eigen::Dynamic, 1>
pw_nb(const std::vector<int>& y,
          const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
          const T2__& theta,
          const int& link, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T1__, T2__>::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__ = 367;
        int N(0);
        (void) N;  // dummy to suppress unused var warning
        stan::math::fill(N, std::numeric_limits<int>::min());
        stan::math::assign(N,rows(eta));

        current_statement_begin__ = 368;
        validate_non_negative_index("rho", "N", N);
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> rho(N);
        stan::math::initialize(rho, DUMMY_VAR__);
        stan::math::fill(rho, DUMMY_VAR__);
        stan::math::assign(rho,linkinv_count(eta, link, pstream__));

        current_statement_begin__ = 369;
        validate_non_negative_index("ll", "N", N);
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> ll(N);
        stan::math::initialize(ll, DUMMY_VAR__);
        stan::math::fill(ll, DUMMY_VAR__);


        current_statement_begin__ = 370;
        for (int n = 1; n <= N; ++n) {
            current_statement_begin__ = 370;
            stan::model::assign(ll, 
                        stan::model::cons_list(stan::model::index_uni(n), stan::model::nil_index_list()), 
                        neg_binomial_2_log(get_base1(y, n, "y", 1), get_base1(rho, n, "rho", 1), theta), 
                        "assigning variable ll");
        }
        current_statement_begin__ = 371;
        return stan::math::promote_scalar<fun_return_scalar_t__>(ll);
        }
    } 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 ***");
    }
}


struct pw_nb_functor__ {
    template <typename T1__, typename T2__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T1__, T2__>::type, Eigen::Dynamic, 1>
    operator()(const std::vector<int>& y,
          const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
          const T2__& theta,
          const int& link, std::ostream* pstream__) const {
        return pw_nb(y, eta, theta, link, pstream__);
    }
};

class model_count : public prob_grad {
private:
        int N;
        int K;
        vector_d xbar;
        int dense_X;
        std::vector<matrix_d> X;
        int nnz_X;
        vector_d w_X;
        std::vector<int> v_X;
        std::vector<int> u_X;
        int K_smooth;
        matrix_d S;
        std::vector<int> smooth_map;
        std::vector<int> y;
        int prior_PD;
        int compute_mean_PPD;
        int has_intercept;
        int link;
        int prior_dist;
        int prior_dist_for_intercept;
        int prior_dist_for_aux;
        int prior_dist_for_smooth;
        int has_weights;
        vector_d weights;
        int has_offset;
        vector_d offset;
        int family;
        vector_d prior_scale;
        double prior_scale_for_intercept;
        double prior_scale_for_aux;
        vector_d prior_scale_for_smooth;
        vector_d prior_mean;
        double prior_mean_for_intercept;
        double prior_mean_for_aux;
        vector_d prior_mean_for_smooth;
        vector_d prior_df;
        double prior_df_for_intercept;
        double prior_df_for_aux;
        vector_d prior_df_for_smooth;
        double global_prior_df;
        double global_prior_scale;
        double slab_df;
        double slab_scale;
        std::vector<int> num_normals;
        int t;
        std::vector<int> p;
        std::vector<int> l;
        int q;
        int len_theta_L;
        vector_d shape;
        vector_d scale;
        int len_concentration;
        std::vector<double> concentration;
        int len_regularization;
        std::vector<double> regularization;
        int num_non_zero;
        vector_d w;
        std::vector<int> v;
        std::vector<int> u;
        int special_case;
        double poisson_max;
        std::vector<std::vector<int> > V;
        int can_do_countlogglm;
        matrix_d XS;
        int len_z_T;
        int len_var_group;
        int len_rho;
        int is_continuous;
        int pos;
        std::vector<double> delta;
        int hs;
public:
    model_count(stan::io::var_context& context__,
        std::ostream* pstream__ = 0)
        : prob_grad(0) {
        ctor_body(context__, 0, pstream__);
    }

    model_count(stan::io::var_context& context__,
        unsigned int random_seed__,
        std::ostream* pstream__ = 0)
        : prob_grad(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__ = "model_count_namespace::model_count";
        (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__ = 377;
            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, 0);

            current_statement_begin__ = 378;
            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, 0);

            current_statement_begin__ = 381;
            validate_non_negative_index("xbar", "K", K);
            context__.validate_dims("data initialization", "xbar", "vector_d", context__.to_vec(K));
            xbar = Eigen::Matrix<double, Eigen::Dynamic, 1>(K);
            vals_r__ = context__.vals_r("xbar");
            pos__ = 0;
            size_t xbar_j_1_max__ = K;
            for (size_t j_1__ = 0; j_1__ < xbar_j_1_max__; ++j_1__) {
                xbar(j_1__) = vals_r__[pos__++];
            }

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

            current_statement_begin__ = 383;
            validate_non_negative_index("X", "N", N);
            validate_non_negative_index("X", "K", K);
            validate_non_negative_index("X", "dense_X", dense_X);
            context__.validate_dims("data initialization", "X", "matrix_d", context__.to_vec(dense_X,N,K));
            X = std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> >(dense_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;
            size_t X_k_0_max__ = dense_X;
            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__) {
                    for (size_t k_0__ = 0; k_0__ < X_k_0_max__; ++k_0__) {
                        X[k_0__](j_1__, j_2__) = vals_r__[pos__++];
                    }
                }
            }

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

            current_statement_begin__ = 387;
            validate_non_negative_index("w_X", "nnz_X", nnz_X);
            context__.validate_dims("data initialization", "w_X", "vector_d", context__.to_vec(nnz_X));
            w_X = Eigen::Matrix<double, Eigen::Dynamic, 1>(nnz_X);
            vals_r__ = context__.vals_r("w_X");
            pos__ = 0;
            size_t w_X_j_1_max__ = nnz_X;
            for (size_t j_1__ = 0; j_1__ < w_X_j_1_max__; ++j_1__) {
                w_X(j_1__) = vals_r__[pos__++];
            }

            current_statement_begin__ = 388;
            validate_non_negative_index("v_X", "nnz_X", nnz_X);
            context__.validate_dims("data initialization", "v_X", "int", context__.to_vec(nnz_X));
            v_X = std::vector<int>(nnz_X, int(0));
            vals_i__ = context__.vals_i("v_X");
            pos__ = 0;
            size_t v_X_k_0_max__ = nnz_X;
            for (size_t k_0__ = 0; k_0__ < v_X_k_0_max__; ++k_0__) {
                v_X[k_0__] = vals_i__[pos__++];
            }
            size_t v_X_i_0_max__ = nnz_X;
            for (size_t i_0__ = 0; i_0__ < v_X_i_0_max__; ++i_0__) {
                check_greater_or_equal(function__, "v_X[i_0__]", v_X[i_0__], 0);
                check_less_or_equal(function__, "v_X[i_0__]", v_X[i_0__], (K - 1));
            }

            current_statement_begin__ = 390;
            validate_non_negative_index("u_X", "(dense_X ? 0 : (N + 1) )", (dense_X ? 0 : (N + 1) ));
            context__.validate_dims("data initialization", "u_X", "int", context__.to_vec((dense_X ? 0 : (N + 1) )));
            u_X = std::vector<int>((dense_X ? 0 : (N + 1) ), int(0));
            vals_i__ = context__.vals_i("u_X");
            pos__ = 0;
            size_t u_X_k_0_max__ = (dense_X ? 0 : (N + 1) );
            for (size_t k_0__ = 0; k_0__ < u_X_k_0_max__; ++k_0__) {
                u_X[k_0__] = vals_i__[pos__++];
            }
            size_t u_X_i_0_max__ = (dense_X ? 0 : (N + 1) );
            for (size_t i_0__ = 0; i_0__ < u_X_i_0_max__; ++i_0__) {
                check_greater_or_equal(function__, "u_X[i_0__]", u_X[i_0__], 0);
                check_less_or_equal(function__, "u_X[i_0__]", u_X[i_0__], (rows(w_X) + 1));
            }

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

            current_statement_begin__ = 394;
            validate_non_negative_index("S", "N", N);
            validate_non_negative_index("S", "K_smooth", K_smooth);
            context__.validate_dims("data initialization", "S", "matrix_d", context__.to_vec(N,K_smooth));
            S = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>(N, K_smooth);
            vals_r__ = context__.vals_r("S");
            pos__ = 0;
            size_t S_j_2_max__ = K_smooth;
            size_t S_j_1_max__ = N;
            for (size_t j_2__ = 0; j_2__ < S_j_2_max__; ++j_2__) {
                for (size_t j_1__ = 0; j_1__ < S_j_1_max__; ++j_1__) {
                    S(j_1__, j_2__) = vals_r__[pos__++];
                }
            }

            current_statement_begin__ = 395;
            validate_non_negative_index("smooth_map", "K_smooth", K_smooth);
            context__.validate_dims("data initialization", "smooth_map", "int", context__.to_vec(K_smooth));
            smooth_map = std::vector<int>(K_smooth, int(0));
            vals_i__ = context__.vals_i("smooth_map");
            pos__ = 0;
            size_t smooth_map_k_0_max__ = K_smooth;
            for (size_t k_0__ = 0; k_0__ < smooth_map_k_0_max__; ++k_0__) {
                smooth_map[k_0__] = vals_i__[pos__++];
            }
            size_t smooth_map_i_0_max__ = K_smooth;
            for (size_t i_0__ = 0; i_0__ < smooth_map_i_0_max__; ++i_0__) {
                check_greater_or_equal(function__, "smooth_map[i_0__]", smooth_map[i_0__], 1);
            }

            current_statement_begin__ = 396;
            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__++];
            }
            size_t y_i_0_max__ = N;
            for (size_t i_0__ = 0; i_0__ < y_i_0_max__; ++i_0__) {
                check_greater_or_equal(function__, "y[i_0__]", y[i_0__], 0);
            }

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

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

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

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

            current_statement_begin__ = 410;
            context__.validate_dims("data initialization", "prior_dist", "int", context__.to_vec());
            prior_dist = int(0);
            vals_i__ = context__.vals_i("prior_dist");
            pos__ = 0;
            prior_dist = vals_i__[pos__++];
            check_greater_or_equal(function__, "prior_dist", prior_dist, 0);
            check_less_or_equal(function__, "prior_dist", prior_dist, 7);

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

            current_statement_begin__ = 414;
            context__.validate_dims("data initialization", "prior_dist_for_aux", "int", context__.to_vec());
            prior_dist_for_aux = int(0);
            vals_i__ = context__.vals_i("prior_dist_for_aux");
            pos__ = 0;
            prior_dist_for_aux = vals_i__[pos__++];
            check_greater_or_equal(function__, "prior_dist_for_aux", prior_dist_for_aux, 0);
            check_less_or_equal(function__, "prior_dist_for_aux", prior_dist_for_aux, 3);

            current_statement_begin__ = 417;
            context__.validate_dims("data initialization", "prior_dist_for_smooth", "int", context__.to_vec());
            prior_dist_for_smooth = int(0);
            vals_i__ = context__.vals_i("prior_dist_for_smooth");
            pos__ = 0;
            prior_dist_for_smooth = vals_i__[pos__++];
            check_greater_or_equal(function__, "prior_dist_for_smooth", prior_dist_for_smooth, 0);
            check_less_or_equal(function__, "prior_dist_for_smooth", prior_dist_for_smooth, 3);

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

            current_statement_begin__ = 421;
            validate_non_negative_index("weights", "(has_weights ? N : 0 )", (has_weights ? N : 0 ));
            context__.validate_dims("data initialization", "weights", "vector_d", context__.to_vec((has_weights ? N : 0 )));
            weights = Eigen::Matrix<double, Eigen::Dynamic, 1>((has_weights ? N : 0 ));
            vals_r__ = context__.vals_r("weights");
            pos__ = 0;
            size_t weights_j_1_max__ = (has_weights ? N : 0 );
            for (size_t j_1__ = 0; j_1__ < weights_j_1_max__; ++j_1__) {
                weights(j_1__) = vals_r__[pos__++];
            }

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

            current_statement_begin__ = 425;
            validate_non_negative_index("offset", "(has_offset ? N : 0 )", (has_offset ? N : 0 ));
            context__.validate_dims("data initialization", "offset", "vector_d", context__.to_vec((has_offset ? N : 0 )));
            offset = Eigen::Matrix<double, Eigen::Dynamic, 1>((has_offset ? N : 0 ));
            vals_r__ = context__.vals_r("offset");
            pos__ = 0;
            size_t offset_j_1_max__ = (has_offset ? N : 0 );
            for (size_t j_1__ = 0; j_1__ < offset_j_1_max__; ++j_1__) {
                offset(j_1__) = vals_r__[pos__++];
            }

            current_statement_begin__ = 426;
            context__.validate_dims("data initialization", "family", "int", context__.to_vec());
            family = int(0);
            vals_i__ = context__.vals_i("family");
            pos__ = 0;
            family = vals_i__[pos__++];
            check_greater_or_equal(function__, "family", family, 6);
            check_less_or_equal(function__, "family", family, 7);

            current_statement_begin__ = 429;
            validate_non_negative_index("prior_scale", "K", K);
            context__.validate_dims("data initialization", "prior_scale", "vector_d", context__.to_vec(K));
            prior_scale = Eigen::Matrix<double, Eigen::Dynamic, 1>(K);
            vals_r__ = context__.vals_r("prior_scale");
            pos__ = 0;
            size_t prior_scale_j_1_max__ = K;
            for (size_t j_1__ = 0; j_1__ < prior_scale_j_1_max__; ++j_1__) {
                prior_scale(j_1__) = vals_r__[pos__++];
            }
            check_greater_or_equal(function__, "prior_scale", prior_scale, 0);

            current_statement_begin__ = 430;
            context__.validate_dims("data initialization", "prior_scale_for_intercept", "double", context__.to_vec());
            prior_scale_for_intercept = double(0);
            vals_r__ = context__.vals_r("prior_scale_for_intercept");
            pos__ = 0;
            prior_scale_for_intercept = vals_r__[pos__++];
            check_greater_or_equal(function__, "prior_scale_for_intercept", prior_scale_for_intercept, 0);

            current_statement_begin__ = 431;
            context__.validate_dims("data initialization", "prior_scale_for_aux", "double", context__.to_vec());
            prior_scale_for_aux = double(0);
            vals_r__ = context__.vals_r("prior_scale_for_aux");
            pos__ = 0;
            prior_scale_for_aux = vals_r__[pos__++];
            check_greater_or_equal(function__, "prior_scale_for_aux", prior_scale_for_aux, 0);

            current_statement_begin__ = 432;
            validate_non_negative_index("prior_scale_for_smooth", "(logical_gt(K_smooth, 0) ? max(smooth_map) : 0 )", (logical_gt(K_smooth, 0) ? max(smooth_map) : 0 ));
            context__.validate_dims("data initialization", "prior_scale_for_smooth", "vector_d", context__.to_vec((logical_gt(K_smooth, 0) ? max(smooth_map) : 0 )));
            prior_scale_for_smooth = Eigen::Matrix<double, Eigen::Dynamic, 1>((logical_gt(K_smooth, 0) ? max(smooth_map) : 0 ));
            vals_r__ = context__.vals_r("prior_scale_for_smooth");
            pos__ = 0;
            size_t prior_scale_for_smooth_j_1_max__ = (logical_gt(K_smooth, 0) ? max(smooth_map) : 0 );
            for (size_t j_1__ = 0; j_1__ < prior_scale_for_smooth_j_1_max__; ++j_1__) {
                prior_scale_for_smooth(j_1__) = vals_r__[pos__++];
            }
            check_greater_or_equal(function__, "prior_scale_for_smooth", prior_scale_for_smooth, 0);

            current_statement_begin__ = 433;
            validate_non_negative_index("prior_mean", "K", K);
            context__.validate_dims("data initialization", "prior_mean", "vector_d", context__.to_vec(K));
            prior_mean = Eigen::Matrix<double, Eigen::Dynamic, 1>(K);
            vals_r__ = context__.vals_r("prior_mean");
            pos__ = 0;
            size_t prior_mean_j_1_max__ = K;
            for (size_t j_1__ = 0; j_1__ < prior_mean_j_1_max__; ++j_1__) {
                prior_mean(j_1__) = vals_r__[pos__++];
            }

            current_statement_begin__ = 434;
            context__.validate_dims("data initialization", "prior_mean_for_intercept", "double", context__.to_vec());
            prior_mean_for_intercept = double(0);
            vals_r__ = context__.vals_r("prior_mean_for_intercept");
            pos__ = 0;
            prior_mean_for_intercept = vals_r__[pos__++];

            current_statement_begin__ = 435;
            context__.validate_dims("data initialization", "prior_mean_for_aux", "double", context__.to_vec());
            prior_mean_for_aux = double(0);
            vals_r__ = context__.vals_r("prior_mean_for_aux");
            pos__ = 0;
            prior_mean_for_aux = vals_r__[pos__++];
            check_greater_or_equal(function__, "prior_mean_for_aux", prior_mean_for_aux, 0);

            current_statement_begin__ = 436;
            validate_non_negative_index("prior_mean_for_smooth", "(logical_gt(K_smooth, 0) ? max(smooth_map) : 0 )", (logical_gt(K_smooth, 0) ? max(smooth_map) : 0 ));
            context__.validate_dims("data initialization", "prior_mean_for_smooth", "vector_d", context__.to_vec((logical_gt(K_smooth, 0) ? max(smooth_map) : 0 )));
            prior_mean_for_smooth = Eigen::Matrix<double, Eigen::Dynamic, 1>((logical_gt(K_smooth, 0) ? max(smooth_map) : 0 ));
            vals_r__ = context__.vals_r("prior_mean_for_smooth");
            pos__ = 0;
            size_t prior_mean_for_smooth_j_1_max__ = (logical_gt(K_smooth, 0) ? max(smooth_map) : 0 );
            for (size_t j_1__ = 0; j_1__ < prior_mean_for_smooth_j_1_max__; ++j_1__) {
                prior_mean_for_smooth(j_1__) = vals_r__[pos__++];
            }
            check_greater_or_equal(function__, "prior_mean_for_smooth", prior_mean_for_smooth, 0);

            current_statement_begin__ = 437;
            validate_non_negative_index("prior_df", "K", K);
            context__.validate_dims("data initialization", "prior_df", "vector_d", context__.to_vec(K));
            prior_df = Eigen::Matrix<double, Eigen::Dynamic, 1>(K);
            vals_r__ = context__.vals_r("prior_df");
            pos__ = 0;
            size_t prior_df_j_1_max__ = K;
            for (size_t j_1__ = 0; j_1__ < prior_df_j_1_max__; ++j_1__) {
                prior_df(j_1__) = vals_r__[pos__++];
            }
            check_greater_or_equal(function__, "prior_df", prior_df, 0);

            current_statement_begin__ = 438;
            context__.validate_dims("data initialization", "prior_df_for_intercept", "double", context__.to_vec());
            prior_df_for_intercept = double(0);
            vals_r__ = context__.vals_r("prior_df_for_intercept");
            pos__ = 0;
            prior_df_for_intercept = vals_r__[pos__++];
            check_greater_or_equal(function__, "prior_df_for_intercept", prior_df_for_intercept, 0);

            current_statement_begin__ = 439;
            context__.validate_dims("data initialization", "prior_df_for_aux", "double", context__.to_vec());
            prior_df_for_aux = double(0);
            vals_r__ = context__.vals_r("prior_df_for_aux");
            pos__ = 0;
            prior_df_for_aux = vals_r__[pos__++];
            check_greater_or_equal(function__, "prior_df_for_aux", prior_df_for_aux, 0);

            current_statement_begin__ = 440;
            validate_non_negative_index("prior_df_for_smooth", "(logical_gt(K_smooth, 0) ? max(smooth_map) : 0 )", (logical_gt(K_smooth, 0) ? max(smooth_map) : 0 ));
            context__.validate_dims("data initialization", "prior_df_for_smooth", "vector_d", context__.to_vec((logical_gt(K_smooth, 0) ? max(smooth_map) : 0 )));
            prior_df_for_smooth = Eigen::Matrix<double, Eigen::Dynamic, 1>((logical_gt(K_smooth, 0) ? max(smooth_map) : 0 ));
            vals_r__ = context__.vals_r("prior_df_for_smooth");
            pos__ = 0;
            size_t prior_df_for_smooth_j_1_max__ = (logical_gt(K_smooth, 0) ? max(smooth_map) : 0 );
            for (size_t j_1__ = 0; j_1__ < prior_df_for_smooth_j_1_max__; ++j_1__) {
                prior_df_for_smooth(j_1__) = vals_r__[pos__++];
            }
            check_greater_or_equal(function__, "prior_df_for_smooth", prior_df_for_smooth, 0);

            current_statement_begin__ = 441;
            context__.validate_dims("data initialization", "global_prior_df", "double", context__.to_vec());
            global_prior_df = double(0);
            vals_r__ = context__.vals_r("global_prior_df");
            pos__ = 0;
            global_prior_df = vals_r__[pos__++];
            check_greater_or_equal(function__, "global_prior_df", global_prior_df, 0);

            current_statement_begin__ = 442;
            context__.validate_dims("data initialization", "global_prior_scale", "double", context__.to_vec());
            global_prior_scale = double(0);
            vals_r__ = context__.vals_r("global_prior_scale");
            pos__ = 0;
            global_prior_scale = vals_r__[pos__++];
            check_greater_or_equal(function__, "global_prior_scale", global_prior_scale, 0);

            current_statement_begin__ = 443;
            context__.validate_dims("data initialization", "slab_df", "double", context__.to_vec());
            slab_df = double(0);
            vals_r__ = context__.vals_r("slab_df");
            pos__ = 0;
            slab_df = vals_r__[pos__++];
            check_greater_or_equal(function__, "slab_df", slab_df, 0);

            current_statement_begin__ = 444;
            context__.validate_dims("data initialization", "slab_scale", "double", context__.to_vec());
            slab_scale = double(0);
            vals_r__ = context__.vals_r("slab_scale");
            pos__ = 0;
            slab_scale = vals_r__[pos__++];
            check_greater_or_equal(function__, "slab_scale", slab_scale, 0);

            current_statement_begin__ = 445;
            validate_non_negative_index("num_normals", "(logical_eq(prior_dist, 7) ? K : 0 )", (logical_eq(prior_dist, 7) ? K : 0 ));
            context__.validate_dims("data initialization", "num_normals", "int", context__.to_vec((logical_eq(prior_dist, 7) ? K : 0 )));
            num_normals = std::vector<int>((logical_eq(prior_dist, 7) ? K : 0 ), int(0));
            vals_i__ = context__.vals_i("num_normals");
            pos__ = 0;
            size_t num_normals_k_0_max__ = (logical_eq(prior_dist, 7) ? K : 0 );
            for (size_t k_0__ = 0; k_0__ < num_normals_k_0_max__; ++k_0__) {
                num_normals[k_0__] = vals_i__[pos__++];
            }
            size_t num_normals_i_0_max__ = (logical_eq(prior_dist, 7) ? K : 0 );
            for (size_t i_0__ = 0; i_0__ < num_normals_i_0_max__; ++i_0__) {
                check_greater_or_equal(function__, "num_normals[i_0__]", num_normals[i_0__], 2);
            }

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

            current_statement_begin__ = 450;
            validate_non_negative_index("p", "t", t);
            context__.validate_dims("data initialization", "p", "int", context__.to_vec(t));
            p = std::vector<int>(t, int(0));
            vals_i__ = context__.vals_i("p");
            pos__ = 0;
            size_t p_k_0_max__ = t;
            for (size_t k_0__ = 0; k_0__ < p_k_0_max__; ++k_0__) {
                p[k_0__] = vals_i__[pos__++];
            }
            size_t p_i_0_max__ = t;
            for (size_t i_0__ = 0; i_0__ < p_i_0_max__; ++i_0__) {
                check_greater_or_equal(function__, "p[i_0__]", p[i_0__], 1);
            }

            current_statement_begin__ = 451;
            validate_non_negative_index("l", "t", t);
            context__.validate_dims("data initialization", "l", "int", context__.to_vec(t));
            l = std::vector<int>(t, int(0));
            vals_i__ = context__.vals_i("l");
            pos__ = 0;
            size_t l_k_0_max__ = t;
            for (size_t k_0__ = 0; k_0__ < l_k_0_max__; ++k_0__) {
                l[k_0__] = vals_i__[pos__++];
            }
            size_t l_i_0_max__ = t;
            for (size_t i_0__ = 0; i_0__ < l_i_0_max__; ++i_0__) {
                check_greater_or_equal(function__, "l[i_0__]", l[i_0__], 1);
            }

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

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

            current_statement_begin__ = 456;
            validate_non_negative_index("shape", "t", t);
            context__.validate_dims("data initialization", "shape", "vector_d", context__.to_vec(t));
            shape = Eigen::Matrix<double, Eigen::Dynamic, 1>(t);
            vals_r__ = context__.vals_r("shape");
            pos__ = 0;
            size_t shape_j_1_max__ = t;
            for (size_t j_1__ = 0; j_1__ < shape_j_1_max__; ++j_1__) {
                shape(j_1__) = vals_r__[pos__++];
            }
            check_greater_or_equal(function__, "shape", shape, 0);

            current_statement_begin__ = 457;
            validate_non_negative_index("scale", "t", t);
            context__.validate_dims("data initialization", "scale", "vector_d", context__.to_vec(t));
            scale = Eigen::Matrix<double, Eigen::Dynamic, 1>(t);
            vals_r__ = context__.vals_r("scale");
            pos__ = 0;
            size_t scale_j_1_max__ = t;
            for (size_t j_1__ = 0; j_1__ < scale_j_1_max__; ++j_1__) {
                scale(j_1__) = vals_r__[pos__++];
            }
            check_greater_or_equal(function__, "scale", scale, 0);

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

            current_statement_begin__ = 459;
            validate_non_negative_index("concentration", "len_concentration", len_concentration);
            context__.validate_dims("data initialization", "concentration", "double", context__.to_vec(len_concentration));
            concentration = std::vector<double>(len_concentration, double(0));
            vals_r__ = context__.vals_r("concentration");
            pos__ = 0;
            size_t concentration_k_0_max__ = len_concentration;
            for (size_t k_0__ = 0; k_0__ < concentration_k_0_max__; ++k_0__) {
                concentration[k_0__] = vals_r__[pos__++];
            }
            size_t concentration_i_0_max__ = len_concentration;
            for (size_t i_0__ = 0; i_0__ < concentration_i_0_max__; ++i_0__) {
                check_greater_or_equal(function__, "concentration[i_0__]", concentration[i_0__], 0);
            }

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

            current_statement_begin__ = 461;
            validate_non_negative_index("regularization", "len_regularization", len_regularization);
            context__.validate_dims("data initialization", "regularization", "double", context__.to_vec(len_regularization));
            regularization = std::vector<double>(len_regularization, double(0));
            vals_r__ = context__.vals_r("regularization");
            pos__ = 0;
            size_t regularization_k_0_max__ = len_regularization;
            for (size_t k_0__ = 0; k_0__ < regularization_k_0_max__; ++k_0__) {
                regularization[k_0__] = vals_r__[pos__++];
            }
            size_t regularization_i_0_max__ = len_regularization;
            for (size_t i_0__ = 0; i_0__ < regularization_i_0_max__; ++i_0__) {
                check_greater_or_equal(function__, "regularization[i_0__]", regularization[i_0__], 0);
            }

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

            current_statement_begin__ = 464;
            validate_non_negative_index("w", "num_non_zero", num_non_zero);
            context__.validate_dims("data initialization", "w", "vector_d", context__.to_vec(num_non_zero));
            w = Eigen::Matrix<double, Eigen::Dynamic, 1>(num_non_zero);
            vals_r__ = context__.vals_r("w");
            pos__ = 0;
            size_t w_j_1_max__ = num_non_zero;
            for (size_t j_1__ = 0; j_1__ < w_j_1_max__; ++j_1__) {
                w(j_1__) = vals_r__[pos__++];
            }

            current_statement_begin__ = 465;
            validate_non_negative_index("v", "num_non_zero", num_non_zero);
            context__.validate_dims("data initialization", "v", "int", context__.to_vec(num_non_zero));
            v = std::vector<int>(num_non_zero, int(0));
            vals_i__ = context__.vals_i("v");
            pos__ = 0;
            size_t v_k_0_max__ = num_non_zero;
            for (size_t k_0__ = 0; k_0__ < v_k_0_max__; ++k_0__) {
                v[k_0__] = vals_i__[pos__++];
            }
            size_t v_i_0_max__ = num_non_zero;
            for (size_t i_0__ = 0; i_0__ < v_i_0_max__; ++i_0__) {
                check_greater_or_equal(function__, "v[i_0__]", v[i_0__], 0);
                check_less_or_equal(function__, "v[i_0__]", v[i_0__], (q - 1));
            }

            current_statement_begin__ = 466;
            validate_non_negative_index("u", "(logical_gt(t, 0) ? (N + 1) : 0 )", (logical_gt(t, 0) ? (N + 1) : 0 ));
            context__.validate_dims("data initialization", "u", "int", context__.to_vec((logical_gt(t, 0) ? (N + 1) : 0 )));
            u = std::vector<int>((logical_gt(t, 0) ? (N + 1) : 0 ), int(0));
            vals_i__ = context__.vals_i("u");
            pos__ = 0;
            size_t u_k_0_max__ = (logical_gt(t, 0) ? (N + 1) : 0 );
            for (size_t k_0__ = 0; k_0__ < u_k_0_max__; ++k_0__) {
                u[k_0__] = vals_i__[pos__++];
            }
            size_t u_i_0_max__ = (logical_gt(t, 0) ? (N + 1) : 0 );
            for (size_t i_0__ = 0; i_0__ < u_i_0_max__; ++i_0__) {
                check_greater_or_equal(function__, "u[i_0__]", u[i_0__], 0);
                check_less_or_equal(function__, "u[i_0__]", u[i_0__], (rows(w) + 1));
            }

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


            // initialize transformed data variables
            current_statement_begin__ = 470;
            poisson_max = double(0);
            stan::math::fill(poisson_max, DUMMY_VAR__);
            stan::math::assign(poisson_max,pow(2.0, 30.0));

            current_statement_begin__ = 471;
            validate_non_negative_index("V", "(special_case ? t : 0 )", (special_case ? t : 0 ));
            validate_non_negative_index("V", "N", N);
            V = std::vector<std::vector<int> >((special_case ? t : 0 ), std::vector<int>(N, int(0)));
            stan::math::fill(V, std::numeric_limits<int>::min());
            stan::math::assign(V,make_V(N, (special_case ? t : 0 ), v, pstream__));

            current_statement_begin__ = 473;
            can_do_countlogglm = int(0);
            stan::math::fill(can_do_countlogglm, std::numeric_limits<int>::min());
            stan::math::assign(can_do_countlogglm,(primitive_value((primitive_value((primitive_value((primitive_value(logical_eq(link, 1)) && primitive_value(logical_eq(prior_PD, 0)))) && primitive_value(logical_eq(dense_X, 1)))) && primitive_value(logical_eq(has_weights, 0)))) && primitive_value(logical_eq(t, 0))));

            current_statement_begin__ = 474;
            validate_non_negative_index("XS", "(can_do_countlogglm ? N : 0 )", (can_do_countlogglm ? N : 0 ));
            validate_non_negative_index("XS", "(can_do_countlogglm ? (K + K_smooth) : 0 )", (can_do_countlogglm ? (K + K_smooth) : 0 ));
            XS = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>((can_do_countlogglm ? N : 0 ), (can_do_countlogglm ? (K + K_smooth) : 0 ));
            stan::math::fill(XS, DUMMY_VAR__);

            current_statement_begin__ = 477;
            len_z_T = int(0);
            stan::math::fill(len_z_T, std::numeric_limits<int>::min());
            stan::math::assign(len_z_T,0);

            current_statement_begin__ = 478;
            len_var_group = int(0);
            stan::math::fill(len_var_group, std::numeric_limits<int>::min());
            stan::math::assign(len_var_group,(sum(p) * logical_gt(t, 0)));

            current_statement_begin__ = 479;
            len_rho = int(0);
            stan::math::fill(len_rho, std::numeric_limits<int>::min());
            stan::math::assign(len_rho,(sum(p) - t));

            current_statement_begin__ = 480;
            is_continuous = int(0);
            stan::math::fill(is_continuous, std::numeric_limits<int>::min());
            stan::math::assign(is_continuous,0);

            current_statement_begin__ = 481;
            pos = int(0);
            stan::math::fill(pos, std::numeric_limits<int>::min());
            stan::math::assign(pos,1);

            current_statement_begin__ = 482;
            validate_non_negative_index("delta", "len_concentration", len_concentration);
            delta = std::vector<double>(len_concentration, double(0));
            stan::math::fill(delta, DUMMY_VAR__);

            current_statement_begin__ = 483;
            hs = int(0);
            stan::math::fill(hs, std::numeric_limits<int>::min());

            // execute transformed data statements
            current_statement_begin__ = 484;
            if (as_bool(logical_lte(prior_dist, 2))) {
                current_statement_begin__ = 484;
                stan::math::assign(hs, 0);
            } else if (as_bool(logical_eq(prior_dist, 3))) {
                current_statement_begin__ = 485;
                stan::math::assign(hs, 2);
            } else if (as_bool(logical_eq(prior_dist, 4))) {
                current_statement_begin__ = 486;
                stan::math::assign(hs, 4);
            } else {
                current_statement_begin__ = 487;
                stan::math::assign(hs, 0);
            }
            current_statement_begin__ = 489;
            for (int i = 1; i <= t; ++i) {

                current_statement_begin__ = 490;
                if (as_bool(logical_gt(get_base1(p, i, "p", 1), 1))) {

                    current_statement_begin__ = 491;
                    for (int j = 1; j <= get_base1(p, i, "p", 1); ++j) {

                        current_statement_begin__ = 492;
                        stan::model::assign(delta, 
                                    stan::model::cons_list(stan::model::index_uni(pos), stan::model::nil_index_list()), 
                                    get_base1(concentration, j, "concentration", 1), 
                                    "assigning variable delta");
                        current_statement_begin__ = 493;
                        stan::math::assign(pos, (pos + 1));
                    }
                }
                current_statement_begin__ = 496;
                for (int j = 3; j <= get_base1(p, i, "p", 1); ++j) {
                    current_statement_begin__ = 496;
                    stan::math::assign(len_z_T, (len_z_T + (get_base1(p, i, "p", 1) - 1)));
                }
            }
            current_statement_begin__ = 499;
            if (as_bool(can_do_countlogglm)) {

                current_statement_begin__ = 500;
                stan::math::assign(XS, (logical_gt(K_smooth, 0) ? stan::math::promote_scalar<double>(append_col(get_base1(X, 1, "X", 1), S)) : stan::math::promote_scalar<double>(get_base1(X, 1, "X", 1)) ));
            }

            // validate transformed data
            current_statement_begin__ = 471;
            size_t V_i_0_max__ = (special_case ? t : 0 );
            size_t V_i_1_max__ = N;
            for (size_t i_0__ = 0; i_0__ < V_i_0_max__; ++i_0__) {
                for (size_t i_1__ = 0; i_1__ < V_i_1_max__; ++i_1__) {
                    check_greater_or_equal(function__, "V[i_0__][i_1__]", V[i_0__][i_1__], 1);
                }
            }

            current_statement_begin__ = 477;
            check_greater_or_equal(function__, "len_z_T", len_z_T, 0);

            current_statement_begin__ = 478;
            check_greater_or_equal(function__, "len_var_group", len_var_group, 0);

            current_statement_begin__ = 479;
            check_greater_or_equal(function__, "len_rho", len_rho, 0);

            current_statement_begin__ = 480;
            check_greater_or_equal(function__, "is_continuous", is_continuous, 0);
            check_less_or_equal(function__, "is_continuous", is_continuous, 1);

            current_statement_begin__ = 481;
            check_greater_or_equal(function__, "pos", pos, 1);

            current_statement_begin__ = 482;
            size_t delta_i_0_max__ = len_concentration;
            for (size_t i_0__ = 0; i_0__ < delta_i_0_max__; ++i_0__) {
                check_greater_or_equal(function__, "delta[i_0__]", delta[i_0__], 0);
            }

            current_statement_begin__ = 483;
            check_greater_or_equal(function__, "hs", hs, 0);


            // validate, set parameter ranges
            num_params_r__ = 0U;
            param_ranges_i__.clear();
            current_statement_begin__ = 504;
            validate_non_negative_index("gamma", "has_intercept", has_intercept);
            num_params_r__ += (1 * has_intercept);
            current_statement_begin__ = 506;
            validate_non_negative_index("z_beta", "(logical_eq(prior_dist, 7) ? sum(num_normals) : K )", (logical_eq(prior_dist, 7) ? sum(num_normals) : K ));
            num_params_r__ += (logical_eq(prior_dist, 7) ? sum(num_normals) : K );
            current_statement_begin__ = 507;
            validate_non_negative_index("z_beta_smooth", "K_smooth", K_smooth);
            num_params_r__ += K_smooth;
            current_statement_begin__ = 508;
            validate_non_negative_index("smooth_sd_raw", "(logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, \"smooth_map\", 1) : 0 )", (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 ));
            num_params_r__ += (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 );
            current_statement_begin__ = 509;
            validate_non_negative_index("global", "hs", hs);
            num_params_r__ += (1 * hs);
            current_statement_begin__ = 510;
            validate_non_negative_index("local", "K", K);
            validate_non_negative_index("local", "hs", hs);
            num_params_r__ += (K * hs);
            current_statement_begin__ = 511;
            validate_non_negative_index("caux", "logical_gt(hs, 0)", logical_gt(hs, 0));
            num_params_r__ += (1 * logical_gt(hs, 0));
            current_statement_begin__ = 512;
            validate_non_negative_index("mix", "K", K);
            validate_non_negative_index("mix", "(primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6)))", (primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6))));
            num_params_r__ += (K * (primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6))));
            current_statement_begin__ = 513;
            validate_non_negative_index("one_over_lambda", "logical_eq(prior_dist, 6)", logical_eq(prior_dist, 6));
            num_params_r__ += (1 * logical_eq(prior_dist, 6));
            current_statement_begin__ = 514;
            validate_non_negative_index("z_b", "q", q);
            num_params_r__ += q;
            current_statement_begin__ = 515;
            validate_non_negative_index("z_T", "len_z_T", len_z_T);
            num_params_r__ += len_z_T;
            current_statement_begin__ = 516;
            validate_non_negative_index("rho", "len_rho", len_rho);
            num_params_r__ += len_rho;
            current_statement_begin__ = 517;
            validate_non_negative_index("zeta", "len_concentration", len_concentration);
            num_params_r__ += len_concentration;
            current_statement_begin__ = 518;
            validate_non_negative_index("tau", "t", t);
            num_params_r__ += t;
            current_statement_begin__ = 519;
            validate_non_negative_index("aux_unscaled", "logical_gt(family, 6)", logical_gt(family, 6));
            num_params_r__ += (1 * logical_gt(family, 6));
            current_statement_begin__ = 520;
            validate_non_negative_index("noise", "N", N);
            validate_non_negative_index("noise", "logical_eq(family, 8)", logical_eq(family, 8));
            num_params_r__ += (N * logical_eq(family, 8));
        } 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 ***");
        }
    }

    ~model_count() { }


    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__ = 504;
        if (!(context__.contains_r("gamma")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable gamma missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("gamma");
        pos__ = 0U;
        validate_non_negative_index("gamma", "has_intercept", has_intercept);
        context__.validate_dims("parameter initialization", "gamma", "double", context__.to_vec(has_intercept));
        std::vector<double> gamma(has_intercept, double(0));
        size_t gamma_k_0_max__ = has_intercept;
        for (size_t k_0__ = 0; k_0__ < gamma_k_0_max__; ++k_0__) {
            gamma[k_0__] = vals_r__[pos__++];
        }
        size_t gamma_i_0_max__ = has_intercept;
        for (size_t i_0__ = 0; i_0__ < gamma_i_0_max__; ++i_0__) {
            try {
                writer__.scalar_lb_unconstrain((logical_eq(link, 1) ? stan::math::negative_infinity() : 0.0 ), gamma[i_0__]);
            } catch (const std::exception& e) {
                stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable gamma: ") + e.what()), current_statement_begin__, prog_reader__());
            }
        }

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

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

        current_statement_begin__ = 508;
        if (!(context__.contains_r("smooth_sd_raw")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable smooth_sd_raw missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("smooth_sd_raw");
        pos__ = 0U;
        validate_non_negative_index("smooth_sd_raw", "(logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, \"smooth_map\", 1) : 0 )", (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 ));
        context__.validate_dims("parameter initialization", "smooth_sd_raw", "vector_d", context__.to_vec((logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 )));
        Eigen::Matrix<double, Eigen::Dynamic, 1> smooth_sd_raw((logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 ));
        size_t smooth_sd_raw_j_1_max__ = (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 );
        for (size_t j_1__ = 0; j_1__ < smooth_sd_raw_j_1_max__; ++j_1__) {
            smooth_sd_raw(j_1__) = vals_r__[pos__++];
        }
        try {
            writer__.vector_lb_unconstrain(0, smooth_sd_raw);
        } catch (const std::exception& e) {
            stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable smooth_sd_raw: ") + e.what()), current_statement_begin__, prog_reader__());
        }

        current_statement_begin__ = 509;
        if (!(context__.contains_r("global")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable global missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("global");
        pos__ = 0U;
        validate_non_negative_index("global", "hs", hs);
        context__.validate_dims("parameter initialization", "global", "double", context__.to_vec(hs));
        std::vector<double> global(hs, double(0));
        size_t global_k_0_max__ = hs;
        for (size_t k_0__ = 0; k_0__ < global_k_0_max__; ++k_0__) {
            global[k_0__] = vals_r__[pos__++];
        }
        size_t global_i_0_max__ = hs;
        for (size_t i_0__ = 0; i_0__ < global_i_0_max__; ++i_0__) {
            try {
                writer__.scalar_lb_unconstrain(0, global[i_0__]);
            } catch (const std::exception& e) {
                stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable global: ") + e.what()), current_statement_begin__, prog_reader__());
            }
        }

        current_statement_begin__ = 510;
        if (!(context__.contains_r("local")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable local missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("local");
        pos__ = 0U;
        validate_non_negative_index("local", "K", K);
        validate_non_negative_index("local", "hs", hs);
        context__.validate_dims("parameter initialization", "local", "vector_d", context__.to_vec(hs,K));
        std::vector<Eigen::Matrix<double, Eigen::Dynamic, 1> > local(hs, Eigen::Matrix<double, Eigen::Dynamic, 1>(K));
        size_t local_j_1_max__ = K;
        size_t local_k_0_max__ = hs;
        for (size_t j_1__ = 0; j_1__ < local_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < local_k_0_max__; ++k_0__) {
                local[k_0__](j_1__) = vals_r__[pos__++];
            }
        }
        size_t local_i_0_max__ = hs;
        for (size_t i_0__ = 0; i_0__ < local_i_0_max__; ++i_0__) {
            try {
                writer__.vector_lb_unconstrain(0, local[i_0__]);
            } catch (const std::exception& e) {
                stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable local: ") + e.what()), current_statement_begin__, prog_reader__());
            }
        }

        current_statement_begin__ = 511;
        if (!(context__.contains_r("caux")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable caux missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("caux");
        pos__ = 0U;
        validate_non_negative_index("caux", "logical_gt(hs, 0)", logical_gt(hs, 0));
        context__.validate_dims("parameter initialization", "caux", "double", context__.to_vec(logical_gt(hs, 0)));
        std::vector<double> caux(logical_gt(hs, 0), double(0));
        size_t caux_k_0_max__ = logical_gt(hs, 0);
        for (size_t k_0__ = 0; k_0__ < caux_k_0_max__; ++k_0__) {
            caux[k_0__] = vals_r__[pos__++];
        }
        size_t caux_i_0_max__ = logical_gt(hs, 0);
        for (size_t i_0__ = 0; i_0__ < caux_i_0_max__; ++i_0__) {
            try {
                writer__.scalar_lb_unconstrain(0, caux[i_0__]);
            } catch (const std::exception& e) {
                stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable caux: ") + e.what()), current_statement_begin__, prog_reader__());
            }
        }

        current_statement_begin__ = 512;
        if (!(context__.contains_r("mix")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable mix missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("mix");
        pos__ = 0U;
        validate_non_negative_index("mix", "K", K);
        validate_non_negative_index("mix", "(primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6)))", (primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6))));
        context__.validate_dims("parameter initialization", "mix", "vector_d", context__.to_vec((primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6))),K));
        std::vector<Eigen::Matrix<double, Eigen::Dynamic, 1> > mix((primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6))), Eigen::Matrix<double, Eigen::Dynamic, 1>(K));
        size_t mix_j_1_max__ = K;
        size_t mix_k_0_max__ = (primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6)));
        for (size_t j_1__ = 0; j_1__ < mix_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < mix_k_0_max__; ++k_0__) {
                mix[k_0__](j_1__) = vals_r__[pos__++];
            }
        }
        size_t mix_i_0_max__ = (primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6)));
        for (size_t i_0__ = 0; i_0__ < mix_i_0_max__; ++i_0__) {
            try {
                writer__.vector_lb_unconstrain(0, mix[i_0__]);
            } catch (const std::exception& e) {
                stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable mix: ") + e.what()), current_statement_begin__, prog_reader__());
            }
        }

        current_statement_begin__ = 513;
        if (!(context__.contains_r("one_over_lambda")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable one_over_lambda missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("one_over_lambda");
        pos__ = 0U;
        validate_non_negative_index("one_over_lambda", "logical_eq(prior_dist, 6)", logical_eq(prior_dist, 6));
        context__.validate_dims("parameter initialization", "one_over_lambda", "double", context__.to_vec(logical_eq(prior_dist, 6)));
        std::vector<double> one_over_lambda(logical_eq(prior_dist, 6), double(0));
        size_t one_over_lambda_k_0_max__ = logical_eq(prior_dist, 6);
        for (size_t k_0__ = 0; k_0__ < one_over_lambda_k_0_max__; ++k_0__) {
            one_over_lambda[k_0__] = vals_r__[pos__++];
        }
        size_t one_over_lambda_i_0_max__ = logical_eq(prior_dist, 6);
        for (size_t i_0__ = 0; i_0__ < one_over_lambda_i_0_max__; ++i_0__) {
            try {
                writer__.scalar_lb_unconstrain(0, one_over_lambda[i_0__]);
            } catch (const std::exception& e) {
                stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable one_over_lambda: ") + e.what()), current_statement_begin__, prog_reader__());
            }
        }

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

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

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

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

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

        current_statement_begin__ = 519;
        if (!(context__.contains_r("aux_unscaled")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable aux_unscaled missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("aux_unscaled");
        pos__ = 0U;
        validate_non_negative_index("aux_unscaled", "logical_gt(family, 6)", logical_gt(family, 6));
        context__.validate_dims("parameter initialization", "aux_unscaled", "double", context__.to_vec(logical_gt(family, 6)));
        std::vector<double> aux_unscaled(logical_gt(family, 6), double(0));
        size_t aux_unscaled_k_0_max__ = logical_gt(family, 6);
        for (size_t k_0__ = 0; k_0__ < aux_unscaled_k_0_max__; ++k_0__) {
            aux_unscaled[k_0__] = vals_r__[pos__++];
        }
        size_t aux_unscaled_i_0_max__ = logical_gt(family, 6);
        for (size_t i_0__ = 0; i_0__ < aux_unscaled_i_0_max__; ++i_0__) {
            try {
                writer__.scalar_lb_unconstrain(0, aux_unscaled[i_0__]);
            } catch (const std::exception& e) {
                stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable aux_unscaled: ") + e.what()), current_statement_begin__, prog_reader__());
            }
        }

        current_statement_begin__ = 520;
        if (!(context__.contains_r("noise")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable noise missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("noise");
        pos__ = 0U;
        validate_non_negative_index("noise", "N", N);
        validate_non_negative_index("noise", "logical_eq(family, 8)", logical_eq(family, 8));
        context__.validate_dims("parameter initialization", "noise", "vector_d", context__.to_vec(logical_eq(family, 8),N));
        std::vector<Eigen::Matrix<double, Eigen::Dynamic, 1> > noise(logical_eq(family, 8), Eigen::Matrix<double, Eigen::Dynamic, 1>(N));
        size_t noise_j_1_max__ = N;
        size_t noise_k_0_max__ = logical_eq(family, 8);
        for (size_t j_1__ = 0; j_1__ < noise_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < noise_k_0_max__; ++k_0__) {
                noise[k_0__](j_1__) = vals_r__[pos__++];
            }
        }
        size_t noise_i_0_max__ = logical_eq(family, 8);
        for (size_t i_0__ = 0; i_0__ < noise_i_0_max__; ++i_0__) {
            try {
                writer__.vector_lb_unconstrain(0, noise[i_0__]);
            } catch (const std::exception& e) {
                stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable noise: ") + 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__ = 504;
            std::vector<local_scalar_t__> gamma;
            size_t gamma_d_0_max__ = has_intercept;
            gamma.reserve(gamma_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < gamma_d_0_max__; ++d_0__) {
                if (jacobian__)
                    gamma.push_back(in__.scalar_lb_constrain((logical_eq(link, 1) ? stan::math::negative_infinity() : 0.0 ), lp__));
                else
                    gamma.push_back(in__.scalar_lb_constrain((logical_eq(link, 1) ? stan::math::negative_infinity() : 0.0 )));
            }

            current_statement_begin__ = 506;
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> z_beta;
            (void) z_beta;  // dummy to suppress unused var warning
            if (jacobian__)
                z_beta = in__.vector_constrain((logical_eq(prior_dist, 7) ? sum(num_normals) : K ), lp__);
            else
                z_beta = in__.vector_constrain((logical_eq(prior_dist, 7) ? sum(num_normals) : K ));

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

            current_statement_begin__ = 508;
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> smooth_sd_raw;
            (void) smooth_sd_raw;  // dummy to suppress unused var warning
            if (jacobian__)
                smooth_sd_raw = in__.vector_lb_constrain(0, (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 ), lp__);
            else
                smooth_sd_raw = in__.vector_lb_constrain(0, (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 ));

            current_statement_begin__ = 509;
            std::vector<local_scalar_t__> global;
            size_t global_d_0_max__ = hs;
            global.reserve(global_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < global_d_0_max__; ++d_0__) {
                if (jacobian__)
                    global.push_back(in__.scalar_lb_constrain(0, lp__));
                else
                    global.push_back(in__.scalar_lb_constrain(0));
            }

            current_statement_begin__ = 510;
            std::vector<Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> > local;
            size_t local_d_0_max__ = hs;
            local.reserve(local_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < local_d_0_max__; ++d_0__) {
                if (jacobian__)
                    local.push_back(in__.vector_lb_constrain(0, K, lp__));
                else
                    local.push_back(in__.vector_lb_constrain(0, K));
            }

            current_statement_begin__ = 511;
            std::vector<local_scalar_t__> caux;
            size_t caux_d_0_max__ = logical_gt(hs, 0);
            caux.reserve(caux_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < caux_d_0_max__; ++d_0__) {
                if (jacobian__)
                    caux.push_back(in__.scalar_lb_constrain(0, lp__));
                else
                    caux.push_back(in__.scalar_lb_constrain(0));
            }

            current_statement_begin__ = 512;
            std::vector<Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> > mix;
            size_t mix_d_0_max__ = (primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6)));
            mix.reserve(mix_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < mix_d_0_max__; ++d_0__) {
                if (jacobian__)
                    mix.push_back(in__.vector_lb_constrain(0, K, lp__));
                else
                    mix.push_back(in__.vector_lb_constrain(0, K));
            }

            current_statement_begin__ = 513;
            std::vector<local_scalar_t__> one_over_lambda;
            size_t one_over_lambda_d_0_max__ = logical_eq(prior_dist, 6);
            one_over_lambda.reserve(one_over_lambda_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < one_over_lambda_d_0_max__; ++d_0__) {
                if (jacobian__)
                    one_over_lambda.push_back(in__.scalar_lb_constrain(0, lp__));
                else
                    one_over_lambda.push_back(in__.scalar_lb_constrain(0));
            }

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

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

            current_statement_begin__ = 516;
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> rho;
            (void) rho;  // dummy to suppress unused var warning
            if (jacobian__)
                rho = in__.vector_lub_constrain(0, 1, len_rho, lp__);
            else
                rho = in__.vector_lub_constrain(0, 1, len_rho);

            current_statement_begin__ = 517;
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> zeta;
            (void) zeta;  // dummy to suppress unused var warning
            if (jacobian__)
                zeta = in__.vector_lb_constrain(0, len_concentration, lp__);
            else
                zeta = in__.vector_lb_constrain(0, len_concentration);

            current_statement_begin__ = 518;
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> tau;
            (void) tau;  // dummy to suppress unused var warning
            if (jacobian__)
                tau = in__.vector_lb_constrain(0, t, lp__);
            else
                tau = in__.vector_lb_constrain(0, t);

            current_statement_begin__ = 519;
            std::vector<local_scalar_t__> aux_unscaled;
            size_t aux_unscaled_d_0_max__ = logical_gt(family, 6);
            aux_unscaled.reserve(aux_unscaled_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < aux_unscaled_d_0_max__; ++d_0__) {
                if (jacobian__)
                    aux_unscaled.push_back(in__.scalar_lb_constrain(0, lp__));
                else
                    aux_unscaled.push_back(in__.scalar_lb_constrain(0));
            }

            current_statement_begin__ = 520;
            std::vector<Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> > noise;
            size_t noise_d_0_max__ = logical_eq(family, 8);
            noise.reserve(noise_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < noise_d_0_max__; ++d_0__) {
                if (jacobian__)
                    noise.push_back(in__.vector_lb_constrain(0, N, lp__));
                else
                    noise.push_back(in__.vector_lb_constrain(0, N));
            }

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

            current_statement_begin__ = 525;
            validate_non_negative_index("beta", "K", K);
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> beta(K);
            stan::math::initialize(beta, DUMMY_VAR__);
            stan::math::fill(beta, DUMMY_VAR__);

            current_statement_begin__ = 526;
            validate_non_negative_index("beta_smooth", "K_smooth", K_smooth);
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> beta_smooth(K_smooth);
            stan::math::initialize(beta_smooth, DUMMY_VAR__);
            stan::math::fill(beta_smooth, DUMMY_VAR__);

            current_statement_begin__ = 527;
            validate_non_negative_index("smooth_sd", "(logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, \"smooth_map\", 1) : 0 )", (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 ));
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> smooth_sd((logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 ));
            stan::math::initialize(smooth_sd, DUMMY_VAR__);
            stan::math::fill(smooth_sd, DUMMY_VAR__);

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

            current_statement_begin__ = 529;
            validate_non_negative_index("theta_L", "len_theta_L", len_theta_L);
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> theta_L(len_theta_L);
            stan::math::initialize(theta_L, DUMMY_VAR__);
            stan::math::fill(theta_L, DUMMY_VAR__);

            // transformed parameters block statements
            current_statement_begin__ = 530;
            if (as_bool(logical_eq(prior_dist, 0))) {
                current_statement_begin__ = 530;
                stan::math::assign(beta, z_beta);
            } else if (as_bool(logical_eq(prior_dist, 1))) {
                current_statement_begin__ = 531;
                stan::math::assign(beta, add(elt_multiply(z_beta, prior_scale), prior_mean));
            } else if (as_bool(logical_eq(prior_dist, 2))) {
                current_statement_begin__ = 532;
                for (int k = 1; k <= K; ++k) {

                    current_statement_begin__ = 533;
                    stan::model::assign(beta, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                ((CFt(get_base1(z_beta, k, "z_beta", 1), get_base1(prior_df, k, "prior_df", 1), pstream__) * get_base1(prior_scale, k, "prior_scale", 1)) + get_base1(prior_mean, k, "prior_mean", 1)), 
                                "assigning variable beta");
                }
            } else if (as_bool(logical_eq(prior_dist, 3))) {
                {
                current_statement_begin__ = 536;
                local_scalar_t__ c2(DUMMY_VAR__);
                (void) c2;  // dummy to suppress unused var warning
                stan::math::initialize(c2, DUMMY_VAR__);
                stan::math::fill(c2, DUMMY_VAR__);
                stan::math::assign(c2,(square(slab_scale) * get_base1(caux, 1, "caux", 1)));


                current_statement_begin__ = 537;
                if (as_bool((primitive_value(logical_eq(is_continuous, 1)) && primitive_value(logical_eq(family, 1))))) {
                    current_statement_begin__ = 538;
                    stan::math::assign(beta, hs_prior(z_beta, global, local, global_prior_scale, aux, c2, pstream__));
                } else {
                    current_statement_begin__ = 539;
                    stan::math::assign(beta, hs_prior(z_beta, global, local, global_prior_scale, 1, c2, pstream__));
                }
                }
            } else if (as_bool(logical_eq(prior_dist, 4))) {
                {
                current_statement_begin__ = 542;
                local_scalar_t__ c2(DUMMY_VAR__);
                (void) c2;  // dummy to suppress unused var warning
                stan::math::initialize(c2, DUMMY_VAR__);
                stan::math::fill(c2, DUMMY_VAR__);
                stan::math::assign(c2,(square(slab_scale) * get_base1(caux, 1, "caux", 1)));


                current_statement_begin__ = 543;
                if (as_bool((primitive_value(logical_eq(is_continuous, 1)) && primitive_value(logical_eq(family, 1))))) {
                    current_statement_begin__ = 544;
                    stan::math::assign(beta, hsplus_prior(z_beta, global, local, global_prior_scale, aux, c2, pstream__));
                } else {
                    current_statement_begin__ = 545;
                    stan::math::assign(beta, hsplus_prior(z_beta, global, local, global_prior_scale, 1, c2, pstream__));
                }
                }
            } else if (as_bool(logical_eq(prior_dist, 5))) {
                current_statement_begin__ = 548;
                stan::math::assign(beta, add(prior_mean, elt_multiply(elt_multiply(prior_scale, stan::math::sqrt(multiply(2, get_base1(mix, 1, "mix", 1)))), z_beta)));
            } else if (as_bool(logical_eq(prior_dist, 6))) {
                current_statement_begin__ = 550;
                stan::math::assign(beta, add(prior_mean, elt_multiply(elt_multiply(multiply(get_base1(one_over_lambda, 1, "one_over_lambda", 1), prior_scale), stan::math::sqrt(multiply(2, get_base1(mix, 1, "mix", 1)))), z_beta)));
            } else if (as_bool(logical_eq(prior_dist, 7))) {
                {
                current_statement_begin__ = 552;
                int z_pos(0);
                (void) z_pos;  // dummy to suppress unused var warning
                stan::math::fill(z_pos, std::numeric_limits<int>::min());
                stan::math::assign(z_pos,1);


                current_statement_begin__ = 553;
                for (int k = 1; k <= K; ++k) {

                    current_statement_begin__ = 554;
                    stan::model::assign(beta, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                get_base1(z_beta, z_pos, "z_beta", 1), 
                                "assigning variable beta");
                    current_statement_begin__ = 555;
                    stan::math::assign(z_pos, (z_pos + 1));
                    current_statement_begin__ = 556;
                    for (int n = 2; n <= get_base1(num_normals, k, "num_normals", 1); ++n) {

                        current_statement_begin__ = 557;
                        stan::model::assign(beta, 
                                    stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                    (stan::model::rvalue(beta, stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), "beta") * get_base1(z_beta, z_pos, "z_beta", 1)), 
                                    "assigning variable beta");
                        current_statement_begin__ = 558;
                        stan::math::assign(z_pos, (z_pos + 1));
                    }
                    current_statement_begin__ = 560;
                    stan::model::assign(beta, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                (stan::model::rvalue(beta, stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), "beta") * pow(get_base1(prior_scale, k, "prior_scale", 1), get_base1(num_normals, k, "num_normals", 1))), 
                                "assigning variable beta");
                    current_statement_begin__ = 561;
                    stan::model::assign(beta, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                (stan::model::rvalue(beta, stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), "beta") + get_base1(prior_mean, k, "prior_mean", 1)), 
                                "assigning variable beta");
                }
                }
            }
            current_statement_begin__ = 565;
            if (as_bool(K_smooth)) {

                current_statement_begin__ = 566;
                stan::math::assign(smooth_sd, add(prior_mean_for_smooth, elt_multiply(prior_scale_for_smooth, smooth_sd_raw)));
                current_statement_begin__ = 567;
                if (as_bool((primitive_value(is_continuous) && primitive_value(logical_eq(family, 1))))) {
                    current_statement_begin__ = 567;
                    stan::math::assign(smooth_sd, multiply(smooth_sd, aux));
                }
                current_statement_begin__ = 568;
                stan::math::assign(beta_smooth, elt_multiply(z_beta_smooth, stan::model::rvalue(smooth_sd, stan::model::cons_list(stan::model::index_multi(smooth_map), stan::model::nil_index_list()), "smooth_sd")));
            }
            current_statement_begin__ = 571;
            if (as_bool((primitive_value(logical_gt(family, 6)) && primitive_value((primitive_value(logical_eq(prior_dist_for_aux, 0)) || primitive_value(logical_lte(prior_scale_for_aux, 0))))))) {
                current_statement_begin__ = 572;
                stan::math::assign(aux, get_base1(aux_unscaled, 1, "aux_unscaled", 1));
            } else if (as_bool(logical_gt(family, 6))) {

                current_statement_begin__ = 574;
                stan::math::assign(aux, (prior_scale_for_aux * get_base1(aux_unscaled, 1, "aux_unscaled", 1)));
                current_statement_begin__ = 575;
                if (as_bool(logical_lte(prior_dist_for_aux, 2))) {
                    current_statement_begin__ = 576;
                    stan::math::assign(aux, (aux + prior_mean_for_aux));
                }
            }
            current_statement_begin__ = 579;
            if (as_bool(logical_gt(t, 0))) {

                current_statement_begin__ = 580;
                if (as_bool(logical_eq(special_case, 1))) {
                    {
                    current_statement_begin__ = 581;
                    int start(0);
                    (void) start;  // dummy to suppress unused var warning
                    stan::math::fill(start, std::numeric_limits<int>::min());
                    stan::math::assign(start,1);


                    current_statement_begin__ = 582;
                    stan::math::assign(theta_L, elt_multiply(scale, (logical_eq(family, 6) ? stan::math::promote_scalar<local_scalar_t__>(tau) : stan::math::promote_scalar<local_scalar_t__>(multiply(tau, aux)) )));
                    current_statement_begin__ = 583;
                    if (as_bool(logical_eq(t, 1))) {
                        current_statement_begin__ = 583;
                        stan::math::assign(b, multiply(get_base1(theta_L, 1, "theta_L", 1), z_b));
                    } else {
                        current_statement_begin__ = 584;
                        for (int i = 1; i <= t; ++i) {
                            {
                            current_statement_begin__ = 585;
                            int end(0);
                            (void) end;  // dummy to suppress unused var warning
                            stan::math::fill(end, std::numeric_limits<int>::min());
                            stan::math::assign(end,((start + get_base1(l, i, "l", 1)) - 1));


                            current_statement_begin__ = 586;
                            stan::model::assign(b, 
                                        stan::model::cons_list(stan::model::index_min_max(start, end), stan::model::nil_index_list()), 
                                        multiply(get_base1(theta_L, i, "theta_L", 1), stan::model::rvalue(z_b, stan::model::cons_list(stan::model::index_min_max(start, end), stan::model::nil_index_list()), "z_b")), 
                                        "assigning variable b");
                            current_statement_begin__ = 587;
                            stan::math::assign(start, (end + 1));
                            }
                        }
                    }
                    }
                } else {

                    current_statement_begin__ = 591;
                    if (as_bool(logical_eq(family, 6))) {
                        current_statement_begin__ = 592;
                        stan::math::assign(theta_L, make_theta_L(len_theta_L, p, 1.0, tau, scale, zeta, rho, z_T, pstream__));
                    } else {
                        current_statement_begin__ = 595;
                        stan::math::assign(theta_L, make_theta_L(len_theta_L, p, aux, tau, scale, zeta, rho, z_T, pstream__));
                    }
                    current_statement_begin__ = 597;
                    stan::math::assign(b, make_b(z_b, theta_L, p, l, pstream__));
                }
            }

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

            current_statement_begin__ = 523;
            if (stan::math::is_uninitialized(aux)) {
                std::stringstream msg__;
                msg__ << "Undefined transformed parameter: aux";
                stan::lang::rethrow_located(std::runtime_error(std::string("Error initializing variable aux: ") + msg__.str()), current_statement_begin__, prog_reader__());
            }
            current_statement_begin__ = 525;
            size_t beta_j_1_max__ = K;
            for (size_t j_1__ = 0; j_1__ < beta_j_1_max__; ++j_1__) {
                if (stan::math::is_uninitialized(beta(j_1__))) {
                    std::stringstream msg__;
                    msg__ << "Undefined transformed parameter: beta" << "(" << j_1__ << ")";
                    stan::lang::rethrow_located(std::runtime_error(std::string("Error initializing variable beta: ") + msg__.str()), current_statement_begin__, prog_reader__());
                }
            }
            current_statement_begin__ = 526;
            size_t beta_smooth_j_1_max__ = K_smooth;
            for (size_t j_1__ = 0; j_1__ < beta_smooth_j_1_max__; ++j_1__) {
                if (stan::math::is_uninitialized(beta_smooth(j_1__))) {
                    std::stringstream msg__;
                    msg__ << "Undefined transformed parameter: beta_smooth" << "(" << j_1__ << ")";
                    stan::lang::rethrow_located(std::runtime_error(std::string("Error initializing variable beta_smooth: ") + msg__.str()), current_statement_begin__, prog_reader__());
                }
            }
            current_statement_begin__ = 527;
            size_t smooth_sd_j_1_max__ = (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 );
            for (size_t j_1__ = 0; j_1__ < smooth_sd_j_1_max__; ++j_1__) {
                if (stan::math::is_uninitialized(smooth_sd(j_1__))) {
                    std::stringstream msg__;
                    msg__ << "Undefined transformed parameter: smooth_sd" << "(" << j_1__ << ")";
                    stan::lang::rethrow_located(std::runtime_error(std::string("Error initializing variable smooth_sd: ") + msg__.str()), current_statement_begin__, prog_reader__());
                }
            }
            current_statement_begin__ = 528;
            size_t b_j_1_max__ = q;
            for (size_t j_1__ = 0; j_1__ < b_j_1_max__; ++j_1__) {
                if (stan::math::is_uninitialized(b(j_1__))) {
                    std::stringstream msg__;
                    msg__ << "Undefined transformed parameter: b" << "(" << j_1__ << ")";
                    stan::lang::rethrow_located(std::runtime_error(std::string("Error initializing variable b: ") + msg__.str()), current_statement_begin__, prog_reader__());
                }
            }
            current_statement_begin__ = 529;
            size_t theta_L_j_1_max__ = len_theta_L;
            for (size_t j_1__ = 0; j_1__ < theta_L_j_1_max__; ++j_1__) {
                if (stan::math::is_uninitialized(theta_L(j_1__))) {
                    std::stringstream msg__;
                    msg__ << "Undefined transformed parameter: theta_L" << "(" << j_1__ << ")";
                    stan::lang::rethrow_located(std::runtime_error(std::string("Error initializing variable theta_L: ") + msg__.str()), current_statement_begin__, prog_reader__());
                }
            }

            // model body

            current_statement_begin__ = 602;
            if (as_bool(can_do_countlogglm)) {
                {
                current_statement_begin__ = 603;
                validate_non_negative_index("coeff", "(K + K_smooth)", (K + K_smooth));
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> coeff((K + K_smooth));
                stan::math::initialize(coeff, DUMMY_VAR__);
                stan::math::fill(coeff, DUMMY_VAR__);
                stan::math::assign(coeff,(logical_gt(K_smooth, 0) ? stan::math::promote_scalar<local_scalar_t__>(append_row(beta, beta_smooth)) : stan::math::promote_scalar<local_scalar_t__>(beta) ));


                current_statement_begin__ = 604;
                if (as_bool(logical_neq(family, 7))) {

                    current_statement_begin__ = 605;
                    if (as_bool(has_offset)) {

                        current_statement_begin__ = 606;
                        lp_accum__.add(poisson_log_glm_log(y, XS, (has_intercept ? stan::math::promote_scalar<local_scalar_t__>(add(offset, get_base1(gamma, 1, "gamma", 1))) : stan::math::promote_scalar<local_scalar_t__>(offset) ), coeff));
                    } else {

                        current_statement_begin__ = 608;
                        lp_accum__.add(poisson_log_glm_log(y, XS, (has_intercept ? stan::math::promote_scalar<local_scalar_t__>(get_base1(gamma, 1, "gamma", 1)) : stan::math::promote_scalar<local_scalar_t__>(0.0) ), coeff));
                    }
                } else {

                    current_statement_begin__ = 611;
                    if (as_bool(has_offset)) {

                        current_statement_begin__ = 612;
                        lp_accum__.add(neg_binomial_2_log_glm_log(y, XS, (has_intercept ? stan::math::promote_scalar<local_scalar_t__>(add(offset, get_base1(gamma, 1, "gamma", 1))) : stan::math::promote_scalar<local_scalar_t__>(offset) ), coeff, aux));
                    } else {

                        current_statement_begin__ = 614;
                        lp_accum__.add(neg_binomial_2_log_glm_log(y, XS, (has_intercept ? stan::math::promote_scalar<local_scalar_t__>(get_base1(gamma, 1, "gamma", 1)) : stan::math::promote_scalar<local_scalar_t__>(0.0) ), coeff, aux));
                    }
                }
                }
            } else if (as_bool(logical_eq(prior_PD, 0))) {
                {
                current_statement_begin__ = 618;
                validate_non_negative_index("eta", "N", N);
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> eta(N);
                stan::math::initialize(eta, DUMMY_VAR__);
                stan::math::fill(eta, DUMMY_VAR__);


                current_statement_begin__ = 619;
                if (as_bool(logical_gt(K, 0))) {

                    current_statement_begin__ = 620;
                    if (as_bool(dense_X)) {
                        current_statement_begin__ = 620;
                        stan::math::assign(eta, multiply(get_base1(X, 1, "X", 1), beta));
                    } else {
                        current_statement_begin__ = 621;
                        stan::math::assign(eta, csr_matrix_times_vector2(N, K, w_X, v_X, u_X, beta, pstream__));
                    }
                } else {
                    current_statement_begin__ = 623;
                    stan::math::assign(eta, rep_vector(0.0, N));
                }
                current_statement_begin__ = 624;
                if (as_bool(logical_eq(has_offset, 1))) {
                    current_statement_begin__ = 624;
                    stan::math::assign(eta, add(eta, offset));
                }
                current_statement_begin__ = 625;
                if (as_bool(K_smooth)) {
                    current_statement_begin__ = 625;
                    stan::math::assign(eta, add(eta, multiply(S, beta_smooth)));
                }
                current_statement_begin__ = 626;
                if (as_bool(logical_gt(t, 0))) {

                    current_statement_begin__ = 627;
                    if (as_bool(special_case)) {
                        current_statement_begin__ = 627;
                        for (int i = 1; i <= t; ++i) {
                            current_statement_begin__ = 627;
                            stan::math::assign(eta, add(eta, stan::model::rvalue(b, stan::model::cons_list(stan::model::index_multi(get_base1(V, i, "V", 1)), stan::model::nil_index_list()), "b")));
                        }
                    } else {
                        current_statement_begin__ = 628;
                        stan::math::assign(eta, add(eta, csr_matrix_times_vector2(N, q, w, v, u, b, pstream__)));
                    }
                }
                current_statement_begin__ = 630;
                if (as_bool(logical_eq(has_intercept, 1))) {

                    current_statement_begin__ = 631;
                    if (as_bool(logical_eq(link, 1))) {
                        current_statement_begin__ = 631;
                        stan::math::assign(eta, add(eta, get_base1(gamma, 1, "gamma", 1)));
                    } else {
                        current_statement_begin__ = 632;
                        stan::math::assign(eta, add(eta, (get_base1(gamma, 1, "gamma", 1) - min(eta))));
                    }
                } else {

                    current_statement_begin__ = 636;
                    stan::math::assign(eta, add(eta, dot_product(xbar, beta)));
                }
                current_statement_begin__ = 639;
                if (as_bool(logical_eq(family, 8))) {

                    current_statement_begin__ = 640;
                    if (as_bool(logical_eq(link, 1))) {
                        current_statement_begin__ = 640;
                        stan::math::assign(eta, add(eta, add(stan::math::log(aux), stan::math::log(get_base1(noise, 1, "noise", 1)))));
                    } else if (as_bool(logical_eq(link, 2))) {

                        current_statement_begin__ = 642;
                        stan::math::assign(eta, multiply(eta, aux));
                        current_statement_begin__ = 643;
                        stan::math::assign(eta, elt_multiply(eta, get_base1(noise, 1, "noise", 1)));
                    } else {
                        current_statement_begin__ = 645;
                        stan::math::assign(eta, add(eta, add(stan::math::sqrt(aux), stan::math::sqrt(get_base1(noise, 1, "noise", 1)))));
                    }
                }
                current_statement_begin__ = 649;
                if (as_bool(logical_eq(has_weights, 0))) {

                    current_statement_begin__ = 650;
                    if (as_bool(logical_neq(family, 7))) {

                        current_statement_begin__ = 651;
                        if (as_bool(logical_eq(link, 1))) {
                            current_statement_begin__ = 651;
                            lp_accum__.add(poisson_log_log(y, eta));
                        } else {
                            current_statement_begin__ = 652;
                            lp_accum__.add(poisson_log(y, linkinv_count(eta, link, pstream__)));
                        }
                    } else {

                        current_statement_begin__ = 655;
                        if (as_bool(logical_eq(link, 1))) {
                            current_statement_begin__ = 655;
                            lp_accum__.add(neg_binomial_2_log_log(y, eta, aux));
                        } else {
                            current_statement_begin__ = 656;
                            lp_accum__.add(neg_binomial_2_log(y, linkinv_count(eta, link, pstream__), aux));
                        }
                    }
                } else if (as_bool(logical_neq(family, 7))) {
                    current_statement_begin__ = 660;
                    lp_accum__.add(dot_product(weights, pw_pois(y, eta, link, pstream__)));
                } else {
                    current_statement_begin__ = 662;
                    lp_accum__.add(dot_product(weights, pw_nb(y, eta, aux, link, pstream__)));
                }
                }
            }
            current_statement_begin__ = 666;
            if (as_bool((primitive_value((primitive_value(logical_gt(family, 6)) && primitive_value(logical_gt(prior_dist_for_aux, 0)))) && primitive_value(logical_gt(prior_scale_for_aux, 0))))) {
                {
                current_statement_begin__ = 668;
                local_scalar_t__ log_half(DUMMY_VAR__);
                (void) log_half;  // dummy to suppress unused var warning
                stan::math::initialize(log_half, DUMMY_VAR__);
                stan::math::fill(log_half, DUMMY_VAR__);
                stan::math::assign(log_half,-(0.693147180559945286));


                current_statement_begin__ = 669;
                if (as_bool(logical_eq(prior_dist_for_aux, 1))) {
                    current_statement_begin__ = 670;
                    lp_accum__.add((normal_log(aux_unscaled, 0, 1) - log_half));
                } else if (as_bool(logical_eq(prior_dist_for_aux, 2))) {
                    current_statement_begin__ = 672;
                    lp_accum__.add((student_t_log(aux_unscaled, prior_df_for_aux, 0, 1) - log_half));
                } else {
                    current_statement_begin__ = 674;
                    lp_accum__.add(exponential_log(aux_unscaled, 1));
                }
                }
            }
            current_statement_begin__ = 678;
            if (as_bool(logical_eq(prior_dist, 1))) {
                current_statement_begin__ = 678;
                lp_accum__.add(normal_log(z_beta, 0, 1));
            } else if (as_bool(logical_eq(prior_dist, 2))) {
                current_statement_begin__ = 679;
                lp_accum__.add(normal_log(z_beta, 0, 1));
            } else if (as_bool(logical_eq(prior_dist, 3))) {
                {
                current_statement_begin__ = 681;
                local_scalar_t__ log_half(DUMMY_VAR__);
                (void) log_half;  // dummy to suppress unused var warning
                stan::math::initialize(log_half, DUMMY_VAR__);
                stan::math::fill(log_half, DUMMY_VAR__);
                stan::math::assign(log_half,-(0.693147180559945286));


                current_statement_begin__ = 682;
                lp_accum__.add(normal_log(z_beta, 0, 1));
                current_statement_begin__ = 683;
                lp_accum__.add((normal_log(get_base1(local, 1, "local", 1), 0, 1) - log_half));
                current_statement_begin__ = 684;
                lp_accum__.add(inv_gamma_log(get_base1(local, 2, "local", 1), multiply(0.5, prior_df), multiply(0.5, prior_df)));
                current_statement_begin__ = 685;
                lp_accum__.add((normal_log(get_base1(global, 1, "global", 1), 0, 1) - log_half));
                current_statement_begin__ = 686;
                lp_accum__.add(inv_gamma_log(get_base1(global, 2, "global", 1), (0.5 * global_prior_df), (0.5 * global_prior_df)));
                current_statement_begin__ = 687;
                lp_accum__.add(inv_gamma_log(caux, (0.5 * slab_df), (0.5 * slab_df)));
                }
            } else if (as_bool(logical_eq(prior_dist, 4))) {
                {
                current_statement_begin__ = 690;
                local_scalar_t__ log_half(DUMMY_VAR__);
                (void) log_half;  // dummy to suppress unused var warning
                stan::math::initialize(log_half, DUMMY_VAR__);
                stan::math::fill(log_half, DUMMY_VAR__);
                stan::math::assign(log_half,-(0.693147180559945286));


                current_statement_begin__ = 691;
                lp_accum__.add(normal_log(z_beta, 0, 1));
                current_statement_begin__ = 692;
                lp_accum__.add((normal_log(get_base1(local, 1, "local", 1), 0, 1) - log_half));
                current_statement_begin__ = 693;
                lp_accum__.add(inv_gamma_log(get_base1(local, 2, "local", 1), multiply(0.5, prior_df), multiply(0.5, prior_df)));
                current_statement_begin__ = 694;
                lp_accum__.add((normal_log(get_base1(local, 3, "local", 1), 0, 1) - log_half));
                current_statement_begin__ = 696;
                lp_accum__.add(inv_gamma_log(get_base1(local, 4, "local", 1), multiply(0.5, prior_scale), multiply(0.5, prior_scale)));
                current_statement_begin__ = 697;
                lp_accum__.add((normal_log(get_base1(global, 1, "global", 1), 0, 1) - log_half));
                current_statement_begin__ = 698;
                lp_accum__.add(inv_gamma_log(get_base1(global, 2, "global", 1), (0.5 * global_prior_df), (0.5 * global_prior_df)));
                current_statement_begin__ = 699;
                lp_accum__.add(inv_gamma_log(caux, (0.5 * slab_df), (0.5 * slab_df)));
                }
            } else if (as_bool(logical_eq(prior_dist, 5))) {

                current_statement_begin__ = 702;
                lp_accum__.add(normal_log(z_beta, 0, 1));
                current_statement_begin__ = 703;
                lp_accum__.add(exponential_log(get_base1(mix, 1, "mix", 1), 1));
            } else if (as_bool(logical_eq(prior_dist, 6))) {

                current_statement_begin__ = 706;
                lp_accum__.add(normal_log(z_beta, 0, 1));
                current_statement_begin__ = 707;
                lp_accum__.add(exponential_log(get_base1(mix, 1, "mix", 1), 1));
                current_statement_begin__ = 708;
                lp_accum__.add(chi_square_log(get_base1(one_over_lambda, 1, "one_over_lambda", 1), get_base1(prior_df, 1, "prior_df", 1)));
            } else if (as_bool(logical_eq(prior_dist, 7))) {

                current_statement_begin__ = 711;
                lp_accum__.add(normal_log(z_beta, 0, 1));
            }
            current_statement_begin__ = 716;
            if (as_bool(logical_eq(has_intercept, 1))) {

                current_statement_begin__ = 717;
                if (as_bool(logical_eq(prior_dist_for_intercept, 1))) {
                    current_statement_begin__ = 718;
                    lp_accum__.add(normal_log(gamma, prior_mean_for_intercept, prior_scale_for_intercept));
                } else if (as_bool(logical_eq(prior_dist_for_intercept, 2))) {
                    current_statement_begin__ = 720;
                    lp_accum__.add(student_t_log(gamma, prior_df_for_intercept, prior_mean_for_intercept, prior_scale_for_intercept));
                }
            }
            current_statement_begin__ = 725;
            if (as_bool(K_smooth)) {

                current_statement_begin__ = 726;
                lp_accum__.add(normal_log(z_beta_smooth, 0, 1));
                current_statement_begin__ = 727;
                if (as_bool(logical_gt(prior_dist_for_smooth, 0))) {
                    {
                    current_statement_begin__ = 728;
                    local_scalar_t__ log_half(DUMMY_VAR__);
                    (void) log_half;  // dummy to suppress unused var warning
                    stan::math::initialize(log_half, DUMMY_VAR__);
                    stan::math::fill(log_half, DUMMY_VAR__);
                    stan::math::assign(log_half,-(0.693147180559945286));


                    current_statement_begin__ = 729;
                    if (as_bool(logical_eq(prior_dist_for_smooth, 1))) {
                        current_statement_begin__ = 730;
                        lp_accum__.add((normal_log(smooth_sd_raw, 0, 1) - log_half));
                    } else if (as_bool(logical_eq(prior_dist_for_smooth, 2))) {
                        current_statement_begin__ = 732;
                        lp_accum__.add((student_t_log(smooth_sd_raw, prior_df_for_smooth, 0, 1) - log_half));
                    } else if (as_bool(logical_eq(prior_dist_for_smooth, 3))) {
                        current_statement_begin__ = 734;
                        lp_accum__.add(exponential_log(smooth_sd_raw, 1));
                    }
                    }
                }
            }
            current_statement_begin__ = 739;
            if (as_bool(logical_eq(family, 8))) {
                current_statement_begin__ = 739;
                lp_accum__.add(gamma_log(get_base1(noise, 1, "noise", 1), aux, 1));
            }
            current_statement_begin__ = 741;
            if (as_bool(logical_gt(t, 0))) {
                {
                current_statement_begin__ = 742;
                local_scalar_t__ dummy(DUMMY_VAR__);
                (void) dummy;  // dummy to suppress unused var warning
                stan::math::initialize(dummy, DUMMY_VAR__);
                stan::math::fill(dummy, DUMMY_VAR__);
                stan::math::assign(dummy,decov_lp(z_b, z_T, rho, zeta, tau, regularization, delta, shape, t, p, lp__, lp_accum__, 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 ***");
        }

        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("gamma");
        names__.push_back("z_beta");
        names__.push_back("z_beta_smooth");
        names__.push_back("smooth_sd_raw");
        names__.push_back("global");
        names__.push_back("local");
        names__.push_back("caux");
        names__.push_back("mix");
        names__.push_back("one_over_lambda");
        names__.push_back("z_b");
        names__.push_back("z_T");
        names__.push_back("rho");
        names__.push_back("zeta");
        names__.push_back("tau");
        names__.push_back("aux_unscaled");
        names__.push_back("noise");
        names__.push_back("aux");
        names__.push_back("beta");
        names__.push_back("beta_smooth");
        names__.push_back("smooth_sd");
        names__.push_back("b");
        names__.push_back("theta_L");
        names__.push_back("mean_PPD");
        names__.push_back("alpha");
    }


    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(has_intercept);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back((logical_eq(prior_dist, 7) ? sum(num_normals) : K ));
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(K_smooth);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back((logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 ));
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(hs);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(hs);
        dims__.push_back(K);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(logical_gt(hs, 0));
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back((primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6))));
        dims__.push_back(K);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(logical_eq(prior_dist, 6));
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(q);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(len_z_T);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(len_rho);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(len_concentration);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(t);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(logical_gt(family, 6));
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(logical_eq(family, 8));
        dims__.push_back(N);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(K);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(K_smooth);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back((logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 ));
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(q);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(len_theta_L);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(has_intercept);
        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__ = "model_count_namespace::write_array";
        (void) function__;  // dummy to suppress unused var warning

        // read-transform, write parameters
        std::vector<double> gamma;
        size_t gamma_d_0_max__ = has_intercept;
        gamma.reserve(gamma_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < gamma_d_0_max__; ++d_0__) {
            gamma.push_back(in__.scalar_lb_constrain((logical_eq(link, 1) ? stan::math::negative_infinity() : 0.0 )));
        }
        size_t gamma_k_0_max__ = has_intercept;
        for (size_t k_0__ = 0; k_0__ < gamma_k_0_max__; ++k_0__) {
            vars__.push_back(gamma[k_0__]);
        }

        Eigen::Matrix<double, Eigen::Dynamic, 1> z_beta = in__.vector_constrain((logical_eq(prior_dist, 7) ? sum(num_normals) : K ));
        size_t z_beta_j_1_max__ = (logical_eq(prior_dist, 7) ? sum(num_normals) : K );
        for (size_t j_1__ = 0; j_1__ < z_beta_j_1_max__; ++j_1__) {
            vars__.push_back(z_beta(j_1__));
        }

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

        Eigen::Matrix<double, Eigen::Dynamic, 1> smooth_sd_raw = in__.vector_lb_constrain(0, (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 ));
        size_t smooth_sd_raw_j_1_max__ = (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 );
        for (size_t j_1__ = 0; j_1__ < smooth_sd_raw_j_1_max__; ++j_1__) {
            vars__.push_back(smooth_sd_raw(j_1__));
        }

        std::vector<double> global;
        size_t global_d_0_max__ = hs;
        global.reserve(global_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < global_d_0_max__; ++d_0__) {
            global.push_back(in__.scalar_lb_constrain(0));
        }
        size_t global_k_0_max__ = hs;
        for (size_t k_0__ = 0; k_0__ < global_k_0_max__; ++k_0__) {
            vars__.push_back(global[k_0__]);
        }

        std::vector<Eigen::Matrix<double, Eigen::Dynamic, 1> > local;
        size_t local_d_0_max__ = hs;
        local.reserve(local_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < local_d_0_max__; ++d_0__) {
            local.push_back(in__.vector_lb_constrain(0, K));
        }
        size_t local_j_1_max__ = K;
        size_t local_k_0_max__ = hs;
        for (size_t j_1__ = 0; j_1__ < local_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < local_k_0_max__; ++k_0__) {
                vars__.push_back(local[k_0__](j_1__));
            }
        }

        std::vector<double> caux;
        size_t caux_d_0_max__ = logical_gt(hs, 0);
        caux.reserve(caux_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < caux_d_0_max__; ++d_0__) {
            caux.push_back(in__.scalar_lb_constrain(0));
        }
        size_t caux_k_0_max__ = logical_gt(hs, 0);
        for (size_t k_0__ = 0; k_0__ < caux_k_0_max__; ++k_0__) {
            vars__.push_back(caux[k_0__]);
        }

        std::vector<Eigen::Matrix<double, Eigen::Dynamic, 1> > mix;
        size_t mix_d_0_max__ = (primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6)));
        mix.reserve(mix_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < mix_d_0_max__; ++d_0__) {
            mix.push_back(in__.vector_lb_constrain(0, K));
        }
        size_t mix_j_1_max__ = K;
        size_t mix_k_0_max__ = (primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6)));
        for (size_t j_1__ = 0; j_1__ < mix_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < mix_k_0_max__; ++k_0__) {
                vars__.push_back(mix[k_0__](j_1__));
            }
        }

        std::vector<double> one_over_lambda;
        size_t one_over_lambda_d_0_max__ = logical_eq(prior_dist, 6);
        one_over_lambda.reserve(one_over_lambda_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < one_over_lambda_d_0_max__; ++d_0__) {
            one_over_lambda.push_back(in__.scalar_lb_constrain(0));
        }
        size_t one_over_lambda_k_0_max__ = logical_eq(prior_dist, 6);
        for (size_t k_0__ = 0; k_0__ < one_over_lambda_k_0_max__; ++k_0__) {
            vars__.push_back(one_over_lambda[k_0__]);
        }

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

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

        Eigen::Matrix<double, Eigen::Dynamic, 1> rho = in__.vector_lub_constrain(0, 1, len_rho);
        size_t rho_j_1_max__ = len_rho;
        for (size_t j_1__ = 0; j_1__ < rho_j_1_max__; ++j_1__) {
            vars__.push_back(rho(j_1__));
        }

        Eigen::Matrix<double, Eigen::Dynamic, 1> zeta = in__.vector_lb_constrain(0, len_concentration);
        size_t zeta_j_1_max__ = len_concentration;
        for (size_t j_1__ = 0; j_1__ < zeta_j_1_max__; ++j_1__) {
            vars__.push_back(zeta(j_1__));
        }

        Eigen::Matrix<double, Eigen::Dynamic, 1> tau = in__.vector_lb_constrain(0, t);
        size_t tau_j_1_max__ = t;
        for (size_t j_1__ = 0; j_1__ < tau_j_1_max__; ++j_1__) {
            vars__.push_back(tau(j_1__));
        }

        std::vector<double> aux_unscaled;
        size_t aux_unscaled_d_0_max__ = logical_gt(family, 6);
        aux_unscaled.reserve(aux_unscaled_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < aux_unscaled_d_0_max__; ++d_0__) {
            aux_unscaled.push_back(in__.scalar_lb_constrain(0));
        }
        size_t aux_unscaled_k_0_max__ = logical_gt(family, 6);
        for (size_t k_0__ = 0; k_0__ < aux_unscaled_k_0_max__; ++k_0__) {
            vars__.push_back(aux_unscaled[k_0__]);
        }

        std::vector<Eigen::Matrix<double, Eigen::Dynamic, 1> > noise;
        size_t noise_d_0_max__ = logical_eq(family, 8);
        noise.reserve(noise_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < noise_d_0_max__; ++d_0__) {
            noise.push_back(in__.vector_lb_constrain(0, N));
        }
        size_t noise_j_1_max__ = N;
        size_t noise_k_0_max__ = logical_eq(family, 8);
        for (size_t j_1__ = 0; j_1__ < noise_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < noise_k_0_max__; ++k_0__) {
                vars__.push_back(noise[k_0__](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__ = 523;
            double aux;
            (void) aux;  // dummy to suppress unused var warning
            stan::math::initialize(aux, DUMMY_VAR__);
            stan::math::fill(aux, DUMMY_VAR__);
            stan::math::assign(aux,stan::math::negative_infinity());

            current_statement_begin__ = 525;
            validate_non_negative_index("beta", "K", K);
            Eigen::Matrix<double, Eigen::Dynamic, 1> beta(K);
            stan::math::initialize(beta, DUMMY_VAR__);
            stan::math::fill(beta, DUMMY_VAR__);

            current_statement_begin__ = 526;
            validate_non_negative_index("beta_smooth", "K_smooth", K_smooth);
            Eigen::Matrix<double, Eigen::Dynamic, 1> beta_smooth(K_smooth);
            stan::math::initialize(beta_smooth, DUMMY_VAR__);
            stan::math::fill(beta_smooth, DUMMY_VAR__);

            current_statement_begin__ = 527;
            validate_non_negative_index("smooth_sd", "(logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, \"smooth_map\", 1) : 0 )", (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 ));
            Eigen::Matrix<double, Eigen::Dynamic, 1> smooth_sd((logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 ));
            stan::math::initialize(smooth_sd, DUMMY_VAR__);
            stan::math::fill(smooth_sd, DUMMY_VAR__);

            current_statement_begin__ = 528;
            validate_non_negative_index("b", "q", q);
            Eigen::Matrix<double, Eigen::Dynamic, 1> b(q);
            stan::math::initialize(b, DUMMY_VAR__);
            stan::math::fill(b, DUMMY_VAR__);

            current_statement_begin__ = 529;
            validate_non_negative_index("theta_L", "len_theta_L", len_theta_L);
            Eigen::Matrix<double, Eigen::Dynamic, 1> theta_L(len_theta_L);
            stan::math::initialize(theta_L, DUMMY_VAR__);
            stan::math::fill(theta_L, DUMMY_VAR__);

            // do transformed parameters statements
            current_statement_begin__ = 530;
            if (as_bool(logical_eq(prior_dist, 0))) {
                current_statement_begin__ = 530;
                stan::math::assign(beta, z_beta);
            } else if (as_bool(logical_eq(prior_dist, 1))) {
                current_statement_begin__ = 531;
                stan::math::assign(beta, add(elt_multiply(z_beta, prior_scale), prior_mean));
            } else if (as_bool(logical_eq(prior_dist, 2))) {
                current_statement_begin__ = 532;
                for (int k = 1; k <= K; ++k) {

                    current_statement_begin__ = 533;
                    stan::model::assign(beta, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                ((CFt(get_base1(z_beta, k, "z_beta", 1), get_base1(prior_df, k, "prior_df", 1), pstream__) * get_base1(prior_scale, k, "prior_scale", 1)) + get_base1(prior_mean, k, "prior_mean", 1)), 
                                "assigning variable beta");
                }
            } else if (as_bool(logical_eq(prior_dist, 3))) {
                {
                current_statement_begin__ = 536;
                local_scalar_t__ c2(DUMMY_VAR__);
                (void) c2;  // dummy to suppress unused var warning
                stan::math::initialize(c2, DUMMY_VAR__);
                stan::math::fill(c2, DUMMY_VAR__);
                stan::math::assign(c2,(square(slab_scale) * get_base1(caux, 1, "caux", 1)));


                current_statement_begin__ = 537;
                if (as_bool((primitive_value(logical_eq(is_continuous, 1)) && primitive_value(logical_eq(family, 1))))) {
                    current_statement_begin__ = 538;
                    stan::math::assign(beta, hs_prior(z_beta, global, local, global_prior_scale, aux, c2, pstream__));
                } else {
                    current_statement_begin__ = 539;
                    stan::math::assign(beta, hs_prior(z_beta, global, local, global_prior_scale, 1, c2, pstream__));
                }
                }
            } else if (as_bool(logical_eq(prior_dist, 4))) {
                {
                current_statement_begin__ = 542;
                local_scalar_t__ c2(DUMMY_VAR__);
                (void) c2;  // dummy to suppress unused var warning
                stan::math::initialize(c2, DUMMY_VAR__);
                stan::math::fill(c2, DUMMY_VAR__);
                stan::math::assign(c2,(square(slab_scale) * get_base1(caux, 1, "caux", 1)));


                current_statement_begin__ = 543;
                if (as_bool((primitive_value(logical_eq(is_continuous, 1)) && primitive_value(logical_eq(family, 1))))) {
                    current_statement_begin__ = 544;
                    stan::math::assign(beta, hsplus_prior(z_beta, global, local, global_prior_scale, aux, c2, pstream__));
                } else {
                    current_statement_begin__ = 545;
                    stan::math::assign(beta, hsplus_prior(z_beta, global, local, global_prior_scale, 1, c2, pstream__));
                }
                }
            } else if (as_bool(logical_eq(prior_dist, 5))) {
                current_statement_begin__ = 548;
                stan::math::assign(beta, add(prior_mean, elt_multiply(elt_multiply(prior_scale, stan::math::sqrt(multiply(2, get_base1(mix, 1, "mix", 1)))), z_beta)));
            } else if (as_bool(logical_eq(prior_dist, 6))) {
                current_statement_begin__ = 550;
                stan::math::assign(beta, add(prior_mean, elt_multiply(elt_multiply(multiply(get_base1(one_over_lambda, 1, "one_over_lambda", 1), prior_scale), stan::math::sqrt(multiply(2, get_base1(mix, 1, "mix", 1)))), z_beta)));
            } else if (as_bool(logical_eq(prior_dist, 7))) {
                {
                current_statement_begin__ = 552;
                int z_pos(0);
                (void) z_pos;  // dummy to suppress unused var warning
                stan::math::fill(z_pos, std::numeric_limits<int>::min());
                stan::math::assign(z_pos,1);


                current_statement_begin__ = 553;
                for (int k = 1; k <= K; ++k) {

                    current_statement_begin__ = 554;
                    stan::model::assign(beta, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                get_base1(z_beta, z_pos, "z_beta", 1), 
                                "assigning variable beta");
                    current_statement_begin__ = 555;
                    stan::math::assign(z_pos, (z_pos + 1));
                    current_statement_begin__ = 556;
                    for (int n = 2; n <= get_base1(num_normals, k, "num_normals", 1); ++n) {

                        current_statement_begin__ = 557;
                        stan::model::assign(beta, 
                                    stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                    (stan::model::rvalue(beta, stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), "beta") * get_base1(z_beta, z_pos, "z_beta", 1)), 
                                    "assigning variable beta");
                        current_statement_begin__ = 558;
                        stan::math::assign(z_pos, (z_pos + 1));
                    }
                    current_statement_begin__ = 560;
                    stan::model::assign(beta, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                (stan::model::rvalue(beta, stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), "beta") * pow(get_base1(prior_scale, k, "prior_scale", 1), get_base1(num_normals, k, "num_normals", 1))), 
                                "assigning variable beta");
                    current_statement_begin__ = 561;
                    stan::model::assign(beta, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                (stan::model::rvalue(beta, stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), "beta") + get_base1(prior_mean, k, "prior_mean", 1)), 
                                "assigning variable beta");
                }
                }
            }
            current_statement_begin__ = 565;
            if (as_bool(K_smooth)) {

                current_statement_begin__ = 566;
                stan::math::assign(smooth_sd, add(prior_mean_for_smooth, elt_multiply(prior_scale_for_smooth, smooth_sd_raw)));
                current_statement_begin__ = 567;
                if (as_bool((primitive_value(is_continuous) && primitive_value(logical_eq(family, 1))))) {
                    current_statement_begin__ = 567;
                    stan::math::assign(smooth_sd, multiply(smooth_sd, aux));
                }
                current_statement_begin__ = 568;
                stan::math::assign(beta_smooth, elt_multiply(z_beta_smooth, stan::model::rvalue(smooth_sd, stan::model::cons_list(stan::model::index_multi(smooth_map), stan::model::nil_index_list()), "smooth_sd")));
            }
            current_statement_begin__ = 571;
            if (as_bool((primitive_value(logical_gt(family, 6)) && primitive_value((primitive_value(logical_eq(prior_dist_for_aux, 0)) || primitive_value(logical_lte(prior_scale_for_aux, 0))))))) {
                current_statement_begin__ = 572;
                stan::math::assign(aux, get_base1(aux_unscaled, 1, "aux_unscaled", 1));
            } else if (as_bool(logical_gt(family, 6))) {

                current_statement_begin__ = 574;
                stan::math::assign(aux, (prior_scale_for_aux * get_base1(aux_unscaled, 1, "aux_unscaled", 1)));
                current_statement_begin__ = 575;
                if (as_bool(logical_lte(prior_dist_for_aux, 2))) {
                    current_statement_begin__ = 576;
                    stan::math::assign(aux, (aux + prior_mean_for_aux));
                }
            }
            current_statement_begin__ = 579;
            if (as_bool(logical_gt(t, 0))) {

                current_statement_begin__ = 580;
                if (as_bool(logical_eq(special_case, 1))) {
                    {
                    current_statement_begin__ = 581;
                    int start(0);
                    (void) start;  // dummy to suppress unused var warning
                    stan::math::fill(start, std::numeric_limits<int>::min());
                    stan::math::assign(start,1);


                    current_statement_begin__ = 582;
                    stan::math::assign(theta_L, elt_multiply(scale, (logical_eq(family, 6) ? stan::math::promote_scalar<local_scalar_t__>(tau) : stan::math::promote_scalar<local_scalar_t__>(multiply(tau, aux)) )));
                    current_statement_begin__ = 583;
                    if (as_bool(logical_eq(t, 1))) {
                        current_statement_begin__ = 583;
                        stan::math::assign(b, multiply(get_base1(theta_L, 1, "theta_L", 1), z_b));
                    } else {
                        current_statement_begin__ = 584;
                        for (int i = 1; i <= t; ++i) {
                            {
                            current_statement_begin__ = 585;
                            int end(0);
                            (void) end;  // dummy to suppress unused var warning
                            stan::math::fill(end, std::numeric_limits<int>::min());
                            stan::math::assign(end,((start + get_base1(l, i, "l", 1)) - 1));


                            current_statement_begin__ = 586;
                            stan::model::assign(b, 
                                        stan::model::cons_list(stan::model::index_min_max(start, end), stan::model::nil_index_list()), 
                                        multiply(get_base1(theta_L, i, "theta_L", 1), stan::model::rvalue(z_b, stan::model::cons_list(stan::model::index_min_max(start, end), stan::model::nil_index_list()), "z_b")), 
                                        "assigning variable b");
                            current_statement_begin__ = 587;
                            stan::math::assign(start, (end + 1));
                            }
                        }
                    }
                    }
                } else {

                    current_statement_begin__ = 591;
                    if (as_bool(logical_eq(family, 6))) {
                        current_statement_begin__ = 592;
                        stan::math::assign(theta_L, make_theta_L(len_theta_L, p, 1.0, tau, scale, zeta, rho, z_T, pstream__));
                    } else {
                        current_statement_begin__ = 595;
                        stan::math::assign(theta_L, make_theta_L(len_theta_L, p, aux, tau, scale, zeta, rho, z_T, pstream__));
                    }
                    current_statement_begin__ = 597;
                    stan::math::assign(b, make_b(z_b, theta_L, p, l, pstream__));
                }
            }

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

            // write transformed parameters
            if (include_tparams__) {
                vars__.push_back(aux);
                size_t beta_j_1_max__ = K;
                for (size_t j_1__ = 0; j_1__ < beta_j_1_max__; ++j_1__) {
                    vars__.push_back(beta(j_1__));
                }
                size_t beta_smooth_j_1_max__ = K_smooth;
                for (size_t j_1__ = 0; j_1__ < beta_smooth_j_1_max__; ++j_1__) {
                    vars__.push_back(beta_smooth(j_1__));
                }
                size_t smooth_sd_j_1_max__ = (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 );
                for (size_t j_1__ = 0; j_1__ < smooth_sd_j_1_max__; ++j_1__) {
                    vars__.push_back(smooth_sd(j_1__));
                }
                size_t b_j_1_max__ = q;
                for (size_t j_1__ = 0; j_1__ < b_j_1_max__; ++j_1__) {
                    vars__.push_back(b(j_1__));
                }
                size_t theta_L_j_1_max__ = len_theta_L;
                for (size_t j_1__ = 0; j_1__ < theta_L_j_1_max__; ++j_1__) {
                    vars__.push_back(theta_L(j_1__));
                }
            }
            if (!include_gqs__) return;
            // declare and define generated quantities
            current_statement_begin__ = 747;
            double mean_PPD;
            (void) mean_PPD;  // dummy to suppress unused var warning
            stan::math::initialize(mean_PPD, DUMMY_VAR__);
            stan::math::fill(mean_PPD, DUMMY_VAR__);
            stan::math::assign(mean_PPD,(compute_mean_PPD ? stan::math::promote_scalar<double>(0) : stan::math::promote_scalar<double>(stan::math::negative_infinity()) ));

            current_statement_begin__ = 748;
            validate_non_negative_index("alpha", "has_intercept", has_intercept);
            std::vector<double> alpha(has_intercept, double(0));
            stan::math::initialize(alpha, DUMMY_VAR__);
            stan::math::fill(alpha, DUMMY_VAR__);

            // generated quantities statements
            current_statement_begin__ = 750;
            if (as_bool(logical_eq(has_intercept, 1))) {

                current_statement_begin__ = 751;
                if (as_bool(dense_X)) {
                    current_statement_begin__ = 751;
                    stan::model::assign(alpha, 
                                stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list()), 
                                (get_base1(gamma, 1, "gamma", 1) - dot_product(xbar, beta)), 
                                "assigning variable alpha");
                } else {
                    current_statement_begin__ = 752;
                    stan::model::assign(alpha, 
                                stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list()), 
                                get_base1(gamma, 1, "gamma", 1), 
                                "assigning variable alpha");
                }
            }
            current_statement_begin__ = 755;
            if (as_bool(compute_mean_PPD)) {
                {
                current_statement_begin__ = 756;
                validate_non_negative_index("nu", "N", N);
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> nu(N);
                stan::math::initialize(nu, DUMMY_VAR__);
                stan::math::fill(nu, DUMMY_VAR__);

                current_statement_begin__ = 757;
                validate_non_negative_index("eta", "N", N);
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> eta(N);
                stan::math::initialize(eta, DUMMY_VAR__);
                stan::math::fill(eta, DUMMY_VAR__);


                current_statement_begin__ = 758;
                if (as_bool(logical_gt(K, 0))) {

                    current_statement_begin__ = 759;
                    if (as_bool(dense_X)) {
                        current_statement_begin__ = 759;
                        stan::math::assign(eta, multiply(get_base1(X, 1, "X", 1), beta));
                    } else {
                        current_statement_begin__ = 760;
                        stan::math::assign(eta, csr_matrix_times_vector2(N, K, w_X, v_X, u_X, beta, pstream__));
                    }
                } else {
                    current_statement_begin__ = 762;
                    stan::math::assign(eta, rep_vector(0.0, N));
                }
                current_statement_begin__ = 763;
                if (as_bool(logical_eq(has_offset, 1))) {
                    current_statement_begin__ = 763;
                    stan::math::assign(eta, add(eta, offset));
                }
                current_statement_begin__ = 764;
                if (as_bool(K_smooth)) {
                    current_statement_begin__ = 764;
                    stan::math::assign(eta, add(eta, multiply(S, beta_smooth)));
                }
                current_statement_begin__ = 765;
                if (as_bool(logical_gt(t, 0))) {

                    current_statement_begin__ = 766;
                    if (as_bool(special_case)) {
                        current_statement_begin__ = 766;
                        for (int i = 1; i <= t; ++i) {
                            current_statement_begin__ = 766;
                            stan::math::assign(eta, add(eta, stan::model::rvalue(b, stan::model::cons_list(stan::model::index_multi(get_base1(V, i, "V", 1)), stan::model::nil_index_list()), "b")));
                        }
                    } else {
                        current_statement_begin__ = 767;
                        stan::math::assign(eta, add(eta, csr_matrix_times_vector2(N, q, w, v, u, b, pstream__)));
                    }
                }
                current_statement_begin__ = 769;
                if (as_bool(logical_eq(has_intercept, 1))) {

                    current_statement_begin__ = 770;
                    if (as_bool(logical_eq(link, 1))) {
                        current_statement_begin__ = 770;
                        stan::math::assign(eta, add(eta, get_base1(gamma, 1, "gamma", 1)));
                    } else {
                        {
                        current_statement_begin__ = 772;
                        local_scalar_t__ shift(DUMMY_VAR__);
                        (void) shift;  // dummy to suppress unused var warning
                        stan::math::initialize(shift, DUMMY_VAR__);
                        stan::math::fill(shift, DUMMY_VAR__);
                        stan::math::assign(shift,min(eta));


                        current_statement_begin__ = 773;
                        stan::math::assign(eta, add(eta, (get_base1(gamma, 1, "gamma", 1) - shift)));
                        current_statement_begin__ = 774;
                        stan::model::assign(alpha, 
                                    stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list()), 
                                    (stan::model::rvalue(alpha, stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list()), "alpha") - shift), 
                                    "assigning variable alpha");
                        }
                    }
                } else {

                    current_statement_begin__ = 779;
                    stan::math::assign(eta, add(eta, dot_product(xbar, beta)));
                }
                current_statement_begin__ = 782;
                if (as_bool(logical_eq(family, 8))) {

                    current_statement_begin__ = 783;
                    if (as_bool(logical_eq(link, 1))) {
                        current_statement_begin__ = 783;
                        stan::math::assign(eta, add(eta, add(stan::math::log(aux), stan::math::log(get_base1(noise, 1, "noise", 1)))));
                    } else if (as_bool(logical_eq(link, 2))) {

                        current_statement_begin__ = 785;
                        stan::math::assign(eta, multiply(eta, aux));
                        current_statement_begin__ = 786;
                        stan::math::assign(eta, elt_multiply(eta, get_base1(noise, 1, "noise", 1)));
                    } else {
                        current_statement_begin__ = 788;
                        stan::math::assign(eta, add(eta, add(stan::math::sqrt(aux), stan::math::sqrt(get_base1(noise, 1, "noise", 1)))));
                    }
                }
                current_statement_begin__ = 790;
                stan::math::assign(nu, linkinv_count(eta, link, pstream__));
                current_statement_begin__ = 791;
                if (as_bool(logical_neq(family, 7))) {
                    current_statement_begin__ = 791;
                    for (int n = 1; n <= N; ++n) {

                        current_statement_begin__ = 792;
                        if (as_bool(logical_lt(get_base1(nu, n, "nu", 1), poisson_max))) {
                            current_statement_begin__ = 792;
                            stan::math::assign(mean_PPD, (mean_PPD + poisson_rng(get_base1(nu, n, "nu", 1), base_rng__)));
                        } else {
                            current_statement_begin__ = 793;
                            stan::math::assign(mean_PPD, (mean_PPD + normal_rng(get_base1(nu, n, "nu", 1), stan::math::sqrt(get_base1(nu, n, "nu", 1)), base_rng__)));
                        }
                    }
                } else {
                    current_statement_begin__ = 795;
                    for (int n = 1; n <= N; ++n) {
                        {
                        current_statement_begin__ = 796;
                        local_scalar_t__ gamma_temp(DUMMY_VAR__);
                        (void) gamma_temp;  // dummy to suppress unused var warning
                        stan::math::initialize(gamma_temp, DUMMY_VAR__);
                        stan::math::fill(gamma_temp, DUMMY_VAR__);


                        current_statement_begin__ = 797;
                        if (as_bool(is_inf(aux))) {
                            current_statement_begin__ = 797;
                            stan::math::assign(gamma_temp, get_base1(nu, n, "nu", 1));
                        } else {
                            current_statement_begin__ = 798;
                            stan::math::assign(gamma_temp, gamma_rng(aux, (aux / get_base1(nu, n, "nu", 1)), base_rng__));
                        }
                        current_statement_begin__ = 799;
                        if (as_bool(logical_lt(gamma_temp, poisson_max))) {
                            current_statement_begin__ = 800;
                            stan::math::assign(mean_PPD, (mean_PPD + poisson_rng(gamma_temp, base_rng__)));
                        } else {
                            current_statement_begin__ = 801;
                            stan::math::assign(mean_PPD, (mean_PPD + normal_rng(gamma_temp, stan::math::sqrt(gamma_temp), base_rng__)));
                        }
                        }
                    }
                }
                current_statement_begin__ = 803;
                stan::math::assign(mean_PPD, (mean_PPD / N));
                }
            }

            // validate, write generated quantities
            current_statement_begin__ = 747;
            vars__.push_back(mean_PPD);

            current_statement_begin__ = 748;
            size_t alpha_k_0_max__ = has_intercept;
            for (size_t k_0__ = 0; k_0__ < alpha_k_0_max__; ++k_0__) {
                vars__.push_back(alpha[k_0__]);
            }

        } 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];
    }

    static std::string model_name() {
        return "model_count";
    }


    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 gamma_k_0_max__ = has_intercept;
        for (size_t k_0__ = 0; k_0__ < gamma_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "gamma" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t z_beta_j_1_max__ = (logical_eq(prior_dist, 7) ? sum(num_normals) : K );
        for (size_t j_1__ = 0; j_1__ < z_beta_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "z_beta" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t z_beta_smooth_j_1_max__ = K_smooth;
        for (size_t j_1__ = 0; j_1__ < z_beta_smooth_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "z_beta_smooth" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t smooth_sd_raw_j_1_max__ = (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 );
        for (size_t j_1__ = 0; j_1__ < smooth_sd_raw_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "smooth_sd_raw" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t global_k_0_max__ = hs;
        for (size_t k_0__ = 0; k_0__ < global_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "global" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t local_j_1_max__ = K;
        size_t local_k_0_max__ = hs;
        for (size_t j_1__ = 0; j_1__ < local_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < local_k_0_max__; ++k_0__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "local" << '.' << k_0__ + 1 << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
        }
        size_t caux_k_0_max__ = logical_gt(hs, 0);
        for (size_t k_0__ = 0; k_0__ < caux_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "caux" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t mix_j_1_max__ = K;
        size_t mix_k_0_max__ = (primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6)));
        for (size_t j_1__ = 0; j_1__ < mix_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < mix_k_0_max__; ++k_0__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "mix" << '.' << k_0__ + 1 << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
        }
        size_t one_over_lambda_k_0_max__ = logical_eq(prior_dist, 6);
        for (size_t k_0__ = 0; k_0__ < one_over_lambda_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "one_over_lambda" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t z_b_j_1_max__ = q;
        for (size_t j_1__ = 0; j_1__ < z_b_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "z_b" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t z_T_j_1_max__ = len_z_T;
        for (size_t j_1__ = 0; j_1__ < z_T_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "z_T" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t rho_j_1_max__ = len_rho;
        for (size_t j_1__ = 0; j_1__ < rho_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "rho" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t zeta_j_1_max__ = len_concentration;
        for (size_t j_1__ = 0; j_1__ < zeta_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "zeta" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t tau_j_1_max__ = t;
        for (size_t j_1__ = 0; j_1__ < tau_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "tau" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t aux_unscaled_k_0_max__ = logical_gt(family, 6);
        for (size_t k_0__ = 0; k_0__ < aux_unscaled_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "aux_unscaled" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t noise_j_1_max__ = N;
        size_t noise_k_0_max__ = logical_eq(family, 8);
        for (size_t j_1__ = 0; j_1__ < noise_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < noise_k_0_max__; ++k_0__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "noise" << '.' << k_0__ + 1 << '.' << 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__ << "aux";
            param_names__.push_back(param_name_stream__.str());
            size_t beta_j_1_max__ = K;
            for (size_t j_1__ = 0; j_1__ < beta_j_1_max__; ++j_1__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "beta" << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
            size_t beta_smooth_j_1_max__ = K_smooth;
            for (size_t j_1__ = 0; j_1__ < beta_smooth_j_1_max__; ++j_1__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "beta_smooth" << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
            size_t smooth_sd_j_1_max__ = (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 );
            for (size_t j_1__ = 0; j_1__ < smooth_sd_j_1_max__; ++j_1__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "smooth_sd" << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
            size_t b_j_1_max__ = q;
            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 theta_L_j_1_max__ = len_theta_L;
            for (size_t j_1__ = 0; j_1__ < theta_L_j_1_max__; ++j_1__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "theta_L" << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
        }

        if (!include_gqs__) return;
        param_name_stream__.str(std::string());
        param_name_stream__ << "mean_PPD";
        param_names__.push_back(param_name_stream__.str());
        size_t alpha_k_0_max__ = has_intercept;
        for (size_t k_0__ = 0; k_0__ < alpha_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "alpha" << '.' << k_0__ + 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 gamma_k_0_max__ = has_intercept;
        for (size_t k_0__ = 0; k_0__ < gamma_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "gamma" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t z_beta_j_1_max__ = (logical_eq(prior_dist, 7) ? sum(num_normals) : K );
        for (size_t j_1__ = 0; j_1__ < z_beta_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "z_beta" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t z_beta_smooth_j_1_max__ = K_smooth;
        for (size_t j_1__ = 0; j_1__ < z_beta_smooth_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "z_beta_smooth" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t smooth_sd_raw_j_1_max__ = (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 );
        for (size_t j_1__ = 0; j_1__ < smooth_sd_raw_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "smooth_sd_raw" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t global_k_0_max__ = hs;
        for (size_t k_0__ = 0; k_0__ < global_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "global" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t local_j_1_max__ = K;
        size_t local_k_0_max__ = hs;
        for (size_t j_1__ = 0; j_1__ < local_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < local_k_0_max__; ++k_0__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "local" << '.' << k_0__ + 1 << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
        }
        size_t caux_k_0_max__ = logical_gt(hs, 0);
        for (size_t k_0__ = 0; k_0__ < caux_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "caux" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t mix_j_1_max__ = K;
        size_t mix_k_0_max__ = (primitive_value(logical_eq(prior_dist, 5)) || primitive_value(logical_eq(prior_dist, 6)));
        for (size_t j_1__ = 0; j_1__ < mix_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < mix_k_0_max__; ++k_0__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "mix" << '.' << k_0__ + 1 << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
        }
        size_t one_over_lambda_k_0_max__ = logical_eq(prior_dist, 6);
        for (size_t k_0__ = 0; k_0__ < one_over_lambda_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "one_over_lambda" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t z_b_j_1_max__ = q;
        for (size_t j_1__ = 0; j_1__ < z_b_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "z_b" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t z_T_j_1_max__ = len_z_T;
        for (size_t j_1__ = 0; j_1__ < z_T_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "z_T" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t rho_j_1_max__ = len_rho;
        for (size_t j_1__ = 0; j_1__ < rho_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "rho" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t zeta_j_1_max__ = len_concentration;
        for (size_t j_1__ = 0; j_1__ < zeta_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "zeta" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t tau_j_1_max__ = t;
        for (size_t j_1__ = 0; j_1__ < tau_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "tau" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t aux_unscaled_k_0_max__ = logical_gt(family, 6);
        for (size_t k_0__ = 0; k_0__ < aux_unscaled_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "aux_unscaled" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t noise_j_1_max__ = N;
        size_t noise_k_0_max__ = logical_eq(family, 8);
        for (size_t j_1__ = 0; j_1__ < noise_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < noise_k_0_max__; ++k_0__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "noise" << '.' << k_0__ + 1 << '.' << 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__ << "aux";
            param_names__.push_back(param_name_stream__.str());
            size_t beta_j_1_max__ = K;
            for (size_t j_1__ = 0; j_1__ < beta_j_1_max__; ++j_1__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "beta" << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
            size_t beta_smooth_j_1_max__ = K_smooth;
            for (size_t j_1__ = 0; j_1__ < beta_smooth_j_1_max__; ++j_1__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "beta_smooth" << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
            size_t smooth_sd_j_1_max__ = (logical_gt(K_smooth, 0) ? get_base1(smooth_map, K_smooth, "smooth_map", 1) : 0 );
            for (size_t j_1__ = 0; j_1__ < smooth_sd_j_1_max__; ++j_1__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "smooth_sd" << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
            size_t b_j_1_max__ = q;
            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 theta_L_j_1_max__ = len_theta_L;
            for (size_t j_1__ = 0; j_1__ < theta_L_j_1_max__; ++j_1__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "theta_L" << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
        }

        if (!include_gqs__) return;
        param_name_stream__.str(std::string());
        param_name_stream__ << "mean_PPD";
        param_names__.push_back(param_name_stream__.str());
        size_t alpha_k_0_max__ = has_intercept;
        for (size_t k_0__ = 0; k_0__ < alpha_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "alpha" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
    }

}; // model

}  // namespace

typedef model_count_namespace::model_count stan_model;