// Code generated by Stan version 2.19.1

#include <stan/model/model_header.hpp>

namespace model_continuous_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_continuous");
    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_continuous");
    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_continuous");
    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_continuous");
    reader.add_event(319, 6, "include", "/functions/continuous_likelihoods.stan");
    reader.add_event(319, 0, "start", "/functions/continuous_likelihoods.stan");
    reader.add_event(555, 236, "end", "/functions/continuous_likelihoods.stan");
    reader.add_event(555, 7, "restart", "model_continuous");
    reader.add_event(555, 7, "include", "/functions/SSfunctions.stan");
    reader.add_event(555, 0, "start", "/functions/SSfunctions.stan");
    reader.add_event(703, 148, "end", "/functions/SSfunctions.stan");
    reader.add_event(703, 8, "restart", "model_continuous");
    reader.add_event(739, 44, "include", "/data/NKX.stan");
    reader.add_event(739, 0, "start", "/data/NKX.stan");
    reader.add_event(759, 20, "end", "/data/NKX.stan");
    reader.add_event(759, 45, "restart", "model_continuous");
    reader.add_event(765, 51, "include", "/data/data_glm.stan");
    reader.add_event(765, 0, "start", "/data/data_glm.stan");
    reader.add_event(785, 20, "end", "/data/data_glm.stan");
    reader.add_event(785, 52, "restart", "model_continuous");
    reader.add_event(786, 53, "include", "/data/weights_offset.stan");
    reader.add_event(786, 0, "start", "/data/weights_offset.stan");
    reader.add_event(793, 7, "end", "/data/weights_offset.stan");
    reader.add_event(793, 54, "restart", "model_continuous");
    reader.add_event(794, 55, "include", "/data/hyperparameters.stan");
    reader.add_event(794, 0, "start", "/data/hyperparameters.stan");
    reader.add_event(812, 18, "end", "/data/hyperparameters.stan");
    reader.add_event(812, 56, "restart", "model_continuous");
    reader.add_event(813, 57, "include", "/data/glmer_stuff.stan");
    reader.add_event(813, 0, "start", "/data/glmer_stuff.stan");
    reader.add_event(828, 15, "end", "/data/glmer_stuff.stan");
    reader.add_event(828, 58, "restart", "model_continuous");
    reader.add_event(829, 59, "include", "/data/glmer_stuff2.stan");
    reader.add_event(829, 0, "start", "/data/glmer_stuff2.stan");
    reader.add_event(834, 5, "end", "/data/glmer_stuff2.stan");
    reader.add_event(834, 60, "restart", "model_continuous");
    reader.add_event(834, 60, "include", "/data/data_betareg.stan");
    reader.add_event(834, 0, "start", "/data/data_betareg.stan");
    reader.add_event(854, 20, "end", "/data/data_betareg.stan");
    reader.add_event(854, 61, "restart", "model_continuous");
    reader.add_event(875, 82, "include", "/tdata/tdata_glm.stan");
    reader.add_event(875, 0, "start", "/tdata/tdata_glm.stan");
    reader.add_event(896, 21, "end", "/tdata/tdata_glm.stan");
    reader.add_event(896, 83, "restart", "model_continuous");
    reader.add_event(897, 84, "include", "/tdata/tdata_betareg.stan");
    reader.add_event(897, 0, "start", "/tdata/tdata_betareg.stan");
    reader.add_event(901, 4, "end", "/tdata/tdata_betareg.stan");
    reader.add_event(901, 85, "restart", "model_continuous");
    reader.add_event(926, 110, "include", "/parameters/parameters_glm.stan");
    reader.add_event(926, 0, "start", "/parameters/parameters_glm.stan");
    reader.add_event(939, 13, "end", "/parameters/parameters_glm.stan");
    reader.add_event(939, 111, "restart", "model_continuous");
    reader.add_event(940, 112, "include", "/parameters/parameters_betareg.stan");
    reader.add_event(940, 0, "start", "/parameters/parameters_betareg.stan");
    reader.add_event(947, 7, "end", "/parameters/parameters_betareg.stan");
    reader.add_event(947, 113, "restart", "model_continuous");
    reader.add_event(956, 122, "include", "/tparameters/tparameters_glm.stan");
    reader.add_event(956, 0, "start", "/tparameters/tparameters_glm.stan");
    reader.add_event(1001, 45, "end", "/tparameters/tparameters_glm.stan");
    reader.add_event(1001, 123, "restart", "model_continuous");
    reader.add_event(1001, 123, "include", "/tparameters/tparameters_betareg.stan");
    reader.add_event(1001, 0, "start", "/tparameters/tparameters_betareg.stan");
    reader.add_event(1031, 30, "end", "/tparameters/tparameters_betareg.stan");
    reader.add_event(1031, 124, "restart", "model_continuous");
    reader.add_event(1069, 162, "include", "/model/make_eta.stan");
    reader.add_event(1069, 0, "start", "/model/make_eta.stan");
    reader.add_event(1077, 8, "end", "/model/make_eta.stan");
    reader.add_event(1077, 163, "restart", "model_continuous");
    reader.add_event(1078, 164, "include", "/model/eta_add_Zb.stan");
    reader.add_event(1078, 0, "start", "/model/eta_add_Zb.stan");
    reader.add_event(1080, 2, "end", "/model/eta_add_Zb.stan");
    reader.add_event(1080, 165, "restart", "model_continuous");
    reader.add_event(1087, 172, "include", "/model/eta_no_intercept.stan");
    reader.add_event(1087, 0, "start", "/model/eta_no_intercept.stan");
    reader.add_event(1089, 2, "end", "/model/eta_no_intercept.stan");
    reader.add_event(1089, 173, "restart", "model_continuous");
    reader.add_event(1118, 202, "include", "/model/make_eta_z.stan");
    reader.add_event(1118, 0, "start", "/model/make_eta_z.stan");
    reader.add_event(1124, 6, "end", "/model/make_eta_z.stan");
    reader.add_event(1124, 203, "restart", "model_continuous");
    reader.add_event(1134, 213, "include", "/model/eta_z_no_intercept.stan");
    reader.add_event(1134, 0, "start", "/model/eta_z_no_intercept.stan");
    reader.add_event(1140, 6, "end", "/model/eta_z_no_intercept.stan");
    reader.add_event(1140, 214, "restart", "model_continuous");
    reader.add_event(1192, 266, "include", "/model/priors_glm.stan");
    reader.add_event(1192, 0, "start", "/model/priors_glm.stan");
    reader.add_event(1252, 60, "end", "/model/priors_glm.stan");
    reader.add_event(1252, 267, "restart", "model_continuous");
    reader.add_event(1252, 267, "include", "/model/priors_betareg.stan");
    reader.add_event(1252, 0, "start", "/model/priors_betareg.stan");
    reader.add_event(1299, 47, "end", "/model/priors_betareg.stan");
    reader.add_event(1299, 268, "restart", "model_continuous");
    reader.add_event(1319, 288, "include", "/model/make_eta.stan");
    reader.add_event(1319, 0, "start", "/model/make_eta.stan");
    reader.add_event(1327, 8, "end", "/model/make_eta.stan");
    reader.add_event(1327, 289, "restart", "model_continuous");
    reader.add_event(1328, 290, "include", "/model/eta_add_Zb.stan");
    reader.add_event(1328, 0, "start", "/model/eta_add_Zb.stan");
    reader.add_event(1330, 2, "end", "/model/eta_add_Zb.stan");
    reader.add_event(1330, 291, "restart", "model_continuous");
    reader.add_event(1346, 307, "include", "/model/eta_no_intercept.stan");
    reader.add_event(1346, 0, "start", "/model/eta_no_intercept.stan");
    reader.add_event(1348, 2, "end", "/model/eta_no_intercept.stan");
    reader.add_event(1348, 308, "restart", "model_continuous");
    reader.add_event(1349, 309, "include", "/model/make_eta_z.stan");
    reader.add_event(1349, 0, "start", "/model/make_eta_z.stan");
    reader.add_event(1355, 6, "end", "/model/make_eta_z.stan");
    reader.add_event(1355, 310, "restart", "model_continuous");
    reader.add_event(1366, 321, "include", "/model/eta_z_no_intercept.stan");
    reader.add_event(1366, 0, "start", "/model/eta_z_no_intercept.stan");
    reader.add_event(1372, 6, "end", "/model/eta_z_no_intercept.stan");
    reader.add_event(1372, 322, "restart", "model_continuous");
    reader.add_event(1439, 387, "end", "model_continuous");
    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_gauss(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__ = 328;
        if (as_bool(logical_eq(link, 1))) {
            current_statement_begin__ = 328;
            return stan::math::promote_scalar<fun_return_scalar_t__>(eta);
        } else if (as_bool(logical_eq(link, 2))) {
            current_statement_begin__ = 329;
            return stan::math::promote_scalar<fun_return_scalar_t__>(stan::math::exp(eta));
        } else if (as_bool(logical_eq(link, 3))) {
            current_statement_begin__ = 330;
            return stan::math::promote_scalar<fun_return_scalar_t__>(inv(eta));
        } else {
            current_statement_begin__ = 331;
            std::stringstream errmsg_stream__;
            errmsg_stream__ << "Invalid link";
            throw std::domain_error(errmsg_stream__.str());
        }
        current_statement_begin__ = 332;
        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_gauss_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_gauss(eta, link, pstream__);
    }
};

template <typename T0__, typename T1__, typename T2__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__>::type, Eigen::Dynamic, 1>
pw_gauss(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
             const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
             const T2__& sigma,
             const int& link, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, 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__ = 343;
        return stan::math::promote_scalar<fun_return_scalar_t__>(subtract((-(0.5) * stan::math::log((6.283185307179586232 * sigma))), multiply(0.5, square(divide(subtract(y, linkinv_gauss(eta, link, pstream__)), sigma)))));
    } 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_gauss_functor__ {
    template <typename T0__, typename T1__, typename T2__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__>::type, Eigen::Dynamic, 1>
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
             const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
             const T2__& sigma,
             const int& link, std::ostream* pstream__) const {
        return pw_gauss(y, eta, sigma, link, pstream__);
    }
};

template <typename T0__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__>::type, Eigen::Dynamic, 1>
linkinv_gamma(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__ = 355;
        if (as_bool(logical_eq(link, 1))) {
            current_statement_begin__ = 355;
            return stan::math::promote_scalar<fun_return_scalar_t__>(eta);
        } else if (as_bool(logical_eq(link, 2))) {
            current_statement_begin__ = 356;
            return stan::math::promote_scalar<fun_return_scalar_t__>(stan::math::exp(eta));
        } else if (as_bool(logical_eq(link, 3))) {
            current_statement_begin__ = 357;
            return stan::math::promote_scalar<fun_return_scalar_t__>(inv(eta));
        } else {
            current_statement_begin__ = 358;
            std::stringstream errmsg_stream__;
            errmsg_stream__ << "Invalid link";
            throw std::domain_error(errmsg_stream__.str());
        }
        current_statement_begin__ = 359;
        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_gamma_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_gamma(eta, link, pstream__);
    }
};

template <typename T0__, typename T1__, typename T2__, typename T4__>
typename boost::math::tools::promote_args<T0__, T1__, T2__, T4__>::type
GammaReg(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
             const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
             const T2__& shape,
             const int& link,
             const T4__& sum_log_y, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, T1__, T2__, T4__>::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__ = 374;
        local_scalar_t__ ret(DUMMY_VAR__);
        (void) ret;  // dummy to suppress unused var warning
        stan::math::initialize(ret, DUMMY_VAR__);
        stan::math::fill(ret, DUMMY_VAR__);
        stan::math::assign(ret,((rows(y) * ((shape * stan::math::log(shape)) - stan::math::lgamma(shape))) + ((shape - 1) * sum_log_y)));


        current_statement_begin__ = 376;
        if (as_bool(logical_eq(link, 2))) {
            current_statement_begin__ = 377;
            stan::math::assign(ret, (ret - ((shape * sum(eta)) + (shape * sum(elt_divide(y, stan::math::exp(eta)))))));
        } else if (as_bool(logical_eq(link, 1))) {
            current_statement_begin__ = 379;
            stan::math::assign(ret, (ret - ((shape * sum(stan::math::log(eta))) + (shape * sum(elt_divide(y, eta))))));
        } else if (as_bool(logical_eq(link, 3))) {
            current_statement_begin__ = 381;
            stan::math::assign(ret, (ret + ((shape * sum(stan::math::log(eta))) - (shape * dot_product(eta, y)))));
        } else {
            current_statement_begin__ = 382;
            std::stringstream errmsg_stream__;
            errmsg_stream__ << "Invalid link";
            throw std::domain_error(errmsg_stream__.str());
        }
        current_statement_begin__ = 383;
        return stan::math::promote_scalar<fun_return_scalar_t__>(ret);
        }
    } 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 GammaReg_functor__ {
    template <typename T0__, typename T1__, typename T2__, typename T4__>
        typename boost::math::tools::promote_args<T0__, T1__, T2__, T4__>::type
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
             const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
             const T2__& shape,
             const int& link,
             const T4__& sum_log_y, std::ostream* pstream__) const {
        return GammaReg(y, eta, shape, link, sum_log_y, pstream__);
    }
};

template <typename T0__, typename T1__, typename T2__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__>::type, Eigen::Dynamic, 1>
pw_gamma(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
             const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
             const T2__& shape,
             const int& link, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, 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__ = 395;
        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__ = 396;
        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__ = 397;
        if (as_bool(logical_eq(link, 3))) {

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

                current_statement_begin__ = 399;
                stan::model::assign(ll, 
                            stan::model::cons_list(stan::model::index_uni(n), stan::model::nil_index_list()), 
                            gamma_log(get_base1(y, n, "y", 1), shape, (shape * get_base1(eta, n, "eta", 1))), 
                            "assigning variable ll");
            }
        } else if (as_bool(logical_eq(link, 2))) {

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

                current_statement_begin__ = 404;
                stan::model::assign(ll, 
                            stan::model::cons_list(stan::model::index_uni(n), stan::model::nil_index_list()), 
                            gamma_log(get_base1(y, n, "y", 1), shape, (shape / stan::math::exp(get_base1(eta, n, "eta", 1)))), 
                            "assigning variable ll");
            }
        } else if (as_bool(logical_eq(link, 1))) {

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

                current_statement_begin__ = 409;
                stan::model::assign(ll, 
                            stan::model::cons_list(stan::model::index_uni(n), stan::model::nil_index_list()), 
                            gamma_log(get_base1(y, n, "y", 1), shape, (shape / get_base1(eta, n, "eta", 1))), 
                            "assigning variable ll");
            }
        } else {
            current_statement_begin__ = 412;
            std::stringstream errmsg_stream__;
            errmsg_stream__ << "Invalid link";
            throw std::domain_error(errmsg_stream__.str());
        }
        current_statement_begin__ = 413;
        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_gamma_functor__ {
    template <typename T0__, typename T1__, typename T2__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__>::type, Eigen::Dynamic, 1>
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
             const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
             const T2__& shape,
             const int& link, std::ostream* pstream__) const {
        return pw_gamma(y, eta, shape, link, pstream__);
    }
};

template <typename T0__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__>::type, Eigen::Dynamic, 1>
linkinv_inv_gaussian(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__ = 424;
        if (as_bool(logical_eq(link, 1))) {
            current_statement_begin__ = 424;
            return stan::math::promote_scalar<fun_return_scalar_t__>(eta);
        } else if (as_bool(logical_eq(link, 2))) {
            current_statement_begin__ = 425;
            return stan::math::promote_scalar<fun_return_scalar_t__>(stan::math::exp(eta));
        } else if (as_bool(logical_eq(link, 3))) {
            current_statement_begin__ = 426;
            return stan::math::promote_scalar<fun_return_scalar_t__>(inv(eta));
        } else if (as_bool(logical_eq(link, 4))) {
            current_statement_begin__ = 427;
            return stan::math::promote_scalar<fun_return_scalar_t__>(inv_sqrt(eta));
        } else {
            current_statement_begin__ = 428;
            std::stringstream errmsg_stream__;
            errmsg_stream__ << "Invalid link";
            throw std::domain_error(errmsg_stream__.str());
        }
        current_statement_begin__ = 429;
        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_inv_gaussian_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_inv_gaussian(eta, link, pstream__);
    }
};

template <typename T0__, typename T1__, typename T2__, typename T3__, typename T4__>
typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__>::type>::type
inv_gaussian(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
                 const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& mu,
                 const T2__& lambda,
                 const T3__& sum_log_y,
                 const Eigen::Matrix<T4__, Eigen::Dynamic, 1>& sqrt_y, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__>::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__ = 444;
        return stan::math::promote_scalar<fun_return_scalar_t__>(((((0.5 * rows(y)) * stan::math::log((lambda / 6.283185307179586232))) - (1.5 * sum_log_y)) - ((0.5 * lambda) * dot_self(elt_divide(subtract(y, mu), elt_multiply(mu, sqrt_y))))));
    } 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 inv_gaussian_functor__ {
    template <typename T0__, typename T1__, typename T2__, typename T3__, typename T4__>
        typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__>::type>::type
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
                 const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& mu,
                 const T2__& lambda,
                 const T3__& sum_log_y,
                 const Eigen::Matrix<T4__, Eigen::Dynamic, 1>& sqrt_y, std::ostream* pstream__) const {
        return inv_gaussian(y, mu, lambda, sum_log_y, sqrt_y, pstream__);
    }
};

template <typename T0__, typename T1__, typename T2__, typename T4__, typename T5__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__, T4__, typename boost::math::tools::promote_args<T5__>::type>::type, Eigen::Dynamic, 1>
pw_inv_gaussian(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
                    const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
                    const T2__& lambda,
                    const int& link,
                    const Eigen::Matrix<T4__, Eigen::Dynamic, 1>& log_y,
                    const Eigen::Matrix<T5__, Eigen::Dynamic, 1>& sqrt_y, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, T1__, T2__, T4__, typename boost::math::tools::promote_args<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__ = 462;
        validate_non_negative_index("mu", "rows(y)", rows(y));
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> mu(rows(y));
        stan::math::initialize(mu, DUMMY_VAR__);
        stan::math::fill(mu, DUMMY_VAR__);
        stan::math::assign(mu,linkinv_inv_gaussian(eta, link, pstream__));


        current_statement_begin__ = 463;
        return stan::math::promote_scalar<fun_return_scalar_t__>(subtract(add(multiply((-(0.5) * lambda), square(elt_divide(subtract(y, mu), elt_multiply(mu, sqrt_y)))), (0.5 * stan::math::log((lambda / 6.283185307179586232)))), multiply(1.5, log_y)));
        }
    } 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_inv_gaussian_functor__ {
    template <typename T0__, typename T1__, typename T2__, typename T4__, typename T5__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__, T4__, typename boost::math::tools::promote_args<T5__>::type>::type, Eigen::Dynamic, 1>
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
                    const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
                    const T2__& lambda,
                    const int& link,
                    const Eigen::Matrix<T4__, Eigen::Dynamic, 1>& log_y,
                    const Eigen::Matrix<T5__, Eigen::Dynamic, 1>& sqrt_y, std::ostream* pstream__) const {
        return pw_inv_gaussian(y, eta, lambda, link, log_y, sqrt_y, pstream__);
    }
};

