#ifndef MODELS_HPP
#define MODELS_HPP
#define STAN__SERVICES__COMMAND_HPP
#include <rstan/rstaninc.hpp>
#ifndef USE_STANC3
#define USE_STANC3
#endif

// Code generated by stanc v2.26.1
#include <stan/model/model_header.hpp>
namespace model1c8dcb7bec352c__namespace {


inline void validate_positive_index(const char* var_name, const char* expr,
                                    int val) {
  if (val < 1) {
    std::stringstream msg;
    msg << "Found dimension size less than one in simplex declaration"
        << "; variable=" << var_name << "; dimension size expression=" << expr
        << "; expression value=" << val;
    std::string msg_str(msg.str());
    throw std::invalid_argument(msg_str.c_str());
  }
}

inline void validate_unit_vector_index(const char* var_name, const char* expr,
                                       int val) {
  if (val <= 1) {
    std::stringstream msg;
    if (val == 1) {
      msg << "Found dimension size one in unit vector declaration."
          << " One-dimensional unit vector is discrete"
          << " but the target distribution must be continuous."
          << " variable=" << var_name << "; dimension size expression=" << expr;
    } else {
      msg << "Found dimension size less than one in unit vector declaration"
          << "; variable=" << var_name << "; dimension size expression=" << expr
          << "; expression value=" << val;
    }
    std::string msg_str(msg.str());
    throw std::invalid_argument(msg_str.c_str());
  }
}


using std::istream;
using std::string;
using std::stringstream;
using std::vector;
using std::pow;
using stan::io::dump;
using stan::math::lgamma;
using stan::model::model_base_crtp;
using stan::model::rvalue;
using stan::model::cons_list;
using stan::model::index_uni;
using stan::model::index_max;
using stan::model::index_min;
using stan::model::index_min_max;
using stan::model::index_multi;
using stan::model::index_omni;
using stan::model::nil_index_list;
using namespace stan::math;
using stan::math::pow; 

stan::math::profile_map profiles__;
static int current_statement__= 0;
static const std::vector<string> locations_array__ = {" (found before start of program)",
                                                      " (in 'anon_model', line 17, column 2 to column 17)",
                                                      " (in 'anon_model', line 18, column 2 to column 18)",
                                                      " (in 'anon_model', line 19, column 2 to column 22)",
                                                      " (in 'anon_model', line 21, column 2 to column 25)",
                                                      " (in 'anon_model', line 22, column 2 to column 32)",
                                                      " (in 'anon_model', line 23, column 2 to column 18)",
                                                      " (in 'anon_model', line 26, column 2 to column 18)",
                                                      " (in 'anon_model', line 28, column 2 to column 42)",
                                                      " (in 'anon_model', line 50, column 2 to column 31)",
                                                      " (in 'anon_model', line 34, column 11 to column 12)",
                                                      " (in 'anon_model', line 34, column 4 to column 50)",
                                                      " (in 'anon_model', line 37, column 6 to column 35)",
                                                      " (in 'anon_model', line 35, column 19 to line 38, column 5)",
                                                      " (in 'anon_model', line 35, column 4 to line 38, column 5)",
                                                      " (in 'anon_model', line 39, column 4 to column 41)",
                                                      " (in 'anon_model', line 32, column 19 to line 40, column 3)",
                                                      " (in 'anon_model', line 32, column 2 to line 40, column 3)",
                                                      " (in 'anon_model', line 42, column 2 to column 52)",
                                                      " (in 'anon_model', line 43, column 2 to line 44, column 41)",
                                                      " (in 'anon_model', line 45, column 2 to column 47)",
                                                      " (in 'anon_model', line 46, column 2 to column 35)",
                                                      " (in 'anon_model', line 5, column 2 to column 17)",
                                                      " (in 'anon_model', line 6, column 9 to column 10)",
                                                      " (in 'anon_model', line 6, column 2 to column 14)",
                                                      " (in 'anon_model', line 7, column 2 to column 19)",
                                                      " (in 'anon_model', line 9, column 2 to column 21)",
                                                      " (in 'anon_model', line 10, column 9 to column 10)",
                                                      " (in 'anon_model', line 10, column 2 to column 17)",
                                                      " (in 'anon_model', line 11, column 18 to column 19)",
                                                      " (in 'anon_model', line 11, column 2 to column 29)",
                                                      " (in 'anon_model', line 12, column 2 to column 17)",
                                                      " (in 'anon_model', line 18, column 9 to column 12)",
                                                      " (in 'anon_model', line 21, column 9 to column 14)",
                                                      " (in 'anon_model', line 22, column 18 to column 23)",
                                                      " (in 'anon_model', line 23, column 9 to column 10)",
                                                      " (in 'anon_model', line 26, column 9 to column 10)"};



class model1c8dcb7bec352c_ final : public model_base_crtp<model1c8dcb7bec352c_> {