template <typename T0__, typename T1__, class RNG>
typename boost::math::tools::promote_args<T0__, T1__>::type
inv_gaussian_rng(const T0__& mu,
                     const T1__& lambda, RNG& base_rng__, 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__ = 477;
        local_scalar_t__ mu2(DUMMY_VAR__);
        (void) mu2;  // dummy to suppress unused var warning
        stan::math::initialize(mu2, DUMMY_VAR__);
        stan::math::fill(mu2, DUMMY_VAR__);
        stan::math::assign(mu2,square(mu));

        current_statement_begin__ = 478;
        local_scalar_t__ z(DUMMY_VAR__);
        (void) z;  // dummy to suppress unused var warning
        stan::math::initialize(z, DUMMY_VAR__);
        stan::math::fill(z, DUMMY_VAR__);
        stan::math::assign(z,uniform_rng(0, 1, base_rng__));

        current_statement_begin__ = 479;
        local_scalar_t__ y(DUMMY_VAR__);
        (void) y;  // dummy to suppress unused var warning
        stan::math::initialize(y, DUMMY_VAR__);
        stan::math::fill(y, DUMMY_VAR__);
        stan::math::assign(y,square(normal_rng(0, 1, base_rng__)));

        current_statement_begin__ = 480;
        local_scalar_t__ x(DUMMY_VAR__);
        (void) x;  // dummy to suppress unused var warning
        stan::math::initialize(x, DUMMY_VAR__);
        stan::math::fill(x, DUMMY_VAR__);
        stan::math::assign(x,(mu + (((mu2 * y) - (mu * stan::math::sqrt(((((4 * mu) * lambda) * y) + (mu2 * square(y)))))) / (2 * lambda))));


        current_statement_begin__ = 482;
        if (as_bool(logical_lte(z, (mu / (mu + x))))) {
            current_statement_begin__ = 482;
            return stan::math::promote_scalar<fun_return_scalar_t__>(x);
        } else {
            current_statement_begin__ = 483;
            return stan::math::promote_scalar<fun_return_scalar_t__>((mu2 / x));
        }
        }
    } 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 inv_gaussian_rng_functor__ {
    template <typename T0__, typename T1__, class RNG>
        typename boost::math::tools::promote_args<T0__, T1__>::type
    operator()(const T0__& mu,
                     const T1__& lambda, RNG& base_rng__, std::ostream* pstream__) const {
        return inv_gaussian_rng(mu, lambda, base_rng__, pstream__);
    }
};

template <typename T0__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__>::type, Eigen::Dynamic, 1>
linkinv_beta(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__ = 494;
        if (as_bool(logical_eq(link, 1))) {
            current_statement_begin__ = 494;
            return stan::math::promote_scalar<fun_return_scalar_t__>(inv_logit(eta));
        } else if (as_bool(logical_eq(link, 2))) {
            current_statement_begin__ = 495;
            return stan::math::promote_scalar<fun_return_scalar_t__>(Phi(eta));
        } else if (as_bool(logical_eq(link, 3))) {
            current_statement_begin__ = 496;
            return stan::math::promote_scalar<fun_return_scalar_t__>(inv_cloglog(eta));
        } else if (as_bool(logical_eq(link, 4))) {
            current_statement_begin__ = 497;
            return stan::math::promote_scalar<fun_return_scalar_t__>(add(0.5, divide(stan::math::atan(eta), stan::math::pi())));
        } else if (as_bool(logical_eq(link, 5))) {
            current_statement_begin__ = 498;
            return stan::math::promote_scalar<fun_return_scalar_t__>(stan::math::exp(eta));
        } else if (as_bool(logical_eq(link, 6))) {
            current_statement_begin__ = 499;
            return stan::math::promote_scalar<fun_return_scalar_t__>(subtract(1, inv_cloglog(minus(eta))));
        } else {
            current_statement_begin__ = 500;
            std::stringstream errmsg_stream__;
            errmsg_stream__ << "invalid link";
            throw std::domain_error(errmsg_stream__.str());
        }
        current_statement_begin__ = 501;
        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_beta_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_beta(eta, link, pstream__);
    }
};

template <typename T0__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__>::type, Eigen::Dynamic, 1>
linkinv_beta_z(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__ = 512;
        if (as_bool(logical_eq(link, 1))) {
            current_statement_begin__ = 512;
            return stan::math::promote_scalar<fun_return_scalar_t__>(stan::math::exp(eta));
        } else if (as_bool(logical_eq(link, 2))) {
            current_statement_begin__ = 513;
            return stan::math::promote_scalar<fun_return_scalar_t__>(eta);
        } else if (as_bool(logical_eq(link, 3))) {
            current_statement_begin__ = 514;
            return stan::math::promote_scalar<fun_return_scalar_t__>(square(eta));
        } else {
            current_statement_begin__ = 515;
            std::stringstream errmsg_stream__;
            errmsg_stream__ << "Invalid link";
            throw std::domain_error(errmsg_stream__.str());
        }
        current_statement_begin__ = 516;
        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_beta_z_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_beta_z(eta, link, pstream__);
    }
};

template <typename T0__, typename T1__, typename T2__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__>::type, Eigen::Dynamic, 1>
pw_beta(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
            const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
            const T2__& dispersion,
            const int& link, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, 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__ = 529;
        validate_non_negative_index("ll", "rows(y)", rows(y));
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> ll(rows(y));
        stan::math::initialize(ll, DUMMY_VAR__);
        stan::math::fill(ll, DUMMY_VAR__);

        current_statement_begin__ = 530;
        validate_non_negative_index("mu", "rows(y)", rows(y));
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> mu(rows(y));
        stan::math::initialize(mu, DUMMY_VAR__);
        stan::math::fill(mu, DUMMY_VAR__);
        stan::math::assign(mu,linkinv_beta(eta, link, pstream__));


        current_statement_begin__ = 531;
        for (int n = 1; n <= rows(y); ++n) {

            current_statement_begin__ = 532;
            stan::model::assign(ll, 
                        stan::model::cons_list(stan::model::index_uni(n), stan::model::nil_index_list()), 
                        beta_log(get_base1(y, n, "y", 1), (get_base1(mu, n, "mu", 1) * dispersion), ((1 - get_base1(mu, n, "mu", 1)) * dispersion)), 
                        "assigning variable ll");
        }
        current_statement_begin__ = 534;
        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_beta_functor__ {
    template <typename T0__, typename T1__, typename T2__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__>::type, Eigen::Dynamic, 1>
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
            const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
            const T2__& dispersion,
            const int& link, std::ostream* pstream__) const {
        return pw_beta(y, eta, dispersion, link, pstream__);
    }
};

template <typename T0__, typename T1__, typename T2__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__>::type, Eigen::Dynamic, 1>
pw_beta_z(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
              const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
              const Eigen::Matrix<T2__, Eigen::Dynamic, 1>& eta_z,
              const int& link,
              const int& link_phi, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, 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__ = 548;
        validate_non_negative_index("ll", "rows(y)", rows(y));
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> ll(rows(y));
        stan::math::initialize(ll, DUMMY_VAR__);
        stan::math::fill(ll, DUMMY_VAR__);

        current_statement_begin__ = 549;
        validate_non_negative_index("mu", "rows(y)", rows(y));
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> mu(rows(y));
        stan::math::initialize(mu, DUMMY_VAR__);
        stan::math::fill(mu, DUMMY_VAR__);
        stan::math::assign(mu,linkinv_beta(eta, link, pstream__));

        current_statement_begin__ = 550;
        validate_non_negative_index("mu_z", "rows(y)", rows(y));
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> mu_z(rows(y));
        stan::math::initialize(mu_z, DUMMY_VAR__);
        stan::math::fill(mu_z, DUMMY_VAR__);
        stan::math::assign(mu_z,linkinv_beta_z(eta_z, link_phi, pstream__));


        current_statement_begin__ = 551;
        for (int n = 1; n <= rows(y); ++n) {

            current_statement_begin__ = 552;
            stan::model::assign(ll, 
                        stan::model::cons_list(stan::model::index_uni(n), stan::model::nil_index_list()), 
                        beta_log(get_base1(y, n, "y", 1), (get_base1(mu, n, "mu", 1) * get_base1(mu_z, n, "mu_z", 1)), ((1 - get_base1(mu, n, "mu", 1)) * get_base1(mu_z, n, "mu_z", 1))), 
                        "assigning variable ll");
        }
        current_statement_begin__ = 554;
        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_beta_z_functor__ {
    template <typename T0__, typename T1__, typename T2__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__>::type, Eigen::Dynamic, 1>
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& y,
              const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& eta,
              const Eigen::Matrix<T2__, Eigen::Dynamic, 1>& eta_z,
              const int& link,
              const int& link_phi, std::ostream* pstream__) const {
        return pw_beta_z(y, eta, eta_z, link, link_phi, pstream__);
    }
};

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_asymp(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
             const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__);

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_asympOff(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
                const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__);

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_asympOrig(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
                 const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__);

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_biexp(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
             const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__);

template <typename T0__, typename T1__, typename T2__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__>::type, Eigen::Dynamic, 1>
SS_fol(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& Dose,
           const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& input,
           const Eigen::Matrix<T2__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__);

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_fpl(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
           const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__);

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_gompertz(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& x,
                const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__);

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_logis(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
             const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__);

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_micmen(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
              const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__);

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_weibull(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& x,
               const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__);

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_asymp(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
             const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, 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__ = 575;
        if (as_bool(logical_gt(rows(Phi), 1))) {
            {
            current_statement_begin__ = 576;
            validate_non_negative_index("Asym", "rows(Phi)", rows(Phi));
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> Asym(rows(Phi));
            stan::math::initialize(Asym, DUMMY_VAR__);
            stan::math::fill(Asym, DUMMY_VAR__);
            stan::math::assign(Asym,stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list())), "Phi"));


            current_statement_begin__ = 577;
            return stan::math::promote_scalar<fun_return_scalar_t__>(add(Asym, elt_multiply(subtract(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(2), stan::model::nil_index_list())), "Phi"), Asym), stan::math::exp(elt_multiply(minus(stan::math::exp(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(3), stan::model::nil_index_list())), "Phi"))), input)))));
            }
        } else {
            {
            current_statement_begin__ = 580;
            local_scalar_t__ Asym(DUMMY_VAR__);
            (void) Asym;  // dummy to suppress unused var warning
            stan::math::initialize(Asym, DUMMY_VAR__);
            stan::math::fill(Asym, DUMMY_VAR__);
            stan::math::assign(Asym,get_base1(Phi, 1, 1, "Phi", 1));


            current_statement_begin__ = 581;
            return stan::math::promote_scalar<fun_return_scalar_t__>(add(Asym, multiply((get_base1(Phi, 1, 2, "Phi", 1) - Asym), stan::math::exp(multiply(-(stan::math::exp(get_base1(Phi, 1, 3, "Phi", 1))), input)))));
            }
        }
    } 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 SS_asymp_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>& input,
             const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__) const {
        return SS_asymp(input, Phi, pstream__);
    }
};

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_asympOff(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
                const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, 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__ = 587;
        if (as_bool(logical_gt(rows(Phi), 1))) {
            current_statement_begin__ = 588;
            return stan::math::promote_scalar<fun_return_scalar_t__>(elt_multiply(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list())), "Phi"), subtract(1, stan::math::exp(elt_multiply(minus(stan::math::exp(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(2), stan::model::nil_index_list())), "Phi"))), subtract(input, stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(3), stan::model::nil_index_list())), "Phi")))))));
        } else {
            current_statement_begin__ = 590;
            return stan::math::promote_scalar<fun_return_scalar_t__>(multiply(get_base1(Phi, 1, 1, "Phi", 1), subtract(1, stan::math::exp(multiply(-(stan::math::exp(get_base1(Phi, 1, 2, "Phi", 1))), subtract(input, get_base1(Phi, 1, 3, "Phi", 1)))))));
        }
    } catch (const std::exception& e) {
        stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
        // Next line prevents compiler griping about no return
        throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
    }
}


struct SS_asympOff_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>& input,
                const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__) const {
        return SS_asympOff(input, Phi, pstream__);
    }
};

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_asympOrig(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
                 const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, 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__ = 595;
        if (as_bool(logical_gt(rows(Phi), 1))) {
            current_statement_begin__ = 596;
            return stan::math::promote_scalar<fun_return_scalar_t__>(elt_multiply(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list())), "Phi"), subtract(1, stan::math::exp(elt_multiply(minus(stan::math::exp(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(2), stan::model::nil_index_list())), "Phi"))), input)))));
        } else {
            current_statement_begin__ = 598;
            return stan::math::promote_scalar<fun_return_scalar_t__>(multiply(get_base1(Phi, 1, 1, "Phi", 1), subtract(1, stan::math::exp(multiply(-(stan::math::exp(get_base1(Phi, 1, 2, "Phi", 1))), input)))));
        }
    } 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 SS_asympOrig_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>& input,
                 const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__) const {
        return SS_asympOrig(input, Phi, pstream__);
    }
};

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_biexp(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
             const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, 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__ = 603;
        if (as_bool(logical_gt(rows(Phi), 1))) {
            current_statement_begin__ = 604;
            return stan::math::promote_scalar<fun_return_scalar_t__>(add(elt_multiply(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list())), "Phi"), stan::math::exp(elt_multiply(minus(stan::math::exp(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(2), stan::model::nil_index_list())), "Phi"))), input))), elt_multiply(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(3), stan::model::nil_index_list())), "Phi"), stan::math::exp(elt_multiply(minus(stan::math::exp(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(4), stan::model::nil_index_list())), "Phi"))), input)))));
        } else {
            current_statement_begin__ = 607;
            return stan::math::promote_scalar<fun_return_scalar_t__>(add(multiply(get_base1(Phi, 1, 1, "Phi", 1), stan::math::exp(multiply(-(stan::math::exp(get_base1(Phi, 1, 2, "Phi", 1))), input))), multiply(get_base1(Phi, 1, 3, "Phi", 1), stan::math::exp(multiply(-(stan::math::exp(get_base1(Phi, 1, 4, "Phi", 1))), input)))));
        }
    } 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 SS_biexp_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>& input,
             const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__) const {
        return SS_biexp(input, Phi, pstream__);
    }
};

template <typename T0__, typename T1__, typename T2__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__>::type, Eigen::Dynamic, 1>
SS_fol(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& Dose,
           const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& input,
           const Eigen::Matrix<T2__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, 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__ = 613;
        int Phi_rows(0);
        (void) Phi_rows;  // dummy to suppress unused var warning
        stan::math::fill(Phi_rows, std::numeric_limits<int>::min());
        stan::math::assign(Phi_rows,rows(Phi));


        current_statement_begin__ = 614;
        if (as_bool(logical_gt(Phi_rows, 1))) {
            {
            current_statement_begin__ = 615;
            validate_non_negative_index("lKe", "Phi_rows", Phi_rows);
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> lKe(Phi_rows);
            stan::math::initialize(lKe, DUMMY_VAR__);
            stan::math::fill(lKe, DUMMY_VAR__);
            stan::math::assign(lKe,stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list())), "Phi"));

            current_statement_begin__ = 616;
            validate_non_negative_index("lKa", "Phi_rows", Phi_rows);
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> lKa(Phi_rows);
            stan::math::initialize(lKa, DUMMY_VAR__);
            stan::math::fill(lKa, DUMMY_VAR__);
            stan::math::assign(lKa,stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(2), stan::model::nil_index_list())), "Phi"));

            current_statement_begin__ = 617;
            validate_non_negative_index("exp_lKe", "Phi_rows", Phi_rows);
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> exp_lKe(Phi_rows);
            stan::math::initialize(exp_lKe, DUMMY_VAR__);
            stan::math::fill(exp_lKe, DUMMY_VAR__);
            stan::math::assign(exp_lKe,stan::math::exp(lKe));

            current_statement_begin__ = 618;
            validate_non_negative_index("exp_lKa", "Phi_rows", Phi_rows);
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> exp_lKa(Phi_rows);
            stan::math::initialize(exp_lKa, DUMMY_VAR__);
            stan::math::fill(exp_lKa, DUMMY_VAR__);
            stan::math::assign(exp_lKa,stan::math::exp(lKa));


            current_statement_begin__ = 619;
            return stan::math::promote_scalar<fun_return_scalar_t__>(elt_divide(elt_multiply(elt_multiply(Dose, stan::math::exp(subtract(add(lKe, lKa), stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(3), stan::model::nil_index_list())), "Phi")))), subtract(stan::math::exp(elt_multiply(minus(exp_lKe), input)), stan::math::exp(elt_multiply(minus(exp_lKa), input)))), subtract(exp_lKa, exp_lKe)));
            }
        } else {
            {
            current_statement_begin__ = 623;
            local_scalar_t__ lKe(DUMMY_VAR__);
            (void) lKe;  // dummy to suppress unused var warning
            stan::math::initialize(lKe, DUMMY_VAR__);
            stan::math::fill(lKe, DUMMY_VAR__);
            stan::math::assign(lKe,get_base1(Phi, 1, 1, "Phi", 1));

            current_statement_begin__ = 624;
            local_scalar_t__ lKa(DUMMY_VAR__);
            (void) lKa;  // dummy to suppress unused var warning
            stan::math::initialize(lKa, DUMMY_VAR__);
            stan::math::fill(lKa, DUMMY_VAR__);
            stan::math::assign(lKa,get_base1(Phi, 1, 2, "Phi", 1));

            current_statement_begin__ = 625;
            local_scalar_t__ exp_lKe(DUMMY_VAR__);
            (void) exp_lKe;  // dummy to suppress unused var warning
            stan::math::initialize(exp_lKe, DUMMY_VAR__);
            stan::math::fill(exp_lKe, DUMMY_VAR__);
            stan::math::assign(exp_lKe,stan::math::exp(lKe));

            current_statement_begin__ = 626;
            local_scalar_t__ exp_lKa(DUMMY_VAR__);
            (void) exp_lKa;  // dummy to suppress unused var warning
            stan::math::initialize(exp_lKa, DUMMY_VAR__);
            stan::math::fill(exp_lKa, DUMMY_VAR__);
            stan::math::assign(exp_lKa,stan::math::exp(lKa));


            current_statement_begin__ = 627;
            return stan::math::promote_scalar<fun_return_scalar_t__>(divide(elt_multiply(multiply(Dose, stan::math::exp(((lKe + lKa) - get_base1(Phi, 1, 3, "Phi", 1)))), subtract(stan::math::exp(multiply(-(exp_lKe), input)), stan::math::exp(multiply(-(exp_lKa), input)))), (exp_lKa - exp_lKe)));
            }
        }
        }
    } 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 SS_fol_functor__ {
    template <typename T0__, typename T1__, typename T2__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__, T2__>::type, Eigen::Dynamic, 1>
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& Dose,
           const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& input,
           const Eigen::Matrix<T2__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__) const {
        return SS_fol(Dose, input, Phi, pstream__);
    }
};

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_fpl(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
           const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, 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__ = 635;
        if (as_bool(logical_gt(rows(Phi), 1))) {
            {
            current_statement_begin__ = 636;
            validate_non_negative_index("A", "rows(Phi)", rows(Phi));
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> A(rows(Phi));
            stan::math::initialize(A, DUMMY_VAR__);
            stan::math::fill(A, DUMMY_VAR__);
            stan::math::assign(A,stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list())), "Phi"));


            current_statement_begin__ = 637;
            return stan::math::promote_scalar<fun_return_scalar_t__>(add(A, elt_divide(subtract(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(2), stan::model::nil_index_list())), "Phi"), A), add(1, stan::math::exp(elt_divide(subtract(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(3), stan::model::nil_index_list())), "Phi"), input), stan::math::exp(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(4), stan::model::nil_index_list())), "Phi"))))))));
            }
        } else {
            {
            current_statement_begin__ = 640;
            local_scalar_t__ A(DUMMY_VAR__);
            (void) A;  // dummy to suppress unused var warning
            stan::math::initialize(A, DUMMY_VAR__);
            stan::math::fill(A, DUMMY_VAR__);
            stan::math::assign(A,get_base1(Phi, 1, 1, "Phi", 1));


            current_statement_begin__ = 641;
            return stan::math::promote_scalar<fun_return_scalar_t__>(add(A, elt_divide(rep_vector((get_base1(Phi, 1, 2, "Phi", 1) - A), rows(input)), add(1, stan::math::exp(divide(subtract(get_base1(Phi, 1, 3, "Phi", 1), input), stan::math::exp(get_base1(Phi, 1, 4, "Phi", 1))))))));
            }
        }
    } catch (const std::exception& e) {
        stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
        // Next line prevents compiler griping about no return
        throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
    }
}


struct SS_fpl_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>& input,
           const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__) const {
        return SS_fpl(input, Phi, pstream__);
    }
};

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_gompertz(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& x,
                const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, 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__ = 648;
        validate_non_negative_index("out", "rows(x)", rows(x));
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> out(rows(x));
        stan::math::initialize(out, DUMMY_VAR__);
        stan::math::fill(out, DUMMY_VAR__);


        current_statement_begin__ = 649;
        if (as_bool(logical_gt(rows(Phi), 1))) {
            current_statement_begin__ = 649;
            for (int i = 1; i <= rows(x); ++i) {
                current_statement_begin__ = 650;
                stan::model::assign(out, 
                            stan::model::cons_list(stan::model::index_uni(i), stan::model::nil_index_list()), 
                            (get_base1(Phi, i, 1, "Phi", 1) * stan::math::exp((-(get_base1(Phi, i, 2, "Phi", 1)) * pow(get_base1(Phi, i, 3, "Phi", 1), get_base1(x, i, "x", 1))))), 
                            "assigning variable out");
            }
        } else {
            {
            current_statement_begin__ = 652;
            local_scalar_t__ Asym(DUMMY_VAR__);
            (void) Asym;  // dummy to suppress unused var warning
            stan::math::initialize(Asym, DUMMY_VAR__);
            stan::math::fill(Asym, DUMMY_VAR__);
            stan::math::assign(Asym,get_base1(Phi, 1, 1, "Phi", 1));

            current_statement_begin__ = 653;
            local_scalar_t__ b2(DUMMY_VAR__);
            (void) b2;  // dummy to suppress unused var warning
            stan::math::initialize(b2, DUMMY_VAR__);
            stan::math::fill(b2, DUMMY_VAR__);
            stan::math::assign(b2,get_base1(Phi, 1, 2, "Phi", 1));

            current_statement_begin__ = 654;
            local_scalar_t__ b3(DUMMY_VAR__);
            (void) b3;  // dummy to suppress unused var warning
            stan::math::initialize(b3, DUMMY_VAR__);
            stan::math::fill(b3, DUMMY_VAR__);
            stan::math::assign(b3,get_base1(Phi, 1, 3, "Phi", 1));


            current_statement_begin__ = 655;
            for (int i = 1; i <= rows(x); ++i) {
                current_statement_begin__ = 655;
                stan::model::assign(out, 
                            stan::model::cons_list(stan::model::index_uni(i), stan::model::nil_index_list()), 
                            (Asym * stan::math::exp((-(b2) * pow(b3, get_base1(x, i, "x", 1))))), 
                            "assigning variable out");
            }
            }
        }
        current_statement_begin__ = 657;
        return stan::math::promote_scalar<fun_return_scalar_t__>(out);
        }
    } 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 SS_gompertz_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>& x,
                const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__) const {
        return SS_gompertz(x, Phi, pstream__);
    }
};

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_logis(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
             const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, 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__ = 663;
        if (as_bool(logical_gt(rows(Phi), 1))) {
            current_statement_begin__ = 664;
            return stan::math::promote_scalar<fun_return_scalar_t__>(elt_divide(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list())), "Phi"), add(1, stan::math::exp(elt_divide(subtract(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(2), stan::model::nil_index_list())), "Phi"), input), stan::math::exp(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(3), stan::model::nil_index_list())), "Phi")))))));
        } else {
            current_statement_begin__ = 666;
            return stan::math::promote_scalar<fun_return_scalar_t__>(elt_divide(rep_vector(get_base1(Phi, 1, 1, "Phi", 1), rows(input)), add(1, stan::math::exp(divide(subtract(get_base1(Phi, 1, 2, "Phi", 1), input), stan::math::exp(get_base1(Phi, 1, 3, "Phi", 1)))))));
        }
    } catch (const std::exception& e) {
        stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
        // Next line prevents compiler griping about no return
        throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
    }
}


struct SS_logis_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>& input,
             const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__) const {
        return SS_logis(input, Phi, pstream__);
    }
};

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_micmen(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& input,
              const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, 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__ = 672;
        if (as_bool(logical_gt(rows(Phi), 1))) {
            current_statement_begin__ = 673;
            return stan::math::promote_scalar<fun_return_scalar_t__>(elt_divide(elt_multiply(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list())), "Phi"), input), add(stan::model::rvalue(Phi, stan::model::cons_list(stan::model::index_omni(), stan::model::cons_list(stan::model::index_uni(2), stan::model::nil_index_list())), "Phi"), input)));
        } else {
            current_statement_begin__ = 675;
            return stan::math::promote_scalar<fun_return_scalar_t__>(elt_divide(multiply(get_base1(Phi, 1, 1, "Phi", 1), input), add(get_base1(Phi, 1, 2, "Phi", 1), input)));
        }
    } 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 SS_micmen_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>& input,
              const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__) const {
        return SS_micmen(input, Phi, pstream__);
    }
};

template <typename T0__, typename T1__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__, T1__>::type, Eigen::Dynamic, 1>
SS_weibull(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& x,
               const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, 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__ = 680;
        validate_non_negative_index("out", "rows(x)", rows(x));
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> out(rows(x));
        stan::math::initialize(out, DUMMY_VAR__);
        stan::math::fill(out, DUMMY_VAR__);


        current_statement_begin__ = 681;
        if (as_bool(logical_gt(rows(Phi), 1))) {
            current_statement_begin__ = 681;
            for (int i = 1; i <= rows(x); ++i) {
                current_statement_begin__ = 682;
                stan::model::assign(out, 
                            stan::model::cons_list(stan::model::index_uni(i), stan::model::nil_index_list()), 
                            (get_base1(Phi, i, 1, "Phi", 1) - (get_base1(Phi, i, 2, "Phi", 1) * stan::math::exp((-(stan::math::exp(get_base1(Phi, i, 3, "Phi", 1))) * pow(get_base1(x, i, "x", 1), get_base1(Phi, i, 4, "Phi", 1)))))), 
                            "assigning variable out");
            }
        } else {
            {
            current_statement_begin__ = 684;
            local_scalar_t__ Asym(DUMMY_VAR__);
            (void) Asym;  // dummy to suppress unused var warning
            stan::math::initialize(Asym, DUMMY_VAR__);
            stan::math::fill(Asym, DUMMY_VAR__);
            stan::math::assign(Asym,get_base1(Phi, 1, 1, "Phi", 1));

            current_statement_begin__ = 685;
            local_scalar_t__ Drop(DUMMY_VAR__);
            (void) Drop;  // dummy to suppress unused var warning
            stan::math::initialize(Drop, DUMMY_VAR__);
            stan::math::fill(Drop, DUMMY_VAR__);
            stan::math::assign(Drop,get_base1(Phi, 1, 2, "Phi", 1));

            current_statement_begin__ = 686;
            local_scalar_t__ lrc(DUMMY_VAR__);
            (void) lrc;  // dummy to suppress unused var warning
            stan::math::initialize(lrc, DUMMY_VAR__);
            stan::math::fill(lrc, DUMMY_VAR__);
            stan::math::assign(lrc,get_base1(Phi, 1, 3, "Phi", 1));

            current_statement_begin__ = 687;
            local_scalar_t__ pwr(DUMMY_VAR__);
            (void) pwr;  // dummy to suppress unused var warning
            stan::math::initialize(pwr, DUMMY_VAR__);
            stan::math::fill(pwr, DUMMY_VAR__);
            stan::math::assign(pwr,get_base1(Phi, 1, 4, "Phi", 1));


            current_statement_begin__ = 688;
            for (int i = 1; i <= rows(x); ++i) {
                current_statement_begin__ = 689;
                stan::model::assign(out, 
                            stan::model::cons_list(stan::model::index_uni(i), stan::model::nil_index_list()), 
                            (Asym - (Drop * stan::math::exp((-(stan::math::exp(lrc)) * pow(get_base1(x, i, "x", 1), pwr))))), 
                            "assigning variable out");
            }
            }
        }
        current_statement_begin__ = 691;
        return stan::math::promote_scalar<fun_return_scalar_t__>(out);
        }
    } 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 SS_weibull_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>& x,
               const Eigen::Matrix<T1__, Eigen::Dynamic, Eigen::Dynamic>& Phi, std::ostream* pstream__) const {
        return SS_weibull(x, Phi, pstream__);
    }
};

template <typename T0__>
Eigen::Matrix<typename boost::math::tools::promote_args<T0__>::type, Eigen::Dynamic, Eigen::Dynamic>
reshape_vec(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& x,
                const int& Rows,
                const int& Cols, 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__ = 695;
        validate_non_negative_index("out", "Rows", Rows);
        validate_non_negative_index("out", "Cols", Cols);
        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, Eigen::Dynamic> out(Rows, Cols);
        stan::math::initialize(out, DUMMY_VAR__);
        stan::math::fill(out, DUMMY_VAR__);

        current_statement_begin__ = 696;
        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__ = 697;
        if (as_bool(logical_neq(rows(x), (Rows * Cols)))) {
            current_statement_begin__ = 697;
            std::stringstream errmsg_stream__;
            errmsg_stream__ << "x is the wrong length";
            throw std::domain_error(errmsg_stream__.str());
        }
        current_statement_begin__ = 698;
        for (int c = 1; c <= Cols; ++c) {
            current_statement_begin__ = 698;
            for (int r = 1; r <= Rows; ++r) {

                current_statement_begin__ = 699;
                stan::model::assign(out, 
                            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(x, pos, "x", 1), 
                            "assigning variable out");
                current_statement_begin__ = 700;
                stan::math::assign(pos, (pos + 1));
            }
        }
        current_statement_begin__ = 702;
        return stan::math::promote_scalar<fun_return_scalar_t__>(out);
        }
    } 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 reshape_vec_functor__ {
    template <typename T0__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T0__>::type, Eigen::Dynamic, Eigen::Dynamic>
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& x,
                const int& Rows,
                const int& Cols, std::ostream* pstream__) const {
        return reshape_vec(x, Rows, Cols, pstream__);
    }
};

template <typename T0__, typename T1__, typename T2__, typename T3__, typename T4__>
typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__>::type>::type
ll_mvn_ols(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& coeff,
               const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& OLS,
               const Eigen::Matrix<T2__, Eigen::Dynamic, Eigen::Dynamic>& XtX,
               const T3__& SSR,
               const T4__& sigma,
               const int& N, std::ostream* pstream__) {
    typedef typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__>::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__ = 718;
        return stan::math::promote_scalar<fun_return_scalar_t__>((((-(0.5) * (quad_form(XtX, subtract(coeff, OLS)) + SSR)) / square(sigma)) - (N * (stan::math::log(sigma) + stan::math::log(stan::math::sqrt((2 * stan::math::pi())))))));
    } 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 ll_mvn_ols_functor__ {
    template <typename T0__, typename T1__, typename T2__, typename T3__, typename T4__>
        typename boost::math::tools::promote_args<T0__, T1__, T2__, T3__, typename boost::math::tools::promote_args<T4__>::type>::type
    operator()(const Eigen::Matrix<T0__, Eigen::Dynamic, 1>& coeff,
               const Eigen::Matrix<T1__, Eigen::Dynamic, 1>& OLS,
               const Eigen::Matrix<T2__, Eigen::Dynamic, Eigen::Dynamic>& XtX,
               const T3__& SSR,
               const T4__& sigma,
               const int& N, std::ostream* pstream__) const {
        return ll_mvn_ols(coeff, OLS, XtX, SSR, sigma, N, pstream__);
    }
};