 private:
  int N;
  Eigen::Matrix<double, -1, 1> Y;
  int Ksp;
  int Mme_1;
  Eigen::Matrix<double, -1, 1> Xn_1;
  Eigen::Matrix<double, -1, 1> noise_1;
  int prior_only;
 
 public:
  ~model1c8dcb7bec352c_() { }
  
  inline std::string model_name() const final { return "model1c8dcb7bec352c_"; }

  inline std::vector<std::string> model_compile_info() const noexcept {
    return std::vector<std::string>{"stanc_version = stanc3 v2.26.1", "stancflags = "};
  }
  
  
  model1c8dcb7bec352c_(stan::io::var_context& context__,
                       unsigned int random_seed__ = 0,
                       std::ostream* pstream__ = nullptr) : model_base_crtp(0) {
    using local_scalar_t__ = double ;
    boost::ecuyer1988 base_rng__ = 
        stan::services::util::create_rng(random_seed__, 0);
    (void) base_rng__;  // suppress unused var warning
    static const char* function__ = "model1c8dcb7bec352c__namespace::model1c8dcb7bec352c_";
    (void) function__;  // suppress unused var warning
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    (void) DUMMY_VAR__;  // suppress unused var warning
    
    try {
      int pos__;
      pos__ = std::numeric_limits<int>::min();
      
      pos__ = 1;
      current_statement__ = 22;
      context__.validate_dims("data initialization","N","int",
          context__.to_vec());
      N = std::numeric_limits<int>::min();
      
      current_statement__ = 22;
      N = context__.vals_i("N")[(1 - 1)];
      current_statement__ = 22;
      current_statement__ = 22;
      check_greater_or_equal(function__, "N", N, 1);
      current_statement__ = 23;
      validate_non_negative_index("Y", "N", N);
      current_statement__ = 24;
      context__.validate_dims("data initialization","Y","double",
          context__.to_vec(N));
      Y = Eigen::Matrix<double, -1, 1>(N);
      stan::math::fill(Y, std::numeric_limits<double>::quiet_NaN());
      
      {
        std::vector<local_scalar_t__> Y_flat__;
        current_statement__ = 24;
        assign(Y_flat__, nil_index_list(), context__.vals_r("Y"),
          "assigning variable Y_flat__");
        current_statement__ = 24;
        pos__ = 1;
        current_statement__ = 24;
        for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
          current_statement__ = 24;
          assign(Y, cons_list(index_uni(sym1__), nil_index_list()),
            Y_flat__[(pos__ - 1)], "assigning variable Y");
          current_statement__ = 24;
          pos__ = (pos__ + 1);}
      }
      current_statement__ = 25;
      context__.validate_dims("data initialization","Ksp","int",
          context__.to_vec());
      Ksp = std::numeric_limits<int>::min();
      
      current_statement__ = 25;
      Ksp = context__.vals_i("Ksp")[(1 - 1)];
      current_statement__ = 25;
      current_statement__ = 25;
      check_greater_or_equal(function__, "Ksp", Ksp, 1);
      current_statement__ = 26;
      context__.validate_dims("data initialization","Mme_1","int",
          context__.to_vec());
      Mme_1 = std::numeric_limits<int>::min();
      
      current_statement__ = 26;
      Mme_1 = context__.vals_i("Mme_1")[(1 - 1)];
      current_statement__ = 26;
      current_statement__ = 26;
      check_greater_or_equal(function__, "Mme_1", Mme_1, 1);
      current_statement__ = 27;
      validate_non_negative_index("Xn_1", "N", N);
      current_statement__ = 28;
      context__.validate_dims("data initialization","Xn_1","double",
          context__.to_vec(N));
      Xn_1 = Eigen::Matrix<double, -1, 1>(N);
      stan::math::fill(Xn_1, std::numeric_limits<double>::quiet_NaN());
      
      {
        std::vector<local_scalar_t__> Xn_1_flat__;
        current_statement__ = 28;
        assign(Xn_1_flat__, nil_index_list(), context__.vals_r("Xn_1"),
          "assigning variable Xn_1_flat__");
        current_statement__ = 28;
        pos__ = 1;
        current_statement__ = 28;
        for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
          current_statement__ = 28;
          assign(Xn_1, cons_list(index_uni(sym1__), nil_index_list()),
            Xn_1_flat__[(pos__ - 1)], "assigning variable Xn_1");
          current_statement__ = 28;
          pos__ = (pos__ + 1);}
      }
      current_statement__ = 29;
      validate_non_negative_index("noise_1", "N", N);
      current_statement__ = 30;
      context__.validate_dims("data initialization","noise_1","double",
          context__.to_vec(N));
      noise_1 = Eigen::Matrix<double, -1, 1>(N);
      stan::math::fill(noise_1, std::numeric_limits<double>::quiet_NaN());
      
      {
        std::vector<local_scalar_t__> noise_1_flat__;
        current_statement__ = 30;
        assign(noise_1_flat__, nil_index_list(), context__.vals_r("noise_1"),
          "assigning variable noise_1_flat__");
        current_statement__ = 30;
        pos__ = 1;
        current_statement__ = 30;
        for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
          current_statement__ = 30;
          assign(noise_1, cons_list(index_uni(sym1__), nil_index_list()),
            noise_1_flat__[(pos__ - 1)], "assigning variable noise_1");
          current_statement__ = 30;
          pos__ = (pos__ + 1);}
      }
      current_statement__ = 30;
      for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
        current_statement__ = 30;
        current_statement__ = 30;
        check_greater_or_equal(function__, "noise_1[sym1__]",
                               noise_1[(sym1__ - 1)], 0);}
      current_statement__ = 31;
      context__.validate_dims("data initialization","prior_only","int",
          context__.to_vec());
      prior_only = std::numeric_limits<int>::min();
      
      current_statement__ = 31;
      prior_only = context__.vals_i("prior_only")[(1 - 1)];
      current_statement__ = 32;
      validate_non_negative_index("bsp", "Ksp", Ksp);
      current_statement__ = 33;
      validate_non_negative_index("meanme_1", "Mme_1", Mme_1);
      current_statement__ = 34;
      validate_non_negative_index("sdme_1", "Mme_1", Mme_1);
      current_statement__ = 35;
      validate_non_negative_index("zme_1", "N", N);
      current_statement__ = 36;
      validate_non_negative_index("Xme_1", "N", N);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
      // Next line prevents compiler griping about no return
      throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 
    }
    num_params_r__ = 0U;
    
    try {
      num_params_r__ += 1;
      num_params_r__ += Ksp;
      num_params_r__ += 1;
      num_params_r__ += Mme_1;
      num_params_r__ += Mme_1;
      num_params_r__ += N;
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
      // Next line prevents compiler griping about no return
      throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 
    }
  }
  template <bool propto__, bool jacobian__, typename VecR, typename VecI, stan::require_vector_like_t<VecR>* = nullptr, stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
  inline stan::scalar_type_t<VecR> log_prob_impl(VecR& params_r__,
                                                 VecI& params_i__,
                                                 std::ostream* pstream__ = nullptr) const {
    using T__ = stan::scalar_type_t<VecR>;
    using local_scalar_t__ = T__;
    T__ lp__(0.0);
    stan::math::accumulator<T__> lp_accum__;
    static const char* function__ = "model1c8dcb7bec352c__namespace::log_prob";
(void) function__;  // suppress unused var warning

    stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    (void) DUMMY_VAR__;  // suppress unused var warning

    
    try {
      local_scalar_t__ Intercept;
      Intercept = DUMMY_VAR__;
      
      current_statement__ = 1;
      Intercept = in__.scalar();
      Eigen::Matrix<local_scalar_t__, -1, 1> bsp;
      bsp = Eigen::Matrix<local_scalar_t__, -1, 1>(Ksp);
      stan::math::fill(bsp, DUMMY_VAR__);
      
      current_statement__ = 2;
      bsp = in__.vector(Ksp);
      local_scalar_t__ sigma;
      sigma = DUMMY_VAR__;
      
      current_statement__ = 3;
      sigma = in__.scalar();
      current_statement__ = 3;
      if (jacobian__) {
        current_statement__ = 3;
        sigma = stan::math::lb_constrain(sigma, 0, lp__);
      } else {
        current_statement__ = 3;
        sigma = stan::math::lb_constrain(sigma, 0);
      }
      Eigen::Matrix<local_scalar_t__, -1, 1> meanme_1;
      meanme_1 = Eigen::Matrix<local_scalar_t__, -1, 1>(Mme_1);
      stan::math::fill(meanme_1, DUMMY_VAR__);
      
      current_statement__ = 4;
      meanme_1 = in__.vector(Mme_1);
      Eigen::Matrix<local_scalar_t__, -1, 1> sdme_1;
      sdme_1 = Eigen::Matrix<local_scalar_t__, -1, 1>(Mme_1);
      stan::math::fill(sdme_1, DUMMY_VAR__);
      
      current_statement__ = 5;
      sdme_1 = in__.vector(Mme_1);
      current_statement__ = 5;
      for (int sym1__ = 1; sym1__ <= Mme_1; ++sym1__) {
        current_statement__ = 5;
        if (jacobian__) {
          current_statement__ = 5;
          assign(sdme_1, cons_list(index_uni(sym1__), nil_index_list()),
            stan::math::lb_constrain(sdme_1[(sym1__ - 1)], 0, lp__),
            "assigning variable sdme_1");
        } else {
          current_statement__ = 5;
          assign(sdme_1, cons_list(index_uni(sym1__), nil_index_list()),
            stan::math::lb_constrain(sdme_1[(sym1__ - 1)], 0),
            "assigning variable sdme_1");
        }}
      Eigen::Matrix<local_scalar_t__, -1, 1> zme_1;
      zme_1 = Eigen::Matrix<local_scalar_t__, -1, 1>(N);
      stan::math::fill(zme_1, DUMMY_VAR__);
      
      current_statement__ = 6;
      zme_1 = in__.vector(N);
      Eigen::Matrix<local_scalar_t__, -1, 1> Xme_1;
      Xme_1 = Eigen::Matrix<local_scalar_t__, -1, 1>(N);
      stan::math::fill(Xme_1, DUMMY_VAR__);
      
      current_statement__ = 8;
      assign(Xme_1, nil_index_list(),
        add(meanme_1[(1 - 1)], multiply(sdme_1[(1 - 1)], zme_1)),
        "assigning variable Xme_1");
      {
        current_statement__ = 17;
        if (logical_negation(prior_only)) {
          current_statement__ = 10;
          validate_non_negative_index("mu", "N", N);
          Eigen::Matrix<local_scalar_t__, -1, 1> mu;
          mu = Eigen::Matrix<local_scalar_t__, -1, 1>(N);
          stan::math::fill(mu, DUMMY_VAR__);
          
          current_statement__ = 11;
          assign(mu, nil_index_list(), add(Intercept, rep_vector(0.0, N)),
            "assigning variable mu");
          current_statement__ = 14;
          for (int n = 1; n <= N; ++n) {
            current_statement__ = 12;
            assign(mu, cons_list(index_uni(n), nil_index_list()),
              (mu[(n - 1)] + (bsp[(1 - 1)] * Xme_1[(n - 1)])),
              "assigning variable mu");}
          current_statement__ = 15;
          lp_accum__.add(normal_lpdf<false>(Y, mu, sigma));
        } 
        current_statement__ = 18;
        lp_accum__.add(student_t_lpdf<false>(Intercept, 3, 0.1, 2.5));
        current_statement__ = 19;
        lp_accum__.add(
          (student_t_lpdf<false>(sigma, 3, 0, 2.5) -
            (1 * student_t_lccdf(0, 3, 0, 2.5))));
        current_statement__ = 20;
        lp_accum__.add(normal_lpdf<false>(Xn_1, Xme_1, noise_1));
        current_statement__ = 21;
        lp_accum__.add(std_normal_lpdf<false>(zme_1));
      }
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
      // 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_impl() 
    
  template <typename RNG, typename VecR, typename VecI, typename VecVar, stan::require_vector_like_vt<std::is_floating_point, VecR>* = nullptr, stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr, stan::require_std_vector_vt<std::is_floating_point, VecVar>* = nullptr>
  inline void write_array_impl(RNG& base_rng__, VecR& params_r__,
                               VecI& params_i__, VecVar& vars__,
                               const bool emit_transformed_parameters__ = true,
                               const bool emit_generated_quantities__ = true,
                               std::ostream* pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    vars__.resize(0);
    stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
    static const char* function__ = "model1c8dcb7bec352c__namespace::write_array";
(void) function__;  // suppress unused var warning

    (void) function__;  // suppress unused var warning

    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

    
    try {
      double Intercept;
      Intercept = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 1;
      Intercept = in__.scalar();
      Eigen::Matrix<double, -1, 1> bsp;
      bsp = Eigen::Matrix<double, -1, 1>(Ksp);
      stan::math::fill(bsp, std::numeric_limits<double>::quiet_NaN());
      
      current_statement__ = 2;
      bsp = in__.vector(Ksp);
      double sigma;
      sigma = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 3;
      sigma = in__.scalar();
      current_statement__ = 3;
      sigma = stan::math::lb_constrain(sigma, 0);
      Eigen::Matrix<double, -1, 1> meanme_1;
      meanme_1 = Eigen::Matrix<double, -1, 1>(Mme_1);
      stan::math::fill(meanme_1, std::numeric_limits<double>::quiet_NaN());
      
      current_statement__ = 4;
      meanme_1 = in__.vector(Mme_1);
      Eigen::Matrix<double, -1, 1> sdme_1;
      sdme_1 = Eigen::Matrix<double, -1, 1>(Mme_1);
      stan::math::fill(sdme_1, std::numeric_limits<double>::quiet_NaN());
      
      current_statement__ = 5;
      sdme_1 = in__.vector(Mme_1);
      current_statement__ = 5;
      for (int sym1__ = 1; sym1__ <= Mme_1; ++sym1__) {
        current_statement__ = 5;
        assign(sdme_1, cons_list(index_uni(sym1__), nil_index_list()),
          stan::math::lb_constrain(sdme_1[(sym1__ - 1)], 0),
          "assigning variable sdme_1");}
      Eigen::Matrix<double, -1, 1> zme_1;
      zme_1 = Eigen::Matrix<double, -1, 1>(N);
      stan::math::fill(zme_1, std::numeric_limits<double>::quiet_NaN());
      
      current_statement__ = 6;
      zme_1 = in__.vector(N);
      Eigen::Matrix<double, -1, 1> Xme_1;
      Xme_1 = Eigen::Matrix<double, -1, 1>(N);
      stan::math::fill(Xme_1, std::numeric_limits<double>::quiet_NaN());
      
      vars__.emplace_back(Intercept);
      for (int sym1__ = 1; sym1__ <= Ksp; ++sym1__) {
        vars__.emplace_back(bsp[(sym1__ - 1)]);}
      vars__.emplace_back(sigma);
      for (int sym1__ = 1; sym1__ <= Mme_1; ++sym1__) {
        vars__.emplace_back(meanme_1[(sym1__ - 1)]);}
      for (int sym1__ = 1; sym1__ <= Mme_1; ++sym1__) {
        vars__.emplace_back(sdme_1[(sym1__ - 1)]);}
      for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
        vars__.emplace_back(zme_1[(sym1__ - 1)]);}
      if (logical_negation((primitive_value(emit_transformed_parameters__) ||
            primitive_value(emit_generated_quantities__)))) {
        return ;
      } 
      current_statement__ = 8;
      assign(Xme_1, nil_index_list(),
        add(meanme_1[(1 - 1)], multiply(sdme_1[(1 - 1)], zme_1)),
        "assigning variable Xme_1");
      if (emit_transformed_parameters__) {
        for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
          vars__.emplace_back(Xme_1[(sym1__ - 1)]);}
      } 
      if (logical_negation(emit_generated_quantities__)) {
        return ;
      } 
      double b_Intercept;
      b_Intercept = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 9;
      b_Intercept = Intercept;
      vars__.emplace_back(b_Intercept);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
      // Next line prevents compiler griping about no return
      throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 
    }
    } // write_array_impl() 
    
  template <typename VecVar, typename VecI, stan::require_std_vector_t<VecVar>* = nullptr, stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
  inline void transform_inits_impl(const stan::io::var_context& context__,
                                   VecI& params_i__, VecVar& vars__,
                                   std::ostream* pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    vars__.clear();
    vars__.reserve(num_params_r__);
    
    try {
      int pos__;
      pos__ = std::numeric_limits<int>::min();
      
      pos__ = 1;
      double Intercept;
      Intercept = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 1;
      Intercept = context__.vals_r("Intercept")[(1 - 1)];
      Eigen::Matrix<double, -1, 1> bsp;
      bsp = Eigen::Matrix<double, -1, 1>(Ksp);
      stan::math::fill(bsp, std::numeric_limits<double>::quiet_NaN());
      
      {
        std::vector<local_scalar_t__> bsp_flat__;
        current_statement__ = 2;
        assign(bsp_flat__, nil_index_list(), context__.vals_r("bsp"),
          "assigning variable bsp_flat__");
        current_statement__ = 2;
        pos__ = 1;
        current_statement__ = 2;
        for (int sym1__ = 1; sym1__ <= Ksp; ++sym1__) {
          current_statement__ = 2;
          assign(bsp, cons_list(index_uni(sym1__), nil_index_list()),
            bsp_flat__[(pos__ - 1)], "assigning variable bsp");
          current_statement__ = 2;
          pos__ = (pos__ + 1);}
      }
      double sigma;
      sigma = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 3;
      sigma = context__.vals_r("sigma")[(1 - 1)];
      double sigma_free__;
      sigma_free__ = std::numeric_limits<double>::quiet_NaN();
      
      current_statement__ = 3;
      sigma_free__ = stan::math::lb_free(sigma, 0);
      Eigen::Matrix<double, -1, 1> meanme_1;
      meanme_1 = Eigen::Matrix<double, -1, 1>(Mme_1);
      stan::math::fill(meanme_1, std::numeric_limits<double>::quiet_NaN());
      
      {
        std::vector<local_scalar_t__> meanme_1_flat__;
        current_statement__ = 4;
        assign(meanme_1_flat__, nil_index_list(),
          context__.vals_r("meanme_1"), "assigning variable meanme_1_flat__");
        current_statement__ = 4;
        pos__ = 1;
        current_statement__ = 4;
        for (int sym1__ = 1; sym1__ <= Mme_1; ++sym1__) {
          current_statement__ = 4;
          assign(meanme_1, cons_list(index_uni(sym1__), nil_index_list()),
            meanme_1_flat__[(pos__ - 1)], "assigning variable meanme_1");
          current_statement__ = 4;
          pos__ = (pos__ + 1);}
      }
      Eigen::Matrix<double, -1, 1> sdme_1;
      sdme_1 = Eigen::Matrix<double, -1, 1>(Mme_1);
      stan::math::fill(sdme_1, std::numeric_limits<double>::quiet_NaN());
      
      {
        std::vector<local_scalar_t__> sdme_1_flat__;
        current_statement__ = 5;
        assign(sdme_1_flat__, nil_index_list(), context__.vals_r("sdme_1"),
          "assigning variable sdme_1_flat__");
        current_statement__ = 5;
        pos__ = 1;
        current_statement__ = 5;
        for (int sym1__ = 1; sym1__ <= Mme_1; ++sym1__) {
          current_statement__ = 5;
          assign(sdme_1, cons_list(index_uni(sym1__), nil_index_list()),
            sdme_1_flat__[(pos__ - 1)], "assigning variable sdme_1");
          current_statement__ = 5;
          pos__ = (pos__ + 1);}
      }
      Eigen::Matrix<double, -1, 1> sdme_1_free__;
      sdme_1_free__ = Eigen::Matrix<double, -1, 1>(Mme_1);
      stan::math::fill(sdme_1_free__, std::numeric_limits<double>::quiet_NaN());
      
      current_statement__ = 5;
      for (int sym1__ = 1; sym1__ <= Mme_1; ++sym1__) {
        current_statement__ = 5;
        assign(sdme_1_free__, cons_list(index_uni(sym1__), nil_index_list()),
          stan::math::lb_free(sdme_1[(sym1__ - 1)], 0),
          "assigning variable sdme_1_free__");}
      Eigen::Matrix<double, -1, 1> zme_1;
      zme_1 = Eigen::Matrix<double, -1, 1>(N);
      stan::math::fill(zme_1, std::numeric_limits<double>::quiet_NaN());
      
      {
        std::vector<local_scalar_t__> zme_1_flat__;
        current_statement__ = 6;
        assign(zme_1_flat__, nil_index_list(), context__.vals_r("zme_1"),
          "assigning variable zme_1_flat__");
        current_statement__ = 6;
        pos__ = 1;
        current_statement__ = 6;
        for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
          current_statement__ = 6;
          assign(zme_1, cons_list(index_uni(sym1__), nil_index_list()),
            zme_1_flat__[(pos__ - 1)], "assigning variable zme_1");
          current_statement__ = 6;
          pos__ = (pos__ + 1);}
      }
      vars__.emplace_back(Intercept);
      for (int sym1__ = 1; sym1__ <= Ksp; ++sym1__) {
        vars__.emplace_back(bsp[(sym1__ - 1)]);}
      vars__.emplace_back(sigma_free__);
      for (int sym1__ = 1; sym1__ <= Mme_1; ++sym1__) {
        vars__.emplace_back(meanme_1[(sym1__ - 1)]);}
      for (int sym1__ = 1; sym1__ <= Mme_1; ++sym1__) {
        vars__.emplace_back(sdme_1_free__[(sym1__ - 1)]);}
      for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
        vars__.emplace_back(zme_1[(sym1__ - 1)]);}
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
      // Next line prevents compiler griping about no return
      throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 
    }
    } // transform_inits_impl() 
    
  inline void get_param_names(std::vector<std::string>& names__) const {
    
    names__.clear();
    names__.emplace_back("Intercept");
    names__.emplace_back("bsp");
    names__.emplace_back("sigma");
    names__.emplace_back("meanme_1");
    names__.emplace_back("sdme_1");
    names__.emplace_back("zme_1");
    names__.emplace_back("Xme_1");
    names__.emplace_back("b_Intercept");
    } // get_param_names() 
    
  inline void get_dims(std::vector<std::vector<size_t>>& dimss__) const {
    dimss__.clear();
    dimss__.emplace_back(std::vector<size_t>{});
    
    dimss__.emplace_back(std::vector<size_t>{static_cast<size_t>(Ksp)});
    
    dimss__.emplace_back(std::vector<size_t>{});
    
    dimss__.emplace_back(std::vector<size_t>{static_cast<size_t>(Mme_1)});
    
    dimss__.emplace_back(std::vector<size_t>{static_cast<size_t>(Mme_1)});
    
    dimss__.emplace_back(std::vector<size_t>{static_cast<size_t>(N)});
    
    dimss__.emplace_back(std::vector<size_t>{static_cast<size_t>(N)});
    
    dimss__.emplace_back(std::vector<size_t>{});
    
    } // get_dims() 
    
  inline void constrained_param_names(
                                      std::vector<std::string>& param_names__,
                                      bool emit_transformed_parameters__ = true,
                                      bool emit_generated_quantities__ = true) const
    final {
    
    param_names__.emplace_back(std::string() + "Intercept");
    for (int sym1__ = 1; sym1__ <= Ksp; ++sym1__) {
      {
        param_names__.emplace_back(std::string() + "bsp" + '.' + std::to_string(sym1__));
      }}
    param_names__.emplace_back(std::string() + "sigma");
    for (int sym1__ = 1; sym1__ <= Mme_1; ++sym1__) {
      {
        param_names__.emplace_back(std::string() + "meanme_1" + '.' + std::to_string(sym1__));
      }}
    for (int sym1__ = 1; sym1__ <= Mme_1; ++sym1__) {
      {
        param_names__.emplace_back(std::string() + "sdme_1" + '.' + std::to_string(sym1__));
      }}
    for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
      {
        param_names__.emplace_back(std::string() + "zme_1" + '.' + std::to_string(sym1__));
      }}
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
        {
          param_names__.emplace_back(std::string() + "Xme_1" + '.' + std::to_string(sym1__));
        }}
    }
    
    if (emit_generated_quantities__) {
      param_names__.emplace_back(std::string() + "b_Intercept");
    }
    
    } // constrained_param_names() 
    
  inline void unconstrained_param_names(
                                        std::vector<std::string>& param_names__,
                                        bool emit_transformed_parameters__ = true,
                                        bool emit_generated_quantities__ = true) const
    final {
    
    param_names__.emplace_back(std::string() + "Intercept");
    for (int sym1__ = 1; sym1__ <= Ksp; ++sym1__) {
      {
        param_names__.emplace_back(std::string() + "bsp" + '.' + std::to_string(sym1__));
      }}
    param_names__.emplace_back(std::string() + "sigma");
    for (int sym1__ = 1; sym1__ <= Mme_1; ++sym1__) {
      {
        param_names__.emplace_back(std::string() + "meanme_1" + '.' + std::to_string(sym1__));
      }}
    for (int sym1__ = 1; sym1__ <= Mme_1; ++sym1__) {
      {
        param_names__.emplace_back(std::string() + "sdme_1" + '.' + std::to_string(sym1__));
      }}
    for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
      {
        param_names__.emplace_back(std::string() + "zme_1" + '.' + std::to_string(sym1__));
      }}
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
        {
          param_names__.emplace_back(std::string() + "Xme_1" + '.' + std::to_string(sym1__));
        }}
    }
    
    if (emit_generated_quantities__) {
      param_names__.emplace_back(std::string() + "b_Intercept");
    }
    
    } // unconstrained_param_names() 
    
  inline std::string get_constrained_sizedtypes() const {
    stringstream s__;
    s__ << "[{\"name\":\"Intercept\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"bsp\",\"type\":{\"name\":\"vector\",\"length\":" << Ksp << "},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"meanme_1\",\"type\":{\"name\":\"vector\",\"length\":" << Mme_1 << "},\"block\":\"parameters\"},{\"name\":\"sdme_1\",\"type\":{\"name\":\"vector\",\"length\":" << Mme_1 << "},\"block\":\"parameters\"},{\"name\":\"zme_1\",\"type\":{\"name\":\"vector\",\"length\":" << N << "},\"block\":\"parameters\"},{\"name\":\"Xme_1\",\"type\":{\"name\":\"vector\",\"length\":" << N << "},\"block\":\"transformed_parameters\"},{\"name\":\"b_Intercept\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]";
    return s__.str();
    } // get_constrained_sizedtypes() 
    
  inline std::string get_unconstrained_sizedtypes() const {
    stringstream s__;
    s__ << "[{\"name\":\"Intercept\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"bsp\",\"type\":{\"name\":\"vector\",\"length\":" << Ksp << "},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"meanme_1\",\"type\":{\"name\":\"vector\",\"length\":" << Mme_1 << "},\"block\":\"parameters\"},{\"name\":\"sdme_1\",\"type\":{\"name\":\"vector\",\"length\":" << Mme_1 << "},\"block\":\"parameters\"},{\"name\":\"zme_1\",\"type\":{\"name\":\"vector\",\"length\":" << N << "},\"block\":\"parameters\"},{\"name\":\"Xme_1\",\"type\":{\"name\":\"vector\",\"length\":" << N << "},\"block\":\"transformed_parameters\"},{\"name\":\"b_Intercept\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]";
    return s__.str();
    } // get_unconstrained_sizedtypes() 
    
  
    // Begin method overload boilerplate
    template <typename RNG>
    inline void write_array(RNG& base_rng,
                            Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
                            Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
                            const bool emit_transformed_parameters = true,
                            const bool emit_generated_quantities = true,
                            std::ostream* pstream = nullptr) const {
      std::vector<double> vars_vec(vars.size());
      std::vector<int> params_i;
      write_array_impl(base_rng, params_r, params_i, vars_vec,
          emit_transformed_parameters, emit_generated_quantities, pstream);
      vars.resize(vars_vec.size());
      for (int i = 0; i < vars.size(); ++i) {
        vars.coeffRef(i) = vars_vec[i];
      }
    }

    template <typename RNG>
    inline void write_array(RNG& base_rng, std::vector<double>& params_r,
                            std::vector<int>& params_i,
                            std::vector<double>& vars,
                            bool emit_transformed_parameters = true,
                            bool emit_generated_quantities = true,
                            std::ostream* pstream = nullptr) const {
      write_array_impl(base_rng, params_r, params_i, vars, emit_transformed_parameters, emit_generated_quantities, pstream);
    }

    template <bool propto__, bool jacobian__, typename T_>
    inline T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
                       std::ostream* pstream = nullptr) const {
      Eigen::Matrix<int, -1, 1> params_i;
      return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
    }

    template <bool propto__, bool jacobian__, typename T__>
    inline T__ log_prob(std::vector<T__>& params_r,
                        std::vector<int>& params_i,
                        std::ostream* pstream = nullptr) const {
      return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
    }
  

    inline void transform_inits(const stan::io::var_context& context,
                         Eigen::Matrix<double, Eigen::Dynamic, 1>& params_r,
                         std::ostream* pstream = nullptr) const final {
      std::vector<double> params_r_vec(params_r.size());
      std::vector<int> params_i;
      transform_inits_impl(context, params_i, params_r_vec, pstream);
      params_r.resize(params_r_vec.size());
      for (int i = 0; i < params_r.size(); ++i) {
        params_r.coeffRef(i) = params_r_vec[i];
      }
    }
    inline void transform_inits(const stan::io::var_context& context,
                                std::vector<int>& params_i,
                                std::vector<double>& vars,
                                std::ostream* pstream = nullptr) const final {
      transform_inits_impl(context, params_i, vars, pstream);
    }        

};
}
using stan_model = model1c8dcb7bec352c__namespace::model1c8dcb7bec352c_;

#ifndef USING_R

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

stan::math::profile_map& get_stan_profile_data() {
  return model1c8dcb7bec352c__namespace::profiles__;
}

#endif



#endif