template <typename T2__, typename T5__>
Eigen::Matrix<typename boost::math::tools::promote_args<T2__, T5__>::type, Eigen::Dynamic, 1>
test_csr_matrix_times_vector(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__) {
    typedef typename boost::math::tools::promote_args<T2__, T5__>::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__ = 735;
        return stan::math::promote_scalar<fun_return_scalar_t__>(csr_matrix_times_vector(m, n, w, v, u, 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 test_csr_matrix_times_vector_functor__ {
    template <typename T2__, typename T5__>
        Eigen::Matrix<typename boost::math::tools::promote_args<T2__, T5__>::type, Eigen::Dynamic, 1>
    operator()(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__) const {
        return test_csr_matrix_times_vector(m, n, w, v, u, b, pstream__);
    }
};

class model_continuous : 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;
        int len_y;
        double lb_y;
        double ub_y;
        vector_d y;
        int family;
        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;
        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;
        int has_intercept_z;
        int link_phi;
        int z_dim;
        matrix_d betareg_z;
        row_vector_d zbar;
        int prior_dist_z;
        int prior_dist_for_intercept_z;
        vector_d prior_scale_z;
        double prior_scale_for_intercept_z;
        vector_d prior_mean_z;
        double prior_mean_for_intercept_z;
        vector_d prior_df_z;
        double prior_df_for_intercept_z;
        double global_prior_scale_z;
        double global_prior_df_z;
        double slab_df_z;
        double slab_scale_z;
        std::vector<int> num_normals_z;
        int SSfun;
        vector_d input;
        vector_d Dose;
        vector_d sqrt_y;
        vector_d log_y;
        double sum_log_y;
        std::vector<std::vector<int> > V;
        int hs_z;
        int can_do_OLS;
        vector_d OLS;
        matrix_d XtX;
        int can_do_normalidglm;
        matrix_d XS;
        double SSR;
        int len_z_T;
        int len_var_group;
        int len_rho;
        int is_continuous;
        int pos;
        std::vector<double> delta;
        int hs;
public:
    model_continuous(stan::io::var_context& context__,
        std::ostream* pstream__ = 0)
        : prob_grad(0) {
        ctor_body(context__, 0, pstream__);
    }

    model_continuous(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_continuous_namespace::model_continuous";
        (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__ = 741;
            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__ = 742;
            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__ = 745;
            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__ = 746;
            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__ = 747;
            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__ = 750;
            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__ = 751;
            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__ = 752;
            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__ = 754;
            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__ = 757;
            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__ = 758;
            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__ = 759;
            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__ = 760;
            context__.validate_dims("data initialization", "len_y", "int", context__.to_vec());
            len_y = int(0);
            vals_i__ = context__.vals_i("len_y");
            pos__ = 0;
            len_y = vals_i__[pos__++];
            check_greater_or_equal(function__, "len_y", len_y, 0);

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

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

            current_statement_begin__ = 763;
            validate_non_negative_index("y", "len_y", len_y);
            context__.validate_dims("data initialization", "y", "vector_d", context__.to_vec(len_y));
            y = Eigen::Matrix<double, Eigen::Dynamic, 1>(len_y);
            vals_r__ = context__.vals_r("y");
            pos__ = 0;
            size_t y_j_1_max__ = len_y;
            for (size_t j_1__ = 0; j_1__ < y_j_1_max__; ++j_1__) {
                y(j_1__) = vals_r__[pos__++];
            }
            check_greater_or_equal(function__, "y", y, lb_y);
            check_less_or_equal(function__, "y", y, ub_y);

            current_statement_begin__ = 764;
            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, 1);
            check_less_or_equal(function__, "family", family, 4);

            current_statement_begin__ = 767;
            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__ = 768;
            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__ = 771;
            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__ = 774;
            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__ = 778;
            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__ = 779;
            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__ = 782;
            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__ = 785;
            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__ = 788;
            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__ = 789;
            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__ = 792;
            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__ = 793;
            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__ = 796;
            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__ = 797;
            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__ = 798;
            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__ = 799;
            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__ = 800;
            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__ = 801;
            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__ = 802;
            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__ = 803;
            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__ = 804;
            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__ = 805;
            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__ = 806;
            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__ = 807;
            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__ = 808;
            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__ = 809;
            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__ = 810;
            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__ = 811;
            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__ = 812;
            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__ = 816;
            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__ = 817;
            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__ = 818;
            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__ = 819;
            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__ = 820;
            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__ = 823;
            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__ = 824;
            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__ = 825;
            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__ = 826;
            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__ = 827;
            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__ = 828;
            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__ = 830;
            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__ = 831;
            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__ = 832;
            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__ = 833;
            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__ = 834;
            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);

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

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

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

            current_statement_begin__ = 839;
            validate_non_negative_index("betareg_z", "N", N);
            validate_non_negative_index("betareg_z", "z_dim", z_dim);
            context__.validate_dims("data initialization", "betareg_z", "matrix_d", context__.to_vec(N,z_dim));
            betareg_z = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>(N, z_dim);
            vals_r__ = context__.vals_r("betareg_z");
            pos__ = 0;
            size_t betareg_z_j_2_max__ = z_dim;
            size_t betareg_z_j_1_max__ = N;
            for (size_t j_2__ = 0; j_2__ < betareg_z_j_2_max__; ++j_2__) {
                for (size_t j_1__ = 0; j_1__ < betareg_z_j_1_max__; ++j_1__) {
                    betareg_z(j_1__, j_2__) = vals_r__[pos__++];
                }
            }

            current_statement_begin__ = 840;
            validate_non_negative_index("zbar", "z_dim", z_dim);
            context__.validate_dims("data initialization", "zbar", "row_vector_d", context__.to_vec(z_dim));
            zbar = Eigen::Matrix<double, 1, Eigen::Dynamic>(z_dim);
            vals_r__ = context__.vals_r("zbar");
            pos__ = 0;
            size_t zbar_j_1_max__ = z_dim;
            for (size_t j_1__ = 0; j_1__ < zbar_j_1_max__; ++j_1__) {
                zbar(j_1__) = vals_r__[pos__++];
            }

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

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

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

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

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

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

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

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

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

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

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

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

            current_statement_begin__ = 854;
            validate_non_negative_index("num_normals_z", "(logical_eq(prior_dist_z, 7) ? z_dim : 0 )", (logical_eq(prior_dist_z, 7) ? z_dim : 0 ));
            context__.validate_dims("data initialization", "num_normals_z", "int", context__.to_vec((logical_eq(prior_dist_z, 7) ? z_dim : 0 )));
            num_normals_z = std::vector<int>((logical_eq(prior_dist_z, 7) ? z_dim : 0 ), int(0));
            vals_i__ = context__.vals_i("num_normals_z");
            pos__ = 0;
            size_t num_normals_z_k_0_max__ = (logical_eq(prior_dist_z, 7) ? z_dim : 0 );
            for (size_t k_0__ = 0; k_0__ < num_normals_z_k_0_max__; ++k_0__) {
                num_normals_z[k_0__] = vals_i__[pos__++];
            }
            size_t num_normals_z_i_0_max__ = (logical_eq(prior_dist_z, 7) ? z_dim : 0 );
            for (size_t i_0__ = 0; i_0__ < num_normals_z_i_0_max__; ++i_0__) {
                check_greater_or_equal(function__, "num_normals_z[i_0__]", num_normals_z[i_0__], 2);
            }

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

            current_statement_begin__ = 857;
            validate_non_negative_index("input", "(logical_gt(SSfun, 0) ? len_y : 0 )", (logical_gt(SSfun, 0) ? len_y : 0 ));
            context__.validate_dims("data initialization", "input", "vector_d", context__.to_vec((logical_gt(SSfun, 0) ? len_y : 0 )));
            input = Eigen::Matrix<double, Eigen::Dynamic, 1>((logical_gt(SSfun, 0) ? len_y : 0 ));
            vals_r__ = context__.vals_r("input");
            pos__ = 0;
            size_t input_j_1_max__ = (logical_gt(SSfun, 0) ? len_y : 0 );
            for (size_t j_1__ = 0; j_1__ < input_j_1_max__; ++j_1__) {
                input(j_1__) = vals_r__[pos__++];
            }

            current_statement_begin__ = 858;
            validate_non_negative_index("Dose", "(logical_eq(SSfun, 5) ? len_y : 0 )", (logical_eq(SSfun, 5) ? len_y : 0 ));
            context__.validate_dims("data initialization", "Dose", "vector_d", context__.to_vec((logical_eq(SSfun, 5) ? len_y : 0 )));
            Dose = Eigen::Matrix<double, Eigen::Dynamic, 1>((logical_eq(SSfun, 5) ? len_y : 0 ));
            vals_r__ = context__.vals_r("Dose");
            pos__ = 0;
            size_t Dose_j_1_max__ = (logical_eq(SSfun, 5) ? len_y : 0 );
            for (size_t j_1__ = 0; j_1__ < Dose_j_1_max__; ++j_1__) {
                Dose(j_1__) = vals_r__[pos__++];
            }


            // initialize transformed data variables
            current_statement_begin__ = 861;
            validate_non_negative_index("sqrt_y", "(logical_eq(family, 3) ? len_y : 0 )", (logical_eq(family, 3) ? len_y : 0 ));
            sqrt_y = Eigen::Matrix<double, Eigen::Dynamic, 1>((logical_eq(family, 3) ? len_y : 0 ));
            stan::math::fill(sqrt_y, DUMMY_VAR__);

            current_statement_begin__ = 862;
            validate_non_negative_index("log_y", "(logical_eq(family, 3) ? len_y : 0 )", (logical_eq(family, 3) ? len_y : 0 ));
            log_y = Eigen::Matrix<double, Eigen::Dynamic, 1>((logical_eq(family, 3) ? len_y : 0 ));
            stan::math::fill(log_y, DUMMY_VAR__);

            current_statement_begin__ = 863;
            sum_log_y = double(0);
            stan::math::fill(sum_log_y, DUMMY_VAR__);
            stan::math::assign(sum_log_y,(logical_eq(family, 1) ? stan::math::not_a_number() : sum(stan::math::log(y)) ));

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

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

            current_statement_begin__ = 866;
            can_do_OLS = int(0);
            stan::math::fill(can_do_OLS, std::numeric_limits<int>::min());
            stan::math::assign(can_do_OLS,(primitive_value((primitive_value((primitive_value((primitive_value((primitive_value((primitive_value((primitive_value((primitive_value(logical_eq(family, 1)) && primitive_value(logical_eq(link, 1)))) && primitive_value(logical_eq(SSfun, 0)))) && primitive_value(logical_eq(has_offset, 0)))) && primitive_value(logical_eq(t, 0)))) && primitive_value(logical_eq(prior_PD, 0)))) && primitive_value(dense_X))) && primitive_value(logical_gt(N, 2)))) && primitive_value(logical_gte(len_y, ((has_intercept + K) + K_smooth)))));

            current_statement_begin__ = 868;
            validate_non_negative_index("OLS", "(can_do_OLS ? ((has_intercept + K) + K_smooth) : 0 )", (can_do_OLS ? ((has_intercept + K) + K_smooth) : 0 ));
            OLS = Eigen::Matrix<double, Eigen::Dynamic, 1>((can_do_OLS ? ((has_intercept + K) + K_smooth) : 0 ));
            stan::math::fill(OLS, DUMMY_VAR__);

            current_statement_begin__ = 869;
            validate_non_negative_index("XtX", "(can_do_OLS ? ((has_intercept + K) + K_smooth) : 0 )", (can_do_OLS ? ((has_intercept + K) + K_smooth) : 0 ));
            validate_non_negative_index("XtX", "(can_do_OLS ? ((has_intercept + K) + K_smooth) : 0 )", (can_do_OLS ? ((has_intercept + K) + K_smooth) : 0 ));
            XtX = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>((can_do_OLS ? ((has_intercept + K) + K_smooth) : 0 ), (can_do_OLS ? ((has_intercept + K) + K_smooth) : 0 ));
            stan::math::fill(XtX, DUMMY_VAR__);

            current_statement_begin__ = 870;
            can_do_normalidglm = int(0);
            stan::math::fill(can_do_normalidglm, std::numeric_limits<int>::min());
            stan::math::assign(can_do_normalidglm,(primitive_value((primitive_value((primitive_value((primitive_value((primitive_value((primitive_value((primitive_value((primitive_value(logical_eq(can_do_OLS, 0)) && primitive_value(logical_eq(family, 1)))) && primitive_value(logical_eq(link, 1)))) && primitive_value(logical_eq(SSfun, 0)))) && primitive_value(logical_eq(has_offset, 0)))) && primitive_value(logical_eq(t, 0)))) && primitive_value(logical_eq(prior_PD, 0)))) && primitive_value(dense_X))) && primitive_value(logical_lt(len_y, ((has_intercept + K) + K_smooth)))));

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

            current_statement_begin__ = 874;
            SSR = double(0);
            stan::math::fill(SSR, DUMMY_VAR__);
            stan::math::assign(SSR,stan::math::not_a_number());

            current_statement_begin__ = 876;
            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__ = 877;
            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__ = 878;
            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__ = 879;
            is_continuous = int(0);
            stan::math::fill(is_continuous, std::numeric_limits<int>::min());
            stan::math::assign(is_continuous,0);

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

            current_statement_begin__ = 881;
            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__ = 882;
            hs = int(0);
            stan::math::fill(hs, std::numeric_limits<int>::min());

            // execute transformed data statements
            current_statement_begin__ = 883;
            if (as_bool(logical_lte(prior_dist, 2))) {
                current_statement_begin__ = 883;
                stan::math::assign(hs, 0);
            } else if (as_bool(logical_eq(prior_dist, 3))) {
                current_statement_begin__ = 884;
                stan::math::assign(hs, 2);
            } else if (as_bool(logical_eq(prior_dist, 4))) {
                current_statement_begin__ = 885;
                stan::math::assign(hs, 4);
            } else {
                current_statement_begin__ = 886;
                stan::math::assign(hs, 0);
            }
            current_statement_begin__ = 888;
            for (int i = 1; i <= t; ++i) {

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

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

                        current_statement_begin__ = 891;
                        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__ = 892;
                        stan::math::assign(pos, (pos + 1));
                    }
                }
                current_statement_begin__ = 895;
                for (int j = 3; j <= get_base1(p, i, "p", 1); ++j) {
                    current_statement_begin__ = 895;
                    stan::math::assign(len_z_T, (len_z_T + (get_base1(p, i, "p", 1) - 1)));
                }
            }
            current_statement_begin__ = 898;
            if (as_bool(logical_lte(prior_dist_z, 2))) {
                current_statement_begin__ = 898;
                stan::math::assign(hs_z, 0);
            } else if (as_bool(logical_eq(prior_dist_z, 3))) {
                current_statement_begin__ = 899;
                stan::math::assign(hs_z, 2);
            } else if (as_bool(logical_eq(prior_dist_z, 4))) {
                current_statement_begin__ = 900;
                stan::math::assign(hs_z, 4);
            } else {
                current_statement_begin__ = 901;
                stan::math::assign(hs_z, 0);
            }
            current_statement_begin__ = 902;
            stan::math::assign(is_continuous, 1);
            current_statement_begin__ = 904;
            if (as_bool(logical_eq(family, 3))) {

                current_statement_begin__ = 905;
                stan::math::assign(sqrt_y, stan::math::sqrt(y));
                current_statement_begin__ = 906;
                stan::math::assign(log_y, stan::math::log(y));
            }
            current_statement_begin__ = 908;
            if (as_bool(can_do_OLS)) {
                {
                current_statement_begin__ = 909;
                validate_non_negative_index("X_", "N", N);
                validate_non_negative_index("X_", "((has_intercept + K) + K_smooth)", ((has_intercept + K) + K_smooth));
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, Eigen::Dynamic> X_(N, ((has_intercept + K) + K_smooth));
                stan::math::initialize(X_, DUMMY_VAR__);
                stan::math::fill(X_, DUMMY_VAR__);
                stan::math::assign(X_,(has_intercept ? stan::math::promote_scalar<double>(append_col(rep_vector(1.0, N), (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)) ))) : stan::math::promote_scalar<double>((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)) )) ));

                current_statement_begin__ = 912;
                validate_non_negative_index("R", "cols(X_)", cols(X_));
                validate_non_negative_index("R", "cols(X_)", cols(X_));
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, Eigen::Dynamic> R(cols(X_), cols(X_));
                stan::math::initialize(R, DUMMY_VAR__);
                stan::math::fill(R, DUMMY_VAR__);
                stan::math::assign(R,qr_thin_R(X_));


                current_statement_begin__ = 913;
                if (as_bool(logical_gt(get_base1(tail(diagonal(R), 1), 1, "tail(diagonal(R), 1)", 1), 1e-16))) {
                    {
                    current_statement_begin__ = 914;
                    validate_non_negative_index("Q", "N", N);
                    validate_non_negative_index("Q", "cols(R)", cols(R));
                    Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, Eigen::Dynamic> Q(N, cols(R));
                    stan::math::initialize(Q, DUMMY_VAR__);
                    stan::math::fill(Q, DUMMY_VAR__);
                    stan::math::assign(Q,qr_thin_Q(X_));


                    current_statement_begin__ = 915;
                    stan::math::assign(XtX, crossprod(X_));
                    current_statement_begin__ = 916;
                    stan::math::assign(OLS, transpose(mdivide_right_tri_low(multiply(transpose(y), Q), transpose(R))));
                    current_statement_begin__ = 917;
                    stan::math::assign(SSR, dot_self(subtract(y, multiply(X_, OLS))));
                    }
                } else {
                    current_statement_begin__ = 918;
                    stan::math::assign(can_do_OLS, 0);
                }
                }
            }
            current_statement_begin__ = 920;
            if (as_bool(can_do_normalidglm)) {

                current_statement_begin__ = 921;
                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__ = 864;
            size_t V_i_0_max__ = (special_case ? t : 0 );
            size_t V_i_1_max__ = len_y;
            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__ = 865;
            check_greater_or_equal(function__, "hs_z", hs_z, 0);

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

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

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

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

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

            current_statement_begin__ = 881;
            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__ = 882;
            check_greater_or_equal(function__, "hs", hs, 0);


            // validate, set parameter ranges
            num_params_r__ = 0U;
            param_ranges_i__.clear();
            current_statement_begin__ = 925;
            validate_non_negative_index("gamma", "has_intercept", has_intercept);
            num_params_r__ += (1 * has_intercept);
            current_statement_begin__ = 927;
            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__ = 928;
            validate_non_negative_index("z_beta_smooth", "K_smooth", K_smooth);
            num_params_r__ += K_smooth;
            current_statement_begin__ = 929;
            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__ = 930;
            validate_non_negative_index("global", "hs", hs);
            num_params_r__ += (1 * hs);
            current_statement_begin__ = 931;
            validate_non_negative_index("local", "K", K);
            validate_non_negative_index("local", "hs", hs);
            num_params_r__ += (K * hs);
            current_statement_begin__ = 932;
            validate_non_negative_index("caux", "logical_gt(hs, 0)", logical_gt(hs, 0));
            num_params_r__ += (1 * logical_gt(hs, 0));
            current_statement_begin__ = 933;
            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__ = 934;
            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__ = 935;
            validate_non_negative_index("z_b", "q", q);
            num_params_r__ += q;
            current_statement_begin__ = 936;
            validate_non_negative_index("z_T", "len_z_T", len_z_T);
            num_params_r__ += len_z_T;
            current_statement_begin__ = 937;
            validate_non_negative_index("rho", "len_rho", len_rho);
            num_params_r__ += len_rho;
            current_statement_begin__ = 938;
            validate_non_negative_index("zeta", "len_concentration", len_concentration);
            num_params_r__ += len_concentration;
            current_statement_begin__ = 939;
            validate_non_negative_index("tau", "t", t);
            num_params_r__ += t;
            current_statement_begin__ = 940;
            num_params_r__ += 1;
            current_statement_begin__ = 941;
            validate_non_negative_index("z_omega", "(logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim )", (logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim ));
            num_params_r__ += (logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim );
            current_statement_begin__ = 942;
            validate_non_negative_index("gamma_z", "has_intercept_z", has_intercept_z);
            num_params_r__ += (1 * has_intercept_z);
            current_statement_begin__ = 943;
            validate_non_negative_index("global_z", "hs_z", hs_z);
            num_params_r__ += (1 * hs_z);
            current_statement_begin__ = 944;
            validate_non_negative_index("local_z", "z_dim", z_dim);
            validate_non_negative_index("local_z", "hs_z", hs_z);
            num_params_r__ += (z_dim * hs_z);
            current_statement_begin__ = 945;
            validate_non_negative_index("caux_z", "logical_gt(hs_z, 0)", logical_gt(hs_z, 0));
            num_params_r__ += (1 * logical_gt(hs_z, 0));
            current_statement_begin__ = 946;
            validate_non_negative_index("S_z", "z_dim", z_dim);
            validate_non_negative_index("S_z", "(primitive_value(logical_eq(prior_dist_z, 5)) || primitive_value(logical_eq(prior_dist_z, 6)))", (primitive_value(logical_eq(prior_dist_z, 5)) || primitive_value(logical_eq(prior_dist_z, 6))));
            num_params_r__ += (z_dim * (primitive_value(logical_eq(prior_dist_z, 5)) || primitive_value(logical_eq(prior_dist_z, 6))));
            current_statement_begin__ = 947;
            validate_non_negative_index("one_over_lambda_z", "logical_eq(prior_dist_z, 6)", logical_eq(prior_dist_z, 6));
            num_params_r__ += (1 * logical_eq(prior_dist_z, 6));
        } 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_continuous() { }


    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__ = 925;
        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_lub_unconstrain(make_lower(family, link, pstream__), make_upper(family, link, pstream__), 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__ = 927;
        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__ = 928;
        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__ = 929;
        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__ = 930;
        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__ = 931;
        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__ = 932;
        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__ = 933;
        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__ = 934;
        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__ = 935;
        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__ = 936;
        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__ = 937;
        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__ = 938;
        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__ = 939;
        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__ = 940;
        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;
        context__.validate_dims("parameter initialization", "aux_unscaled", "double", context__.to_vec());
        double aux_unscaled(0);
        aux_unscaled = vals_r__[pos__++];
        try {
            writer__.scalar_lb_unconstrain(0, aux_unscaled);
        } 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__ = 941;
        if (!(context__.contains_r("z_omega")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable z_omega missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("z_omega");
        pos__ = 0U;
        validate_non_negative_index("z_omega", "(logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim )", (logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim ));
        context__.validate_dims("parameter initialization", "z_omega", "vector_d", context__.to_vec((logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim )));
        Eigen::Matrix<double, Eigen::Dynamic, 1> z_omega((logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim ));
        size_t z_omega_j_1_max__ = (logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim );
        for (size_t j_1__ = 0; j_1__ < z_omega_j_1_max__; ++j_1__) {
            z_omega(j_1__) = vals_r__[pos__++];
        }
        try {
            writer__.vector_unconstrain(z_omega);
        } catch (const std::exception& e) {
            stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable z_omega: ") + e.what()), current_statement_begin__, prog_reader__());
        }

        current_statement_begin__ = 942;
        if (!(context__.contains_r("gamma_z")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable gamma_z missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("gamma_z");
        pos__ = 0U;
        validate_non_negative_index("gamma_z", "has_intercept_z", has_intercept_z);
        context__.validate_dims("parameter initialization", "gamma_z", "double", context__.to_vec(has_intercept_z));
        std::vector<double> gamma_z(has_intercept_z, double(0));
        size_t gamma_z_k_0_max__ = has_intercept_z;
        for (size_t k_0__ = 0; k_0__ < gamma_z_k_0_max__; ++k_0__) {
            gamma_z[k_0__] = vals_r__[pos__++];
        }
        size_t gamma_z_i_0_max__ = has_intercept_z;
        for (size_t i_0__ = 0; i_0__ < gamma_z_i_0_max__; ++i_0__) {
            try {
                writer__.scalar_lb_unconstrain((logical_lte(link_phi, 1) ? stan::math::promote_scalar<double>(stan::math::negative_infinity()) : stan::math::promote_scalar<double>(0) ), gamma_z[i_0__]);
            } catch (const std::exception& e) {
                stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable gamma_z: ") + e.what()), current_statement_begin__, prog_reader__());
            }
        }

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

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

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

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

        current_statement_begin__ = 947;
        if (!(context__.contains_r("one_over_lambda_z")))
            stan::lang::rethrow_located(std::runtime_error(std::string("Variable one_over_lambda_z missing")), current_statement_begin__, prog_reader__());
        vals_r__ = context__.vals_r("one_over_lambda_z");
        pos__ = 0U;
        validate_non_negative_index("one_over_lambda_z", "logical_eq(prior_dist_z, 6)", logical_eq(prior_dist_z, 6));
        context__.validate_dims("parameter initialization", "one_over_lambda_z", "double", context__.to_vec(logical_eq(prior_dist_z, 6)));
        std::vector<double> one_over_lambda_z(logical_eq(prior_dist_z, 6), double(0));
        size_t one_over_lambda_z_k_0_max__ = logical_eq(prior_dist_z, 6);
        for (size_t k_0__ = 0; k_0__ < one_over_lambda_z_k_0_max__; ++k_0__) {
            one_over_lambda_z[k_0__] = vals_r__[pos__++];
        }
        size_t one_over_lambda_z_i_0_max__ = logical_eq(prior_dist_z, 6);
        for (size_t i_0__ = 0; i_0__ < one_over_lambda_z_i_0_max__; ++i_0__) {
            try {
                writer__.scalar_lb_unconstrain(0, one_over_lambda_z[i_0__]);
            } catch (const std::exception& e) {
                stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable one_over_lambda_z: ") + 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__ = 925;
            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_lub_constrain(make_lower(family, link, pstream__), make_upper(family, link, pstream__), lp__));
                else
                    gamma.push_back(in__.scalar_lub_constrain(make_lower(family, link, pstream__), make_upper(family, link, pstream__)));
            }

            current_statement_begin__ = 927;
            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__ = 928;
            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__ = 929;
            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__ = 930;
            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__ = 931;
            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__ = 932;
            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__ = 933;
            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__ = 934;
            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__ = 935;
            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__ = 936;
            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__ = 937;
            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__ = 938;
            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__ = 939;
            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__ = 940;
            local_scalar_t__ aux_unscaled;
            (void) aux_unscaled;  // dummy to suppress unused var warning
            if (jacobian__)
                aux_unscaled = in__.scalar_lb_constrain(0, lp__);
            else
                aux_unscaled = in__.scalar_lb_constrain(0);

            current_statement_begin__ = 941;
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> z_omega;
            (void) z_omega;  // dummy to suppress unused var warning
            if (jacobian__)
                z_omega = in__.vector_constrain((logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim ), lp__);
            else
                z_omega = in__.vector_constrain((logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim ));

            current_statement_begin__ = 942;
            std::vector<local_scalar_t__> gamma_z;
            size_t gamma_z_d_0_max__ = has_intercept_z;
            gamma_z.reserve(gamma_z_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < gamma_z_d_0_max__; ++d_0__) {
                if (jacobian__)
                    gamma_z.push_back(in__.scalar_lb_constrain((logical_lte(link_phi, 1) ? stan::math::promote_scalar<double>(stan::math::negative_infinity()) : stan::math::promote_scalar<double>(0) ), lp__));
                else
                    gamma_z.push_back(in__.scalar_lb_constrain((logical_lte(link_phi, 1) ? stan::math::promote_scalar<double>(stan::math::negative_infinity()) : stan::math::promote_scalar<double>(0) )));
            }

            current_statement_begin__ = 943;
            std::vector<local_scalar_t__> global_z;
            size_t global_z_d_0_max__ = hs_z;
            global_z.reserve(global_z_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < global_z_d_0_max__; ++d_0__) {
                if (jacobian__)
                    global_z.push_back(in__.scalar_lb_constrain(0, lp__));
                else
                    global_z.push_back(in__.scalar_lb_constrain(0));
            }

            current_statement_begin__ = 944;
            std::vector<Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> > local_z;
            size_t local_z_d_0_max__ = hs_z;
            local_z.reserve(local_z_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < local_z_d_0_max__; ++d_0__) {
                if (jacobian__)
                    local_z.push_back(in__.vector_lb_constrain(0, z_dim, lp__));
                else
                    local_z.push_back(in__.vector_lb_constrain(0, z_dim));
            }

            current_statement_begin__ = 945;
            std::vector<local_scalar_t__> caux_z;
            size_t caux_z_d_0_max__ = logical_gt(hs_z, 0);
            caux_z.reserve(caux_z_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < caux_z_d_0_max__; ++d_0__) {
                if (jacobian__)
                    caux_z.push_back(in__.scalar_lb_constrain(0, lp__));
                else
                    caux_z.push_back(in__.scalar_lb_constrain(0));
            }

            current_statement_begin__ = 946;
            std::vector<Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> > S_z;
            size_t S_z_d_0_max__ = (primitive_value(logical_eq(prior_dist_z, 5)) || primitive_value(logical_eq(prior_dist_z, 6)));
            S_z.reserve(S_z_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < S_z_d_0_max__; ++d_0__) {
                if (jacobian__)
                    S_z.push_back(in__.vector_lb_constrain(0, z_dim, lp__));
                else
                    S_z.push_back(in__.vector_lb_constrain(0, z_dim));
            }

            current_statement_begin__ = 947;
            std::vector<local_scalar_t__> one_over_lambda_z;
            size_t one_over_lambda_z_d_0_max__ = logical_eq(prior_dist_z, 6);
            one_over_lambda_z.reserve(one_over_lambda_z_d_0_max__);
            for (size_t d_0__ = 0; d_0__ < one_over_lambda_z_d_0_max__; ++d_0__) {
                if (jacobian__)
                    one_over_lambda_z.push_back(in__.scalar_lb_constrain(0, lp__));
                else
                    one_over_lambda_z.push_back(in__.scalar_lb_constrain(0));
            }

            // transformed parameters
            current_statement_begin__ = 951;
            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,(logical_eq(prior_dist_for_aux, 0) ? stan::math::promote_scalar<local_scalar_t__>(aux_unscaled) : stan::math::promote_scalar<local_scalar_t__>((logical_lte(prior_dist_for_aux, 2) ? stan::math::promote_scalar<local_scalar_t__>(((prior_scale_for_aux * aux_unscaled) + prior_mean_for_aux)) : stan::math::promote_scalar<local_scalar_t__>((prior_scale_for_aux * aux_unscaled)) )) ));

            current_statement_begin__ = 955;
            validate_non_negative_index("omega", "z_dim", z_dim);
            Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> omega(z_dim);
            stan::math::initialize(omega, DUMMY_VAR__);
            stan::math::fill(omega, DUMMY_VAR__);

            current_statement_begin__ = 957;
            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__ = 958;
            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__ = 959;
            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__ = 960;
            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__ = 961;
            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__ = 962;
            if (as_bool(logical_eq(prior_dist, 0))) {
                current_statement_begin__ = 962;
                stan::math::assign(beta, z_beta);
            } else if (as_bool(logical_eq(prior_dist, 1))) {
                current_statement_begin__ = 963;
                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__ = 964;
                for (int k = 1; k <= K; ++k) {

                    current_statement_begin__ = 965;
                    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__ = 968;
                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__ = 969;
                if (as_bool((primitive_value(logical_eq(is_continuous, 1)) && primitive_value(logical_eq(family, 1))))) {
                    current_statement_begin__ = 970;
                    stan::math::assign(beta, hs_prior(z_beta, global, local, global_prior_scale, aux, c2, pstream__));
                } else {
                    current_statement_begin__ = 971;
                    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__ = 974;
                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__ = 975;
                if (as_bool((primitive_value(logical_eq(is_continuous, 1)) && primitive_value(logical_eq(family, 1))))) {
                    current_statement_begin__ = 976;
                    stan::math::assign(beta, hsplus_prior(z_beta, global, local, global_prior_scale, aux, c2, pstream__));
                } else {
                    current_statement_begin__ = 977;
                    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__ = 980;
                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__ = 982;
                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__ = 984;
                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__ = 985;
                for (int k = 1; k <= K; ++k) {

                    current_statement_begin__ = 986;
                    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__ = 987;
                    stan::math::assign(z_pos, (z_pos + 1));
                    current_statement_begin__ = 988;
                    for (int n = 2; n <= get_base1(num_normals, k, "num_normals", 1); ++n) {

                        current_statement_begin__ = 989;
                        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__ = 990;
                        stan::math::assign(z_pos, (z_pos + 1));
                    }
                    current_statement_begin__ = 992;
                    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__ = 993;
                    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__ = 997;
            if (as_bool(K_smooth)) {

                current_statement_begin__ = 998;
                stan::math::assign(smooth_sd, add(prior_mean_for_smooth, elt_multiply(prior_scale_for_smooth, smooth_sd_raw)));
                current_statement_begin__ = 999;
                if (as_bool((primitive_value(is_continuous) && primitive_value(logical_eq(family, 1))))) {
                    current_statement_begin__ = 999;
                    stan::math::assign(smooth_sd, multiply(smooth_sd, aux));
                }
                current_statement_begin__ = 1000;
                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__ = 1002;
            if (as_bool(logical_eq(prior_dist_z, 0))) {
                current_statement_begin__ = 1002;
                stan::math::assign(omega, z_omega);
            } else if (as_bool(logical_eq(prior_dist_z, 1))) {
                current_statement_begin__ = 1003;
                stan::math::assign(omega, add(elt_multiply(z_omega, prior_scale_z), prior_mean_z));
            } else if (as_bool(logical_eq(prior_dist_z, 2))) {
                current_statement_begin__ = 1004;
                for (int k = 1; k <= z_dim; ++k) {
                    {
                    current_statement_begin__ = 1005;
                    local_scalar_t__ left(DUMMY_VAR__);
                    (void) left;  // dummy to suppress unused var warning
                    stan::math::initialize(left, DUMMY_VAR__);
                    stan::math::fill(left, DUMMY_VAR__);
                    stan::math::assign(left,CFt(get_base1(omega, k, "omega", 1), get_base1(prior_df_z, k, "prior_df_z", 1), pstream__));


                    current_statement_begin__ = 1006;
                    stan::model::assign(omega, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                ((left * get_base1(prior_scale_z, k, "prior_scale_z", 1)) + get_base1(prior_mean_z, k, "prior_mean_z", 1)), 
                                "assigning variable omega");
                    }
                }
            } else if (as_bool(logical_eq(prior_dist_z, 3))) {
                current_statement_begin__ = 1009;
                stan::math::assign(omega, hs_prior(z_omega, global_z, local_z, global_prior_scale, 1, (square(slab_scale_z) * get_base1(caux_z, 1, "caux_z", 1)), pstream__));
            } else if (as_bool(logical_eq(prior_dist_z, 4))) {
                current_statement_begin__ = 1012;
                stan::math::assign(omega, hsplus_prior(z_omega, global_z, local_z, global_prior_scale, 1, (square(slab_scale_z) * get_base1(caux_z, 1, "caux_z", 1)), pstream__));
            } else if (as_bool(logical_eq(prior_dist_z, 5))) {
                current_statement_begin__ = 1015;
                stan::math::assign(omega, add(prior_mean_z, elt_multiply(elt_multiply(prior_scale_z, stan::math::sqrt(multiply(2, get_base1(S_z, 1, "S_z", 1)))), z_omega)));
            } else if (as_bool(logical_eq(prior_dist_z, 6))) {
                current_statement_begin__ = 1017;
                stan::math::assign(omega, add(prior_mean_z, elt_multiply(elt_multiply(multiply(get_base1(one_over_lambda_z, 1, "one_over_lambda_z", 1), prior_scale_z), stan::math::sqrt(multiply(2, get_base1(S_z, 1, "S_z", 1)))), z_omega)));
            } else if (as_bool(logical_eq(prior_dist_z, 7))) {
                {
                current_statement_begin__ = 1019;
                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__ = 1020;
                for (int k = 1; k <= z_dim; ++k) {

                    current_statement_begin__ = 1021;
                    stan::model::assign(omega, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                get_base1(z_omega, z_pos, "z_omega", 1), 
                                "assigning variable omega");
                    current_statement_begin__ = 1022;
                    stan::math::assign(z_pos, (z_pos + 1));
                    current_statement_begin__ = 1023;
                    for (int n = 2; n <= get_base1(num_normals_z, k, "num_normals_z", 1); ++n) {

                        current_statement_begin__ = 1024;
                        stan::model::assign(omega, 
                                    stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                    (stan::model::rvalue(omega, stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), "omega") * get_base1(z_omega, z_pos, "z_omega", 1)), 
                                    "assigning variable omega");
                        current_statement_begin__ = 1025;
                        stan::math::assign(z_pos, (z_pos + 1));
                    }
                    current_statement_begin__ = 1027;
                    stan::model::assign(omega, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                (stan::model::rvalue(omega, stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), "omega") * pow(get_base1(prior_scale_z, k, "prior_scale_z", 1), get_base1(num_normals_z, k, "num_normals_z", 1))), 
                                "assigning variable omega");
                    current_statement_begin__ = 1028;
                    stan::model::assign(omega, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                (stan::model::rvalue(omega, stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), "omega") + get_base1(prior_mean_z, k, "prior_mean_z", 1)), 
                                "assigning variable omega");
                }
                }
            }
            current_statement_begin__ = 1033;
            if (as_bool(logical_eq(prior_dist_for_aux, 0))) {
                current_statement_begin__ = 1034;
                stan::math::assign(aux, aux_unscaled);
            } else {

                current_statement_begin__ = 1036;
                stan::math::assign(aux, (prior_scale_for_aux * aux_unscaled));
                current_statement_begin__ = 1037;
                if (as_bool(logical_lte(prior_dist_for_aux, 2))) {
                    current_statement_begin__ = 1038;
                    stan::math::assign(aux, (aux + prior_mean_for_aux));
                }
            }
            current_statement_begin__ = 1041;
            if (as_bool(logical_gt(t, 0))) {

                current_statement_begin__ = 1042;
                if (as_bool(logical_eq(special_case, 1))) {
                    {
                    current_statement_begin__ = 1043;
                    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__ = 1044;
                    stan::math::assign(theta_L, multiply(elt_multiply(scale, tau), aux));
                    current_statement_begin__ = 1045;
                    if (as_bool(logical_eq(t, 1))) {
                        current_statement_begin__ = 1045;
                        stan::math::assign(b, multiply(get_base1(theta_L, 1, "theta_L", 1), z_b));
                    } else {
                        current_statement_begin__ = 1046;
                        for (int i = 1; i <= t; ++i) {
                            {
                            current_statement_begin__ = 1047;
                            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__ = 1048;
                            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__ = 1049;
                            stan::math::assign(start, (end + 1));
                            }
                        }
                    }
                    }
                } else {

                    current_statement_begin__ = 1053;
                    stan::math::assign(theta_L, make_theta_L(len_theta_L, p, aux, tau, scale, zeta, rho, z_T, pstream__));
                    current_statement_begin__ = 1055;
                    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__ = 951;
            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__ = 955;
            size_t omega_j_1_max__ = z_dim;
            for (size_t j_1__ = 0; j_1__ < omega_j_1_max__; ++j_1__) {
                if (stan::math::is_uninitialized(omega(j_1__))) {
                    std::stringstream msg__;
                    msg__ << "Undefined transformed parameter: omega" << "(" << j_1__ << ")";
                    stan::lang::rethrow_located(std::runtime_error(std::string("Error initializing variable omega: ") + msg__.str()), current_statement_begin__, prog_reader__());
                }
            }
            current_statement_begin__ = 957;
            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__ = 958;
            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__ = 959;
            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__ = 960;
            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__ = 961;
            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__ = 1060;
            if (as_bool(can_do_OLS)) {
                {
                current_statement_begin__ = 1061;
                validate_non_negative_index("coeff", "cols(XtX)", cols(XtX));
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> coeff(cols(XtX));
                stan::math::initialize(coeff, DUMMY_VAR__);
                stan::math::fill(coeff, DUMMY_VAR__);
                stan::math::assign(coeff,(has_intercept ? stan::math::promote_scalar<local_scalar_t__>(append_row(to_vector(gamma), (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) ))) : stan::math::promote_scalar<local_scalar_t__>((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__ = 1064;
                lp_accum__.add(ll_mvn_ols(coeff, OLS, XtX, SSR, aux, N, pstream__));
                }
            } else if (as_bool(can_do_normalidglm)) {
                {
                current_statement_begin__ = 1066;
                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__ = 1067;
                lp_accum__.add(normal_id_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__ = 1069;
                validate_non_negative_index("eta_z", "(logical_gt(link_phi, 0) ? N : 0 )", (logical_gt(link_phi, 0) ? N : 0 ));
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> eta_z((logical_gt(link_phi, 0) ? N : 0 ));
                stan::math::initialize(eta_z, DUMMY_VAR__);
                stan::math::fill(eta_z, DUMMY_VAR__);

                current_statement_begin__ = 1070;
                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__ = 1071;
                if (as_bool(logical_gt(K, 0))) {

                    current_statement_begin__ = 1072;
                    if (as_bool(dense_X)) {
                        current_statement_begin__ = 1072;
                        stan::math::assign(eta, multiply(get_base1(X, 1, "X", 1), beta));
                    } else {
                        current_statement_begin__ = 1073;
                        stan::math::assign(eta, csr_matrix_times_vector2(N, K, w_X, v_X, u_X, beta, pstream__));
                    }
                } else {
                    current_statement_begin__ = 1075;
                    stan::math::assign(eta, rep_vector(0.0, N));
                }
                current_statement_begin__ = 1076;
                if (as_bool(logical_eq(has_offset, 1))) {
                    current_statement_begin__ = 1076;
                    stan::math::assign(eta, add(eta, offset));
                }
                current_statement_begin__ = 1077;
                if (as_bool(K_smooth)) {
                    current_statement_begin__ = 1077;
                    stan::math::assign(eta, add(eta, multiply(S, beta_smooth)));
                }
                current_statement_begin__ = 1078;
                if (as_bool(logical_gt(t, 0))) {

                    current_statement_begin__ = 1079;
                    if (as_bool(special_case)) {
                        current_statement_begin__ = 1079;
                        for (int i = 1; i <= t; ++i) {
                            current_statement_begin__ = 1079;
                            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__ = 1080;
                        stan::math::assign(eta, add(eta, csr_matrix_times_vector2(N, q, w, v, u, b, pstream__)));
                    }
                }
                current_statement_begin__ = 1082;
                if (as_bool(logical_eq(has_intercept, 1))) {

                    current_statement_begin__ = 1083;
                    if (as_bool((primitive_value((primitive_value(logical_eq(family, 1)) || primitive_value(logical_eq(link, 2)))) || primitive_value((primitive_value(logical_eq(family, 4)) && primitive_value(logical_neq(link, 5))))))) {
                        current_statement_begin__ = 1083;
                        stan::math::assign(eta, add(eta, get_base1(gamma, 1, "gamma", 1)));
                    } else if (as_bool((primitive_value(logical_eq(family, 4)) && primitive_value(logical_eq(link, 5))))) {
                        current_statement_begin__ = 1084;
                        stan::math::assign(eta, add(eta, (get_base1(gamma, 1, "gamma", 1) - max(eta))));
                    } else {
                        current_statement_begin__ = 1085;
                        stan::math::assign(eta, add(eta, (get_base1(gamma, 1, "gamma", 1) - min(eta))));
                    }
                } else {

                    current_statement_begin__ = 1089;
                    stan::math::assign(eta, add(eta, dot_product(xbar, beta)));
                }
                current_statement_begin__ = 1092;
                if (as_bool(logical_gt(SSfun, 0))) {
                    {
                    current_statement_begin__ = 1093;
                    validate_non_negative_index("P", "len_y", len_y);
                    validate_non_negative_index("P", "K", K);
                    Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, Eigen::Dynamic> P(len_y, K);
                    stan::math::initialize(P, DUMMY_VAR__);
                    stan::math::fill(P, DUMMY_VAR__);
                    stan::math::assign(P,reshape_vec(eta, len_y, K, pstream__));


                    current_statement_begin__ = 1094;
                    if (as_bool(logical_lt(SSfun, 5))) {

                        current_statement_begin__ = 1095;
                        if (as_bool(logical_lte(SSfun, 2))) {

                            current_statement_begin__ = 1096;
                            if (as_bool(logical_eq(SSfun, 1))) {
                                current_statement_begin__ = 1096;
                                lp_accum__.add(normal_log(y, SS_asymp(input, P, pstream__), aux));
                            } else {
                                current_statement_begin__ = 1097;
                                lp_accum__.add(normal_log(y, SS_asympOff(input, P, pstream__), aux));
                            }
                        } else if (as_bool(logical_eq(SSfun, 3))) {
                            current_statement_begin__ = 1099;
                            lp_accum__.add(normal_log(y, SS_asympOrig(input, P, pstream__), aux));
                        } else {

                            current_statement_begin__ = 1101;
                            for (int i = 1; i <= len_y; ++i) {
                                current_statement_begin__ = 1101;
                                stan::model::assign(P, 
                                            stan::model::cons_list(stan::model::index_uni(i), stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list())), 
                                            (stan::model::rvalue(P, stan::model::cons_list(stan::model::index_uni(i), stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list())), "P") + stan::math::exp(get_base1(P, i, 3, "P", 1))), 
                                            "assigning variable P");
                            }
                            current_statement_begin__ = 1102;
                            lp_accum__.add(normal_log(y, SS_biexp(input, P, pstream__), aux));
                        }
                    } else {

                        current_statement_begin__ = 1106;
                        if (as_bool(logical_lte(SSfun, 7))) {

                            current_statement_begin__ = 1107;
                            if (as_bool(logical_eq(SSfun, 5))) {
                                current_statement_begin__ = 1107;
                                lp_accum__.add(normal_log(y, SS_fol(Dose, input, P, pstream__), aux));
                            } else if (as_bool(logical_eq(SSfun, 6))) {
                                current_statement_begin__ = 1108;
                                lp_accum__.add(normal_log(y, SS_fpl(input, P, pstream__), aux));
                            } else {
                                current_statement_begin__ = 1109;
                                lp_accum__.add(normal_log(y, SS_gompertz(input, P, pstream__), aux));
                            }
                        } else {

                            current_statement_begin__ = 1112;
                            if (as_bool(logical_eq(SSfun, 8))) {
                                current_statement_begin__ = 1112;
                                lp_accum__.add(normal_log(y, SS_logis(input, P, pstream__), aux));
                            } else if (as_bool(logical_eq(SSfun, 9))) {
                                current_statement_begin__ = 1113;
                                lp_accum__.add(normal_log(y, SS_micmen(input, P, pstream__), aux));
                            } else {
                                current_statement_begin__ = 1114;
                                lp_accum__.add(normal_log(y, SS_weibull(input, P, pstream__), aux));
                            }
                        }
                    }
                    }
                } else if (as_bool(logical_eq(has_weights, 0))) {

                    current_statement_begin__ = 1119;
                    if (as_bool((primitive_value((primitive_value(logical_eq(family, 4)) && primitive_value(logical_gt(z_dim, 0)))) && primitive_value(logical_gt(link_phi, 0))))) {

                        current_statement_begin__ = 1120;
                        stan::math::assign(eta_z, multiply(betareg_z, omega));
                    } else if (as_bool((primitive_value((primitive_value(logical_eq(family, 4)) && primitive_value(logical_eq(z_dim, 0)))) && primitive_value(logical_eq(has_intercept_z, 1))))) {

                        current_statement_begin__ = 1123;
                        stan::math::assign(eta_z, rep_vector(0.0, N));
                    }
                    current_statement_begin__ = 1126;
                    if (as_bool(logical_eq(has_intercept_z, 1))) {

                        current_statement_begin__ = 1127;
                        if (as_bool(logical_gt(link_phi, 1))) {

                            current_statement_begin__ = 1128;
                            stan::math::assign(eta_z, add(eta_z, (get_base1(gamma_z, 1, "gamma_z", 1) - min(eta_z))));
                        } else {

                            current_statement_begin__ = 1131;
                            stan::math::assign(eta_z, add(eta_z, get_base1(gamma_z, 1, "gamma_z", 1)));
                        }
                    } else {

                        current_statement_begin__ = 1135;
                        if (as_bool(logical_gt(link_phi, 1))) {

                            current_statement_begin__ = 1136;
                            stan::math::assign(eta_z, add(eta_z, (dot_product(zbar, omega) - min(eta_z))));
                        } else {

                            current_statement_begin__ = 1139;
                            stan::math::assign(eta_z, add(eta_z, dot_product(zbar, omega)));
                        }
                    }
                    current_statement_begin__ = 1142;
                    if (as_bool(logical_eq(family, 1))) {

                        current_statement_begin__ = 1143;
                        if (as_bool(logical_eq(link, 1))) {
                            current_statement_begin__ = 1144;
                            lp_accum__.add(normal_log(y, eta, aux));
                        } else if (as_bool(logical_eq(link, 2))) {
                            current_statement_begin__ = 1146;
                            lp_accum__.add(normal_log(y, stan::math::exp(eta), aux));
                        } else {
                            current_statement_begin__ = 1148;
                            lp_accum__.add(normal_log(y, inv(eta), aux));
                        }
                    } else if (as_bool(logical_eq(family, 2))) {

                        current_statement_begin__ = 1151;
                        lp_accum__.add(GammaReg(y, eta, aux, link, sum_log_y, pstream__));
                    } else if (as_bool(logical_eq(family, 3))) {

                        current_statement_begin__ = 1154;
                        lp_accum__.add(inv_gaussian(y, linkinv_inv_gaussian(eta, link, pstream__), aux, sum_log_y, sqrt_y, pstream__));
                    } else if (as_bool((primitive_value(logical_eq(family, 4)) && primitive_value(logical_eq(link_phi, 0))))) {
                        {
                        current_statement_begin__ = 1158;
                        validate_non_negative_index("mu", "N", N);
                        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> mu(N);
                        stan::math::initialize(mu, DUMMY_VAR__);
                        stan::math::fill(mu, DUMMY_VAR__);


                        current_statement_begin__ = 1159;
                        stan::math::assign(mu, linkinv_beta(eta, link, pstream__));
                        current_statement_begin__ = 1160;
                        lp_accum__.add(beta_log(y, multiply(mu, aux), multiply(subtract(1, mu), aux)));
                        }
                    } else if (as_bool((primitive_value(logical_eq(family, 4)) && primitive_value(logical_gt(link_phi, 0))))) {
                        {
                        current_statement_begin__ = 1163;
                        validate_non_negative_index("mu", "N", N);
                        Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> mu(N);
                        stan::math::initialize(mu, DUMMY_VAR__);
                        stan::math::fill(mu, DUMMY_VAR__);

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


                        current_statement_begin__ = 1165;
                        stan::math::assign(mu, linkinv_beta(eta, link, pstream__));
                        current_statement_begin__ = 1166;
                        stan::math::assign(mu_z, linkinv_beta_z(eta_z, link_phi, pstream__));
                        current_statement_begin__ = 1167;
                        lp_accum__.add(beta_log(y, rows_dot_product(mu, mu_z), rows_dot_product(subtract(1, mu), mu_z)));
                        }
                    }
                } else {
                    {
                    current_statement_begin__ = 1172;
                    validate_non_negative_index("summands", "N", N);
                    Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> summands(N);
                    stan::math::initialize(summands, DUMMY_VAR__);
                    stan::math::fill(summands, DUMMY_VAR__);


                    current_statement_begin__ = 1173;
                    if (as_bool(logical_eq(family, 1))) {
                        current_statement_begin__ = 1173;
                        stan::math::assign(summands, pw_gauss(y, eta, aux, link, pstream__));
                    } else if (as_bool(logical_eq(family, 2))) {
                        current_statement_begin__ = 1174;
                        stan::math::assign(summands, pw_gamma(y, eta, aux, link, pstream__));
                    } else if (as_bool(logical_eq(family, 3))) {
                        current_statement_begin__ = 1175;
                        stan::math::assign(summands, pw_inv_gaussian(y, eta, aux, link, log_y, sqrt_y, pstream__));
                    } else if (as_bool((primitive_value(logical_eq(family, 4)) && primitive_value(logical_eq(link_phi, 0))))) {
                        current_statement_begin__ = 1176;
                        stan::math::assign(summands, pw_beta(y, eta, aux, link, pstream__));
                    } else if (as_bool((primitive_value(logical_eq(family, 4)) && primitive_value(logical_gt(link_phi, 0))))) {
                        current_statement_begin__ = 1177;
                        stan::math::assign(summands, pw_beta_z(y, eta, eta_z, link, link_phi, pstream__));
                    }
                    current_statement_begin__ = 1178;
                    lp_accum__.add(dot_product(weights, summands));
                    }
                }
                }
            }
            current_statement_begin__ = 1183;
            if (as_bool((primitive_value(logical_gt(prior_dist_for_aux, 0)) && primitive_value(logical_gt(prior_scale_for_aux, 0))))) {
                {
                current_statement_begin__ = 1184;
                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__ = 1185;
                if (as_bool(logical_eq(prior_dist_for_aux, 1))) {
                    current_statement_begin__ = 1186;
                    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__ = 1188;
                    lp_accum__.add((student_t_log(aux_unscaled, prior_df_for_aux, 0, 1) - log_half));
                } else {
                    current_statement_begin__ = 1190;
                    lp_accum__.add(exponential_log(aux_unscaled, 1));
                }
                }
            }
            current_statement_begin__ = 1194;
            if (as_bool(logical_eq(prior_dist, 1))) {
                current_statement_begin__ = 1194;
                lp_accum__.add(normal_log(z_beta, 0, 1));
            } else if (as_bool(logical_eq(prior_dist, 2))) {
                current_statement_begin__ = 1195;
                lp_accum__.add(normal_log(z_beta, 0, 1));
            } else if (as_bool(logical_eq(prior_dist, 3))) {
                {
                current_statement_begin__ = 1197;
                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__ = 1198;
                lp_accum__.add(normal_log(z_beta, 0, 1));
                current_statement_begin__ = 1199;
                lp_accum__.add((normal_log(get_base1(local, 1, "local", 1), 0, 1) - log_half));
                current_statement_begin__ = 1200;
                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__ = 1201;
                lp_accum__.add((normal_log(get_base1(global, 1, "global", 1), 0, 1) - log_half));
                current_statement_begin__ = 1202;
                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__ = 1203;
                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__ = 1206;
                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__ = 1207;
                lp_accum__.add(normal_log(z_beta, 0, 1));
                current_statement_begin__ = 1208;
                lp_accum__.add((normal_log(get_base1(local, 1, "local", 1), 0, 1) - log_half));
                current_statement_begin__ = 1209;
                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__ = 1210;
                lp_accum__.add((normal_log(get_base1(local, 3, "local", 1), 0, 1) - log_half));
                current_statement_begin__ = 1212;
                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__ = 1213;
                lp_accum__.add((normal_log(get_base1(global, 1, "global", 1), 0, 1) - log_half));
                current_statement_begin__ = 1214;
                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__ = 1215;
                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__ = 1218;
                lp_accum__.add(normal_log(z_beta, 0, 1));
                current_statement_begin__ = 1219;
                lp_accum__.add(exponential_log(get_base1(mix, 1, "mix", 1), 1));
            } else if (as_bool(logical_eq(prior_dist, 6))) {

                current_statement_begin__ = 1222;
                lp_accum__.add(normal_log(z_beta, 0, 1));
                current_statement_begin__ = 1223;
                lp_accum__.add(exponential_log(get_base1(mix, 1, "mix", 1), 1));
                current_statement_begin__ = 1224;
                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__ = 1227;
                lp_accum__.add(normal_log(z_beta, 0, 1));
            }
            current_statement_begin__ = 1232;
            if (as_bool(logical_eq(has_intercept, 1))) {

                current_statement_begin__ = 1233;
                if (as_bool(logical_eq(prior_dist_for_intercept, 1))) {
                    current_statement_begin__ = 1234;
                    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__ = 1236;
                    lp_accum__.add(student_t_log(gamma, prior_df_for_intercept, prior_mean_for_intercept, prior_scale_for_intercept));
                }
            }
            current_statement_begin__ = 1241;
            if (as_bool(K_smooth)) {

                current_statement_begin__ = 1242;
                lp_accum__.add(normal_log(z_beta_smooth, 0, 1));
                current_statement_begin__ = 1243;
                if (as_bool(logical_gt(prior_dist_for_smooth, 0))) {
                    {
                    current_statement_begin__ = 1244;
                    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__ = 1245;
                    if (as_bool(logical_eq(prior_dist_for_smooth, 1))) {
                        current_statement_begin__ = 1246;
                        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__ = 1248;
                        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__ = 1250;
                        lp_accum__.add(exponential_log(smooth_sd_raw, 1));
                    }
                    }
                }
            }
            current_statement_begin__ = 1254;
            if (as_bool(logical_eq(prior_dist_z, 1))) {
                current_statement_begin__ = 1254;
                lp_accum__.add(normal_log(z_omega, 0, 1));
            } else if (as_bool(logical_eq(prior_dist_z, 2))) {
                current_statement_begin__ = 1255;
                lp_accum__.add(normal_log(z_omega, 0, 1));
            } else if (as_bool(logical_eq(prior_dist_z, 3))) {
                {
                current_statement_begin__ = 1257;
                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__ = 1258;
                lp_accum__.add(normal_log(z_omega, 0, 1));
                current_statement_begin__ = 1259;
                lp_accum__.add((normal_log(get_base1(local_z, 1, "local_z", 1), 0, 1) - log_half));
                current_statement_begin__ = 1260;
                lp_accum__.add(inv_gamma_log(get_base1(local_z, 2, "local_z", 1), multiply(0.5, prior_df_z), multiply(0.5, prior_df_z)));
                current_statement_begin__ = 1261;
                lp_accum__.add((normal_log(get_base1(global_z, 1, "global_z", 1), 0, 1) - log_half));
                current_statement_begin__ = 1262;
                lp_accum__.add(inv_gamma_log(get_base1(global_z, 2, "global_z", 1), (0.5 * global_prior_df_z), (0.5 * global_prior_df_z)));
                current_statement_begin__ = 1263;
                lp_accum__.add(inv_gamma_log(caux_z, (0.5 * slab_df_z), (0.5 * slab_df_z)));
                }
            } else if (as_bool(logical_eq(prior_dist_z, 4))) {
                {
                current_statement_begin__ = 1266;
                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__ = 1267;
                lp_accum__.add(normal_log(z_omega, 0, 1));
                current_statement_begin__ = 1268;
                lp_accum__.add((normal_log(get_base1(local_z, 1, "local_z", 1), 0, 1) - log_half));
                current_statement_begin__ = 1269;
                lp_accum__.add(inv_gamma_log(get_base1(local_z, 2, "local_z", 1), multiply(0.5, prior_df_z), multiply(0.5, prior_df_z)));
                current_statement_begin__ = 1270;
                lp_accum__.add((normal_log(get_base1(local_z, 3, "local_z", 1), 0, 1) - log_half));
                current_statement_begin__ = 1272;
                lp_accum__.add(inv_gamma_log(get_base1(local_z, 4, "local_z", 1), multiply(0.5, prior_scale_z), multiply(0.5, prior_scale_z)));
                current_statement_begin__ = 1273;
                lp_accum__.add((normal_log(get_base1(global_z, 1, "global_z", 1), 0, 1) - log_half));
                current_statement_begin__ = 1274;
                lp_accum__.add(inv_gamma_log(get_base1(global_z, 2, "global_z", 1), 0.5, 0.5));
                current_statement_begin__ = 1275;
                lp_accum__.add(inv_gamma_log(caux_z, (0.5 * slab_df_z), (0.5 * slab_df_z)));
                }
            } else if (as_bool(logical_eq(prior_dist_z, 5))) {

                current_statement_begin__ = 1278;
                lp_accum__.add(normal_log(z_omega, 0, 1));
                current_statement_begin__ = 1279;
                lp_accum__.add(exponential_log(get_base1(S_z, 1, "S_z", 1), 1));
            } else if (as_bool(logical_eq(prior_dist_z, 6))) {

                current_statement_begin__ = 1282;
                lp_accum__.add(normal_log(z_omega, 0, 1));
                current_statement_begin__ = 1283;
                lp_accum__.add(exponential_log(get_base1(S_z, 1, "S_z", 1), 1));
                current_statement_begin__ = 1284;
                lp_accum__.add(chi_square_log(get_base1(one_over_lambda_z, 1, "one_over_lambda_z", 1), get_base1(prior_df_z, 1, "prior_df_z", 1)));
            } else if (as_bool(logical_eq(prior_dist_z, 7))) {

                current_statement_begin__ = 1287;
                lp_accum__.add(normal_log(z_omega, 0, 1));
            }
            current_statement_begin__ = 1292;
            if (as_bool(logical_eq(has_intercept_z, 1))) {

                current_statement_begin__ = 1293;
                if (as_bool(logical_eq(prior_dist_for_intercept_z, 1))) {
                    current_statement_begin__ = 1294;
                    lp_accum__.add(normal_log(gamma_z, prior_mean_for_intercept_z, prior_scale_for_intercept_z));
                } else if (as_bool(logical_eq(prior_dist_for_intercept_z, 2))) {
                    current_statement_begin__ = 1296;
                    lp_accum__.add(student_t_log(gamma_z, prior_df_for_intercept_z, prior_mean_for_intercept_z, prior_scale_for_intercept_z));
                }
            }
            current_statement_begin__ = 1300;
            if (as_bool(logical_gt(t, 0))) {
                {
                current_statement_begin__ = 1301;
                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("z_omega");
        names__.push_back("gamma_z");
        names__.push_back("global_z");
        names__.push_back("local_z");
        names__.push_back("caux_z");
        names__.push_back("S_z");
        names__.push_back("one_over_lambda_z");
        names__.push_back("aux");
        names__.push_back("omega");
        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");
        names__.push_back("omega_int");
    }


    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);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back((logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim ));
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(has_intercept_z);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(hs_z);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(hs_z);
        dims__.push_back(z_dim);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(logical_gt(hs_z, 0));
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back((primitive_value(logical_eq(prior_dist_z, 5)) || primitive_value(logical_eq(prior_dist_z, 6))));
        dims__.push_back(z_dim);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(logical_eq(prior_dist_z, 6));
        dimss__.push_back(dims__);
        dims__.resize(0);
        dimss__.push_back(dims__);
        dims__.resize(0);
        dims__.push_back(z_dim);
        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__);
        dims__.resize(0);
        dims__.push_back(has_intercept_z);
        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_continuous_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_lub_constrain(make_lower(family, link, pstream__), make_upper(family, link, pstream__)));
        }
        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__));
        }

        double aux_unscaled = in__.scalar_lb_constrain(0);
        vars__.push_back(aux_unscaled);

        Eigen::Matrix<double, Eigen::Dynamic, 1> z_omega = in__.vector_constrain((logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim ));
        size_t z_omega_j_1_max__ = (logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim );
        for (size_t j_1__ = 0; j_1__ < z_omega_j_1_max__; ++j_1__) {
            vars__.push_back(z_omega(j_1__));
        }

        std::vector<double> gamma_z;
        size_t gamma_z_d_0_max__ = has_intercept_z;
        gamma_z.reserve(gamma_z_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < gamma_z_d_0_max__; ++d_0__) {
            gamma_z.push_back(in__.scalar_lb_constrain((logical_lte(link_phi, 1) ? stan::math::promote_scalar<double>(stan::math::negative_infinity()) : stan::math::promote_scalar<double>(0) )));
        }
        size_t gamma_z_k_0_max__ = has_intercept_z;
        for (size_t k_0__ = 0; k_0__ < gamma_z_k_0_max__; ++k_0__) {
            vars__.push_back(gamma_z[k_0__]);
        }

        std::vector<double> global_z;
        size_t global_z_d_0_max__ = hs_z;
        global_z.reserve(global_z_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < global_z_d_0_max__; ++d_0__) {
            global_z.push_back(in__.scalar_lb_constrain(0));
        }
        size_t global_z_k_0_max__ = hs_z;
        for (size_t k_0__ = 0; k_0__ < global_z_k_0_max__; ++k_0__) {
            vars__.push_back(global_z[k_0__]);
        }

        std::vector<Eigen::Matrix<double, Eigen::Dynamic, 1> > local_z;
        size_t local_z_d_0_max__ = hs_z;
        local_z.reserve(local_z_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < local_z_d_0_max__; ++d_0__) {
            local_z.push_back(in__.vector_lb_constrain(0, z_dim));
        }
        size_t local_z_j_1_max__ = z_dim;
        size_t local_z_k_0_max__ = hs_z;
        for (size_t j_1__ = 0; j_1__ < local_z_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < local_z_k_0_max__; ++k_0__) {
                vars__.push_back(local_z[k_0__](j_1__));
            }
        }

        std::vector<double> caux_z;
        size_t caux_z_d_0_max__ = logical_gt(hs_z, 0);
        caux_z.reserve(caux_z_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < caux_z_d_0_max__; ++d_0__) {
            caux_z.push_back(in__.scalar_lb_constrain(0));
        }
        size_t caux_z_k_0_max__ = logical_gt(hs_z, 0);
        for (size_t k_0__ = 0; k_0__ < caux_z_k_0_max__; ++k_0__) {
            vars__.push_back(caux_z[k_0__]);
        }

        std::vector<Eigen::Matrix<double, Eigen::Dynamic, 1> > S_z;
        size_t S_z_d_0_max__ = (primitive_value(logical_eq(prior_dist_z, 5)) || primitive_value(logical_eq(prior_dist_z, 6)));
        S_z.reserve(S_z_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < S_z_d_0_max__; ++d_0__) {
            S_z.push_back(in__.vector_lb_constrain(0, z_dim));
        }
        size_t S_z_j_1_max__ = z_dim;
        size_t S_z_k_0_max__ = (primitive_value(logical_eq(prior_dist_z, 5)) || primitive_value(logical_eq(prior_dist_z, 6)));
        for (size_t j_1__ = 0; j_1__ < S_z_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < S_z_k_0_max__; ++k_0__) {
                vars__.push_back(S_z[k_0__](j_1__));
            }
        }

        std::vector<double> one_over_lambda_z;
        size_t one_over_lambda_z_d_0_max__ = logical_eq(prior_dist_z, 6);
        one_over_lambda_z.reserve(one_over_lambda_z_d_0_max__);
        for (size_t d_0__ = 0; d_0__ < one_over_lambda_z_d_0_max__; ++d_0__) {
            one_over_lambda_z.push_back(in__.scalar_lb_constrain(0));
        }
        size_t one_over_lambda_z_k_0_max__ = logical_eq(prior_dist_z, 6);
        for (size_t k_0__ = 0; k_0__ < one_over_lambda_z_k_0_max__; ++k_0__) {
            vars__.push_back(one_over_lambda_z[k_0__]);
        }

        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__ = 951;
            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,(logical_eq(prior_dist_for_aux, 0) ? stan::math::promote_scalar<local_scalar_t__>(aux_unscaled) : stan::math::promote_scalar<local_scalar_t__>((logical_lte(prior_dist_for_aux, 2) ? stan::math::promote_scalar<local_scalar_t__>(((prior_scale_for_aux * aux_unscaled) + prior_mean_for_aux)) : stan::math::promote_scalar<local_scalar_t__>((prior_scale_for_aux * aux_unscaled)) )) ));

            current_statement_begin__ = 955;
            validate_non_negative_index("omega", "z_dim", z_dim);
            Eigen::Matrix<double, Eigen::Dynamic, 1> omega(z_dim);
            stan::math::initialize(omega, DUMMY_VAR__);
            stan::math::fill(omega, DUMMY_VAR__);

            current_statement_begin__ = 957;
            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__ = 958;
            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__ = 959;
            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__ = 960;
            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__ = 961;
            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__ = 962;
            if (as_bool(logical_eq(prior_dist, 0))) {
                current_statement_begin__ = 962;
                stan::math::assign(beta, z_beta);
            } else if (as_bool(logical_eq(prior_dist, 1))) {
                current_statement_begin__ = 963;
                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__ = 964;
                for (int k = 1; k <= K; ++k) {

                    current_statement_begin__ = 965;
                    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__ = 968;
                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__ = 969;
                if (as_bool((primitive_value(logical_eq(is_continuous, 1)) && primitive_value(logical_eq(family, 1))))) {
                    current_statement_begin__ = 970;
                    stan::math::assign(beta, hs_prior(z_beta, global, local, global_prior_scale, aux, c2, pstream__));
                } else {
                    current_statement_begin__ = 971;
                    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__ = 974;
                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__ = 975;
                if (as_bool((primitive_value(logical_eq(is_continuous, 1)) && primitive_value(logical_eq(family, 1))))) {
                    current_statement_begin__ = 976;
                    stan::math::assign(beta, hsplus_prior(z_beta, global, local, global_prior_scale, aux, c2, pstream__));
                } else {
                    current_statement_begin__ = 977;
                    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__ = 980;
                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__ = 982;
                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__ = 984;
                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__ = 985;
                for (int k = 1; k <= K; ++k) {

                    current_statement_begin__ = 986;
                    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__ = 987;
                    stan::math::assign(z_pos, (z_pos + 1));
                    current_statement_begin__ = 988;
                    for (int n = 2; n <= get_base1(num_normals, k, "num_normals", 1); ++n) {

                        current_statement_begin__ = 989;
                        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__ = 990;
                        stan::math::assign(z_pos, (z_pos + 1));
                    }
                    current_statement_begin__ = 992;
                    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__ = 993;
                    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__ = 997;
            if (as_bool(K_smooth)) {

                current_statement_begin__ = 998;
                stan::math::assign(smooth_sd, add(prior_mean_for_smooth, elt_multiply(prior_scale_for_smooth, smooth_sd_raw)));
                current_statement_begin__ = 999;
                if (as_bool((primitive_value(is_continuous) && primitive_value(logical_eq(family, 1))))) {
                    current_statement_begin__ = 999;
                    stan::math::assign(smooth_sd, multiply(smooth_sd, aux));
                }
                current_statement_begin__ = 1000;
                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__ = 1002;
            if (as_bool(logical_eq(prior_dist_z, 0))) {
                current_statement_begin__ = 1002;
                stan::math::assign(omega, z_omega);
            } else if (as_bool(logical_eq(prior_dist_z, 1))) {
                current_statement_begin__ = 1003;
                stan::math::assign(omega, add(elt_multiply(z_omega, prior_scale_z), prior_mean_z));
            } else if (as_bool(logical_eq(prior_dist_z, 2))) {
                current_statement_begin__ = 1004;
                for (int k = 1; k <= z_dim; ++k) {
                    {
                    current_statement_begin__ = 1005;
                    local_scalar_t__ left(DUMMY_VAR__);
                    (void) left;  // dummy to suppress unused var warning
                    stan::math::initialize(left, DUMMY_VAR__);
                    stan::math::fill(left, DUMMY_VAR__);
                    stan::math::assign(left,CFt(get_base1(omega, k, "omega", 1), get_base1(prior_df_z, k, "prior_df_z", 1), pstream__));


                    current_statement_begin__ = 1006;
                    stan::model::assign(omega, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                ((left * get_base1(prior_scale_z, k, "prior_scale_z", 1)) + get_base1(prior_mean_z, k, "prior_mean_z", 1)), 
                                "assigning variable omega");
                    }
                }
            } else if (as_bool(logical_eq(prior_dist_z, 3))) {
                current_statement_begin__ = 1009;
                stan::math::assign(omega, hs_prior(z_omega, global_z, local_z, global_prior_scale, 1, (square(slab_scale_z) * get_base1(caux_z, 1, "caux_z", 1)), pstream__));
            } else if (as_bool(logical_eq(prior_dist_z, 4))) {
                current_statement_begin__ = 1012;
                stan::math::assign(omega, hsplus_prior(z_omega, global_z, local_z, global_prior_scale, 1, (square(slab_scale_z) * get_base1(caux_z, 1, "caux_z", 1)), pstream__));
            } else if (as_bool(logical_eq(prior_dist_z, 5))) {
                current_statement_begin__ = 1015;
                stan::math::assign(omega, add(prior_mean_z, elt_multiply(elt_multiply(prior_scale_z, stan::math::sqrt(multiply(2, get_base1(S_z, 1, "S_z", 1)))), z_omega)));
            } else if (as_bool(logical_eq(prior_dist_z, 6))) {
                current_statement_begin__ = 1017;
                stan::math::assign(omega, add(prior_mean_z, elt_multiply(elt_multiply(multiply(get_base1(one_over_lambda_z, 1, "one_over_lambda_z", 1), prior_scale_z), stan::math::sqrt(multiply(2, get_base1(S_z, 1, "S_z", 1)))), z_omega)));
            } else if (as_bool(logical_eq(prior_dist_z, 7))) {
                {
                current_statement_begin__ = 1019;
                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__ = 1020;
                for (int k = 1; k <= z_dim; ++k) {

                    current_statement_begin__ = 1021;
                    stan::model::assign(omega, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                get_base1(z_omega, z_pos, "z_omega", 1), 
                                "assigning variable omega");
                    current_statement_begin__ = 1022;
                    stan::math::assign(z_pos, (z_pos + 1));
                    current_statement_begin__ = 1023;
                    for (int n = 2; n <= get_base1(num_normals_z, k, "num_normals_z", 1); ++n) {

                        current_statement_begin__ = 1024;
                        stan::model::assign(omega, 
                                    stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                    (stan::model::rvalue(omega, stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), "omega") * get_base1(z_omega, z_pos, "z_omega", 1)), 
                                    "assigning variable omega");
                        current_statement_begin__ = 1025;
                        stan::math::assign(z_pos, (z_pos + 1));
                    }
                    current_statement_begin__ = 1027;
                    stan::model::assign(omega, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                (stan::model::rvalue(omega, stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), "omega") * pow(get_base1(prior_scale_z, k, "prior_scale_z", 1), get_base1(num_normals_z, k, "num_normals_z", 1))), 
                                "assigning variable omega");
                    current_statement_begin__ = 1028;
                    stan::model::assign(omega, 
                                stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), 
                                (stan::model::rvalue(omega, stan::model::cons_list(stan::model::index_uni(k), stan::model::nil_index_list()), "omega") + get_base1(prior_mean_z, k, "prior_mean_z", 1)), 
                                "assigning variable omega");
                }
                }
            }
            current_statement_begin__ = 1033;
            if (as_bool(logical_eq(prior_dist_for_aux, 0))) {
                current_statement_begin__ = 1034;
                stan::math::assign(aux, aux_unscaled);
            } else {

                current_statement_begin__ = 1036;
                stan::math::assign(aux, (prior_scale_for_aux * aux_unscaled));
                current_statement_begin__ = 1037;
                if (as_bool(logical_lte(prior_dist_for_aux, 2))) {
                    current_statement_begin__ = 1038;
                    stan::math::assign(aux, (aux + prior_mean_for_aux));
                }
            }
            current_statement_begin__ = 1041;
            if (as_bool(logical_gt(t, 0))) {

                current_statement_begin__ = 1042;
                if (as_bool(logical_eq(special_case, 1))) {
                    {
                    current_statement_begin__ = 1043;
                    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__ = 1044;
                    stan::math::assign(theta_L, multiply(elt_multiply(scale, tau), aux));
                    current_statement_begin__ = 1045;
                    if (as_bool(logical_eq(t, 1))) {
                        current_statement_begin__ = 1045;
                        stan::math::assign(b, multiply(get_base1(theta_L, 1, "theta_L", 1), z_b));
                    } else {
                        current_statement_begin__ = 1046;
                        for (int i = 1; i <= t; ++i) {
                            {
                            current_statement_begin__ = 1047;
                            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__ = 1048;
                            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__ = 1049;
                            stan::math::assign(start, (end + 1));
                            }
                        }
                    }
                    }
                } else {

                    current_statement_begin__ = 1053;
                    stan::math::assign(theta_L, make_theta_L(len_theta_L, p, aux, tau, scale, zeta, rho, z_T, pstream__));
                    current_statement_begin__ = 1055;
                    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 omega_j_1_max__ = z_dim;
                for (size_t j_1__ = 0; j_1__ < omega_j_1_max__; ++j_1__) {
                    vars__.push_back(omega(j_1__));
                }
                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__ = 1306;
            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__ = 1307;
            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__);

            current_statement_begin__ = 1308;
            validate_non_negative_index("omega_int", "has_intercept_z", has_intercept_z);
            std::vector<double> omega_int(has_intercept_z, double(0));
            stan::math::initialize(omega_int, DUMMY_VAR__);
            stan::math::fill(omega_int, DUMMY_VAR__);

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

                current_statement_begin__ = 1311;
                if (as_bool(dense_X)) {
                    current_statement_begin__ = 1311;
                    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__ = 1312;
                    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__ = 1314;
            if (as_bool(logical_eq(has_intercept_z, 1))) {

                current_statement_begin__ = 1315;
                stan::model::assign(omega_int, 
                            stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list()), 
                            (get_base1(gamma_z, 1, "gamma_z", 1) - dot_product(zbar, omega)), 
                            "assigning variable omega_int");
            }
            current_statement_begin__ = 1318;
            if (as_bool(compute_mean_PPD)) {
                {
                current_statement_begin__ = 1319;
                validate_non_negative_index("eta_z", "N", N);
                Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> eta_z(N);
                stan::math::initialize(eta_z, DUMMY_VAR__);
                stan::math::fill(eta_z, DUMMY_VAR__);

                current_statement_begin__ = 1320;
                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__ = 1321;
                if (as_bool(logical_gt(K, 0))) {

                    current_statement_begin__ = 1322;
                    if (as_bool(dense_X)) {
                        current_statement_begin__ = 1322;
                        stan::math::assign(eta, multiply(get_base1(X, 1, "X", 1), beta));
                    } else {
                        current_statement_begin__ = 1323;
                        stan::math::assign(eta, csr_matrix_times_vector2(N, K, w_X, v_X, u_X, beta, pstream__));
                    }
                } else {
                    current_statement_begin__ = 1325;
                    stan::math::assign(eta, rep_vector(0.0, N));
                }
                current_statement_begin__ = 1326;
                if (as_bool(logical_eq(has_offset, 1))) {
                    current_statement_begin__ = 1326;
                    stan::math::assign(eta, add(eta, offset));
                }
                current_statement_begin__ = 1327;
                if (as_bool(K_smooth)) {
                    current_statement_begin__ = 1327;
                    stan::math::assign(eta, add(eta, multiply(S, beta_smooth)));
                }
                current_statement_begin__ = 1328;
                if (as_bool(logical_gt(t, 0))) {

                    current_statement_begin__ = 1329;
                    if (as_bool(special_case)) {
                        current_statement_begin__ = 1329;
                        for (int i = 1; i <= t; ++i) {
                            current_statement_begin__ = 1329;
                            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__ = 1330;
                        stan::math::assign(eta, add(eta, csr_matrix_times_vector2(N, q, w, v, u, b, pstream__)));
                    }
                }
                current_statement_begin__ = 1332;
                if (as_bool(logical_eq(has_intercept, 1))) {

                    current_statement_begin__ = 1333;
                    if (as_bool((primitive_value(logical_eq(make_lower(family, link, pstream__), stan::math::negative_infinity())) && primitive_value(logical_eq(make_upper(family, link, pstream__), stan::math::positive_infinity()))))) {
                        current_statement_begin__ = 1334;
                        stan::math::assign(eta, add(eta, get_base1(gamma, 1, "gamma", 1)));
                    } else if (as_bool((primitive_value(logical_eq(family, 4)) && primitive_value(logical_eq(link, 5))))) {
                        {
                        current_statement_begin__ = 1336;
                        local_scalar_t__ max_eta(DUMMY_VAR__);
                        (void) max_eta;  // dummy to suppress unused var warning
                        stan::math::initialize(max_eta, DUMMY_VAR__);
                        stan::math::fill(max_eta, DUMMY_VAR__);
                        stan::math::assign(max_eta,max(eta));


                        current_statement_begin__ = 1337;
                        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") - max_eta), 
                                    "assigning variable alpha");
                        current_statement_begin__ = 1338;
                        stan::math::assign(eta, add(eta, (get_base1(gamma, 1, "gamma", 1) - max_eta)));
                        }
                    } else {
                        {
                        current_statement_begin__ = 1341;
                        local_scalar_t__ min_eta(DUMMY_VAR__);
                        (void) min_eta;  // dummy to suppress unused var warning
                        stan::math::initialize(min_eta, DUMMY_VAR__);
                        stan::math::fill(min_eta, DUMMY_VAR__);
                        stan::math::assign(min_eta,min(eta));


                        current_statement_begin__ = 1342;
                        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") - min_eta), 
                                    "assigning variable alpha");
                        current_statement_begin__ = 1343;
                        stan::math::assign(eta, add(eta, (get_base1(gamma, 1, "gamma", 1) - min_eta)));
                        }
                    }
                } else {

                    current_statement_begin__ = 1348;
                    stan::math::assign(eta, add(eta, dot_product(xbar, beta)));
                }
                current_statement_begin__ = 1350;
                if (as_bool((primitive_value((primitive_value(logical_eq(family, 4)) && primitive_value(logical_gt(z_dim, 0)))) && primitive_value(logical_gt(link_phi, 0))))) {

                    current_statement_begin__ = 1351;
                    stan::math::assign(eta_z, multiply(betareg_z, omega));
                } else if (as_bool((primitive_value((primitive_value(logical_eq(family, 4)) && primitive_value(logical_eq(z_dim, 0)))) && primitive_value(logical_eq(has_intercept_z, 1))))) {

                    current_statement_begin__ = 1354;
                    stan::math::assign(eta_z, rep_vector(0.0, N));
                }
                current_statement_begin__ = 1357;
                if (as_bool(logical_eq(has_intercept_z, 1))) {

                    current_statement_begin__ = 1358;
                    if (as_bool(logical_gt(link_phi, 1))) {

                        current_statement_begin__ = 1359;
                        stan::model::assign(omega_int, 
                                    stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list()), 
                                    (stan::model::rvalue(omega_int, stan::model::cons_list(stan::model::index_uni(1), stan::model::nil_index_list()), "omega_int") - min(eta_z)), 
                                    "assigning variable omega_int");
                        current_statement_begin__ = 1360;
                        stan::math::assign(eta_z, add(eta_z, (get_base1(gamma_z, 1, "gamma_z", 1) - min(eta_z))));
                    } else {

                        current_statement_begin__ = 1363;
                        stan::math::assign(eta_z, add(eta_z, get_base1(gamma_z, 1, "gamma_z", 1)));
                    }
                } else {

                    current_statement_begin__ = 1367;
                    if (as_bool(logical_gt(link_phi, 1))) {

                        current_statement_begin__ = 1368;
                        stan::math::assign(eta_z, add(eta_z, (dot_product(zbar, omega) - min(eta_z))));
                    } else {

                        current_statement_begin__ = 1371;
                        stan::math::assign(eta_z, add(eta_z, dot_product(zbar, omega)));
                    }
                }
                current_statement_begin__ = 1375;
                if (as_bool(logical_gt(SSfun, 0))) {
                    {
                    current_statement_begin__ = 1376;
                    validate_non_negative_index("eta_nlmer", "len_y", len_y);
                    Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> eta_nlmer(len_y);
                    stan::math::initialize(eta_nlmer, DUMMY_VAR__);
                    stan::math::fill(eta_nlmer, DUMMY_VAR__);

                    current_statement_begin__ = 1377;
                    validate_non_negative_index("P", "len_y", len_y);
                    validate_non_negative_index("P", "K", K);
                    Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, Eigen::Dynamic> P(len_y, K);
                    stan::math::initialize(P, DUMMY_VAR__);
                    stan::math::fill(P, DUMMY_VAR__);


                    current_statement_begin__ = 1378;
                    stan::math::assign(P, reshape_vec(eta, len_y, K, pstream__));
                    current_statement_begin__ = 1379;
                    if (as_bool(logical_lt(SSfun, 5))) {

                        current_statement_begin__ = 1380;
                        if (as_bool(logical_lte(SSfun, 2))) {

                            current_statement_begin__ = 1381;
                            if (as_bool(logical_eq(SSfun, 1))) {
                                current_statement_begin__ = 1381;
                                stan::math::assign(eta_nlmer, SS_asymp(input, P, pstream__));
                            } else {
                                current_statement_begin__ = 1382;
                                stan::math::assign(eta_nlmer, SS_asympOff(input, P, pstream__));
                            }
                        } else if (as_bool(logical_eq(SSfun, 3))) {
                            current_statement_begin__ = 1384;
                            stan::math::assign(eta_nlmer, SS_asympOrig(input, P, pstream__));
                        } else {
                            current_statement_begin__ = 1385;
                            stan::math::assign(eta_nlmer, SS_biexp(input, P, pstream__));
                        }
                    } else {

                        current_statement_begin__ = 1388;
                        if (as_bool(logical_lte(SSfun, 7))) {

                            current_statement_begin__ = 1389;
                            if (as_bool(logical_eq(SSfun, 5))) {
                                current_statement_begin__ = 1389;
                                stan::math::assign(eta_nlmer, SS_fol(Dose, input, P, pstream__));
                            } else if (as_bool(logical_eq(SSfun, 6))) {
                                current_statement_begin__ = 1390;
                                stan::math::assign(eta_nlmer, SS_fpl(input, P, pstream__));
                            } else {
                                current_statement_begin__ = 1391;
                                stan::math::assign(eta_nlmer, SS_gompertz(input, P, pstream__));
                            }
                        } else {

                            current_statement_begin__ = 1394;
                            if (as_bool(logical_eq(SSfun, 8))) {
                                current_statement_begin__ = 1394;
                                stan::math::assign(eta_nlmer, SS_logis(input, P, pstream__));
                            } else if (as_bool(logical_eq(SSfun, 9))) {
                                current_statement_begin__ = 1395;
                                stan::math::assign(eta_nlmer, SS_micmen(input, P, pstream__));
                            } else {
                                current_statement_begin__ = 1396;
                                stan::math::assign(eta_nlmer, SS_weibull(input, P, pstream__));
                            }
                        }
                    }
                    current_statement_begin__ = 1399;
                    for (int n = 1; n <= len_y; ++n) {
                        current_statement_begin__ = 1399;
                        stan::math::assign(mean_PPD, (mean_PPD + normal_rng(get_base1(eta_nlmer, n, "eta_nlmer", 1), aux, base_rng__)));
                    }
                    }
                } else if (as_bool(logical_eq(family, 1))) {
                    {
                    current_statement_begin__ = 1402;
                    validate_non_negative_index("mu", "N", N);
                    Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> mu(N);
                    stan::math::initialize(mu, DUMMY_VAR__);
                    stan::math::fill(mu, DUMMY_VAR__);
                    stan::math::assign(mu,(logical_gt(link, 1) ? stan::math::promote_scalar<double>(linkinv_gauss(eta, link, pstream__)) : stan::math::promote_scalar<double>(eta) ));


                    current_statement_begin__ = 1403;
                    for (int n = 1; n <= len_y; ++n) {
                        current_statement_begin__ = 1403;
                        stan::math::assign(mean_PPD, (mean_PPD + normal_rng(get_base1(mu, n, "mu", 1), aux, base_rng__)));
                    }
                    }
                } else if (as_bool(logical_eq(family, 2))) {
                    {
                    current_statement_begin__ = 1406;
                    validate_non_negative_index("mu", "N", N);
                    Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> mu(N);
                    stan::math::initialize(mu, DUMMY_VAR__);
                    stan::math::fill(mu, DUMMY_VAR__);
                    stan::math::assign(mu,(logical_gt(link, 1) ? stan::math::promote_scalar<double>(linkinv_gamma(eta, link, pstream__)) : stan::math::promote_scalar<double>(eta) ));


                    current_statement_begin__ = 1407;
                    for (int n = 1; n <= len_y; ++n) {
                        current_statement_begin__ = 1407;
                        stan::math::assign(mean_PPD, (mean_PPD + gamma_rng(aux, (aux / get_base1(mu, n, "mu", 1)), base_rng__)));
                    }
                    }
                } else if (as_bool(logical_eq(family, 3))) {
                    {
                    current_statement_begin__ = 1410;
                    validate_non_negative_index("mu", "N", N);
                    Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> mu(N);
                    stan::math::initialize(mu, DUMMY_VAR__);
                    stan::math::fill(mu, DUMMY_VAR__);
                    stan::math::assign(mu,(logical_gt(link, 1) ? stan::math::promote_scalar<double>(linkinv_inv_gaussian(eta, link, pstream__)) : stan::math::promote_scalar<double>(eta) ));


                    current_statement_begin__ = 1411;
                    for (int n = 1; n <= len_y; ++n) {
                        current_statement_begin__ = 1411;
                        stan::math::assign(mean_PPD, (mean_PPD + inv_gaussian_rng(get_base1(mu, n, "mu", 1), aux, base_rng__, pstream__)));
                    }
                    }
                } else if (as_bool((primitive_value(logical_eq(family, 4)) && primitive_value(logical_eq(link_phi, 0))))) {
                    {
                    current_statement_begin__ = 1414;
                    validate_non_negative_index("mu", "N", N);
                    Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> mu(N);
                    stan::math::initialize(mu, DUMMY_VAR__);
                    stan::math::fill(mu, DUMMY_VAR__);
                    stan::math::assign(mu,linkinv_beta(eta, link, pstream__));


                    current_statement_begin__ = 1415;
                    for (int n = 1; n <= N; ++n) {
                        {
                        current_statement_begin__ = 1416;
                        local_scalar_t__ mu_n(DUMMY_VAR__);
                        (void) mu_n;  // dummy to suppress unused var warning
                        stan::math::initialize(mu_n, DUMMY_VAR__);
                        stan::math::fill(mu_n, DUMMY_VAR__);
                        stan::math::assign(mu_n,get_base1(mu, n, "mu", 1));


                        current_statement_begin__ = 1417;
                        if (as_bool(logical_lte(aux, 0))) {
                            current_statement_begin__ = 1417;
                            stan::math::assign(mean_PPD, (mean_PPD + bernoulli_rng(0.5, base_rng__)));
                        } else if (as_bool(logical_gte(mu_n, 1))) {
                            current_statement_begin__ = 1418;
                            stan::math::assign(mean_PPD, (mean_PPD + 1));
                        } else if (as_bool(logical_gt(mu_n, 0))) {
                            current_statement_begin__ = 1420;
                            stan::math::assign(mean_PPD, (mean_PPD + beta_rng((mu_n * aux), ((1 - mu_n) * aux), base_rng__)));
                        }
                        }
                    }
                    }
                } else if (as_bool((primitive_value(logical_eq(family, 4)) && primitive_value(logical_gt(link_phi, 0))))) {
                    {
                    current_statement_begin__ = 1424;
                    validate_non_negative_index("mu", "N", N);
                    Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> mu(N);
                    stan::math::initialize(mu, DUMMY_VAR__);
                    stan::math::fill(mu, DUMMY_VAR__);
                    stan::math::assign(mu,linkinv_beta(eta, link, pstream__));

                    current_statement_begin__ = 1425;
                    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_beta_z(eta_z, link_phi, pstream__));


                    current_statement_begin__ = 1426;
                    for (int n = 1; n <= N; ++n) {
                        {
                        current_statement_begin__ = 1427;
                        local_scalar_t__ mu_n(DUMMY_VAR__);
                        (void) mu_n;  // dummy to suppress unused var warning
                        stan::math::initialize(mu_n, DUMMY_VAR__);
                        stan::math::fill(mu_n, DUMMY_VAR__);
                        stan::math::assign(mu_n,get_base1(mu, n, "mu", 1));

                        current_statement_begin__ = 1428;
                        local_scalar_t__ aux_n(DUMMY_VAR__);
                        (void) aux_n;  // dummy to suppress unused var warning
                        stan::math::initialize(aux_n, DUMMY_VAR__);
                        stan::math::fill(aux_n, DUMMY_VAR__);
                        stan::math::assign(aux_n,get_base1(phi, n, "phi", 1));


                        current_statement_begin__ = 1429;
                        if (as_bool(logical_lte(aux_n, 0))) {
                            current_statement_begin__ = 1429;
                            stan::math::assign(mean_PPD, (mean_PPD + bernoulli_rng(0.5, base_rng__)));
                        } else if (as_bool(logical_gte(mu_n, 1))) {
                            current_statement_begin__ = 1430;
                            stan::math::assign(mean_PPD, (mean_PPD + 1));
                        } else if (as_bool(logical_gt(mu_n, 0))) {
                            current_statement_begin__ = 1432;
                            stan::math::assign(mean_PPD, (mean_PPD + beta_rng((mu_n * aux_n), ((1 - mu_n) * aux_n), base_rng__)));
                        }
                        }
                    }
                    }
                }
                current_statement_begin__ = 1435;
                stan::math::assign(mean_PPD, (mean_PPD / len_y));
                }
            }

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

            current_statement_begin__ = 1307;
            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__]);
            }

            current_statement_begin__ = 1308;
            size_t omega_int_k_0_max__ = has_intercept_z;
            for (size_t k_0__ = 0; k_0__ < omega_int_k_0_max__; ++k_0__) {
                vars__.push_back(omega_int[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_continuous";
    }


    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());
        }
        param_name_stream__.str(std::string());
        param_name_stream__ << "aux_unscaled";
        param_names__.push_back(param_name_stream__.str());
        size_t z_omega_j_1_max__ = (logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim );
        for (size_t j_1__ = 0; j_1__ < z_omega_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "z_omega" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t gamma_z_k_0_max__ = has_intercept_z;
        for (size_t k_0__ = 0; k_0__ < gamma_z_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "gamma_z" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t global_z_k_0_max__ = hs_z;
        for (size_t k_0__ = 0; k_0__ < global_z_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "global_z" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t local_z_j_1_max__ = z_dim;
        size_t local_z_k_0_max__ = hs_z;
        for (size_t j_1__ = 0; j_1__ < local_z_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < local_z_k_0_max__; ++k_0__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "local_z" << '.' << k_0__ + 1 << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
        }
        size_t caux_z_k_0_max__ = logical_gt(hs_z, 0);
        for (size_t k_0__ = 0; k_0__ < caux_z_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "caux_z" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t S_z_j_1_max__ = z_dim;
        size_t S_z_k_0_max__ = (primitive_value(logical_eq(prior_dist_z, 5)) || primitive_value(logical_eq(prior_dist_z, 6)));
        for (size_t j_1__ = 0; j_1__ < S_z_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < S_z_k_0_max__; ++k_0__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "S_z" << '.' << k_0__ + 1 << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
        }
        size_t one_over_lambda_z_k_0_max__ = logical_eq(prior_dist_z, 6);
        for (size_t k_0__ = 0; k_0__ < one_over_lambda_z_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "one_over_lambda_z" << '.' << k_0__ + 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 omega_j_1_max__ = z_dim;
            for (size_t j_1__ = 0; j_1__ < omega_j_1_max__; ++j_1__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "omega" << '.' << j_1__ + 1;
                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());
        }
        size_t omega_int_k_0_max__ = has_intercept_z;
        for (size_t k_0__ = 0; k_0__ < omega_int_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "omega_int" << '.' << 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());
        }
        param_name_stream__.str(std::string());
        param_name_stream__ << "aux_unscaled";
        param_names__.push_back(param_name_stream__.str());
        size_t z_omega_j_1_max__ = (logical_eq(prior_dist_z, 7) ? sum(num_normals_z) : z_dim );
        for (size_t j_1__ = 0; j_1__ < z_omega_j_1_max__; ++j_1__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "z_omega" << '.' << j_1__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t gamma_z_k_0_max__ = has_intercept_z;
        for (size_t k_0__ = 0; k_0__ < gamma_z_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "gamma_z" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t global_z_k_0_max__ = hs_z;
        for (size_t k_0__ = 0; k_0__ < global_z_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "global_z" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t local_z_j_1_max__ = z_dim;
        size_t local_z_k_0_max__ = hs_z;
        for (size_t j_1__ = 0; j_1__ < local_z_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < local_z_k_0_max__; ++k_0__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "local_z" << '.' << k_0__ + 1 << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
        }
        size_t caux_z_k_0_max__ = logical_gt(hs_z, 0);
        for (size_t k_0__ = 0; k_0__ < caux_z_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "caux_z" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
        size_t S_z_j_1_max__ = z_dim;
        size_t S_z_k_0_max__ = (primitive_value(logical_eq(prior_dist_z, 5)) || primitive_value(logical_eq(prior_dist_z, 6)));
        for (size_t j_1__ = 0; j_1__ < S_z_j_1_max__; ++j_1__) {
            for (size_t k_0__ = 0; k_0__ < S_z_k_0_max__; ++k_0__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "S_z" << '.' << k_0__ + 1 << '.' << j_1__ + 1;
                param_names__.push_back(param_name_stream__.str());
            }
        }
        size_t one_over_lambda_z_k_0_max__ = logical_eq(prior_dist_z, 6);
        for (size_t k_0__ = 0; k_0__ < one_over_lambda_z_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "one_over_lambda_z" << '.' << k_0__ + 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 omega_j_1_max__ = z_dim;
            for (size_t j_1__ = 0; j_1__ < omega_j_1_max__; ++j_1__) {
                param_name_stream__.str(std::string());
                param_name_stream__ << "omega" << '.' << j_1__ + 1;
                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());
        }
        size_t omega_int_k_0_max__ = has_intercept_z;
        for (size_t k_0__ = 0; k_0__ < omega_int_k_0_max__; ++k_0__) {
            param_name_stream__.str(std::string());
            param_name_stream__ << "omega_int" << '.' << k_0__ + 1;
            param_names__.push_back(param_name_stream__.str());
        }
    }

}; // model

}  // namespace

typedef model_continuous_namespace::model_continuous stan_model;