#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.35.0
#include <stan/model/model_header.hpp>
namespace model109c732fa5cb3__namespace {
using stan::model::model_base_crtp;
using namespace stan::math;
stan::math::profile_map profiles__;
static constexpr std::array<const char*, 76> locations_array__ =
  {" (found before start of program)",
  " (in 'anon_model', line 85, column 2 to column 15)",
  " (in 'anon_model', line 86, column 2 to column 28)",
  " (in 'anon_model', line 87, column 2 to column 25)",
  " (in 'anon_model', line 88, column 2 to column 18)",
  " (in 'anon_model', line 91, column 2 to column 16)",
  " (in 'anon_model', line 92, column 2 to column 18)",
  " (in 'anon_model', line 117, column 2 to column 67)",
  " (in 'anon_model', line 93, column 2 to column 34)",
  " (in 'anon_model', line 94, column 2 to column 44)",
  " (in 'anon_model', line 95, column 2 to column 48)",
  " (in 'anon_model', line 96, column 2 to column 43)",
  " (in 'anon_model', line 102, column 11 to column 12)",
  " (in 'anon_model', line 102, column 4 to column 38)",
  " (in 'anon_model', line 103, column 4 to column 17)",
  " (in 'anon_model', line 106, column 6 to column 47)",
  " (in 'anon_model', line 104, column 19 to line 107, column 5)",
  " (in 'anon_model', line 104, column 4 to line 107, column 5)",
  " (in 'anon_model', line 109, column 6 to column 63)",
  " (in 'anon_model', line 108, column 19 to line 110, column 5)",
  " (in 'anon_model', line 108, column 4 to line 110, column 5)",
  " (in 'anon_model', line 100, column 19 to line 111, column 3)",
  " (in 'anon_model', line 100, column 2 to line 111, column 3)",
  " (in 'anon_model', line 113, column 2 to column 19)",
  " (in 'anon_model', line 63, column 2 to column 17)",
  " (in 'anon_model', line 64, column 8 to column 9)",
  " (in 'anon_model', line 64, column 2 to column 17)",
  " (in 'anon_model', line 65, column 2 to column 22)",
  " (in 'anon_model', line 66, column 2 to column 17)",
  " (in 'anon_model', line 67, column 9 to column 10)",
  " (in 'anon_model', line 67, column 12 to column 13)",
  " (in 'anon_model', line 67, column 2 to column 17)",
  " (in 'anon_model', line 68, column 2 to column 18)",
  " (in 'anon_model', line 69, column 2 to column 19)",
  " (in 'anon_model', line 70, column 2 to column 19)",
  " (in 'anon_model', line 71, column 8 to column 11)",
  " (in 'anon_model', line 71, column 2 to column 30)",
  " (in 'anon_model', line 72, column 8 to column 9)",
  " (in 'anon_model', line 72, column 2 to column 21)",
  " (in 'anon_model', line 73, column 9 to column 15)",
  " (in 'anon_model', line 73, column 2 to column 28)",
  " (in 'anon_model', line 74, column 2 to column 17)",
  " (in 'anon_model', line 77, column 9 to column 10)",
  " (in 'anon_model', line 77, column 12 to column 14)",
  " (in 'anon_model', line 77, column 2 to column 19)",
  " (in 'anon_model', line 78, column 9 to column 11)",
  " (in 'anon_model', line 78, column 2 to column 21)",
  " (in 'anon_model', line 80, column 4 to column 30)",
  " (in 'anon_model', line 81, column 4 to column 34)",
  " (in 'anon_model', line 79, column 17 to line 82, column 3)",
  " (in 'anon_model', line 79, column 2 to line 82, column 3)",
  " (in 'anon_model', line 85, column 9 to column 11)",
  " (in 'anon_model', line 86, column 10 to column 16)",
  " (in 'anon_model', line 87, column 10 to column 16)",
  " (in 'anon_model', line 88, column 9 to column 12)",
  " (in 'anon_model', line 117, column 9 to column 15)",
  " (in 'anon_model', line 13, column 5 to column 38)",
  " (in 'anon_model', line 19, column 7 to column 85)",
  " (in 'anon_model', line 18, column 12 to line 20, column 6)",
  " (in 'anon_model', line 17, column 7 to column 59)",
  " (in 'anon_model', line 16, column 33 to line 18, column 6)",
  " (in 'anon_model', line 16, column 12 to line 20, column 6)",
  " (in 'anon_model', line 15, column 7 to column 52)",
  " (in 'anon_model', line 14, column 17 to line 16, column 6)",
  " (in 'anon_model', line 14, column 5 to line 20, column 6)",
  " (in 'anon_model', line 12, column 71 to line 21, column 4)",
  " (in 'anon_model', line 33, column 5 to column 66)",
  " (in 'anon_model', line 32, column 93 to line 34, column 4)",
  " (in 'anon_model', line 45, column 5 to column 60)",
  " (in 'anon_model', line 44, column 82 to line 46, column 4)",
  " (in 'anon_model', line 58, column 6 to column 43)",
  " (in 'anon_model', line 57, column 11 to line 59, column 5)",
  " (in 'anon_model', line 56, column 6 to column 15)",
  " (in 'anon_model', line 55, column 16 to line 57, column 5)",
  " (in 'anon_model', line 55, column 4 to line 59, column 5)",
  " (in 'anon_model', line 54, column 31 to line 60, column 3)"};
template <bool propto__, typename T0__, typename T1__, typename T2__,
          typename T3__,
          stan::require_all_t<std::is_integral<T0__>,
                              stan::math::disjunction<stan::is_autodiff<T1__>,
                                                      std::is_floating_point<T1__>>,
                              stan::math::disjunction<stan::is_autodiff<T2__>,
                                                      std::is_floating_point<T2__>>,
                              stan::is_col_vector<T3__>,
                              stan::is_vt_not_complex<T3__>>* = nullptr>
stan::promote_args_t<T1__, T2__, stan::base_type_t<T3__>>
cumulative_logit_lpmf(const T0__& y, const T1__& mu, const T2__& disc,
                      const T3__& thres_arg__, std::ostream* pstream__);
template <bool propto__, typename T0__, typename T1__, typename T2__,
          typename T3__, typename T4__,
          stan::require_all_t<std::is_integral<T0__>,
                              stan::math::disjunction<stan::is_autodiff<T1__>,
                                                      std::is_floating_point<T1__>>,
                              stan::math::disjunction<stan::is_autodiff<T2__>,
                                                      std::is_floating_point<T2__>>,
                              stan::is_col_vector<T3__>,
                              stan::is_vt_not_complex<T3__>,
                              stan::is_std_vector<T4__>,
                              std::is_integral<stan::value_type_t<T4__>>>* = nullptr>
stan::promote_args_t<T1__, T2__, stan::base_type_t<T3__>>
cumulative_logit_merged_lpmf(const T0__& y, const T1__& mu, const T2__& disc,
                             const T3__& thres_arg__, const T4__& j,
                             std::ostream* pstream__);
template <bool propto__, typename T0__, typename T1__, typename T2__,
          typename T3__,
          stan::require_all_t<std::is_integral<T0__>,
                              stan::math::disjunction<stan::is_autodiff<T1__>,
                                                      std::is_floating_point<T1__>>,
                              stan::is_col_vector<T2__>,
                              stan::is_vt_not_complex<T2__>,
                              stan::is_std_vector<T3__>,
                              std::is_integral<stan::value_type_t<T3__>>>* = nullptr>
stan::promote_args_t<T1__, stan::base_type_t<T2__>>
ordered_logistic_merged_lpmf(const T0__& y, const T1__& mu, const T2__&
                             thres_arg__, const T3__& j, std::ostream*
                             pstream__);
template <typename T0__, typename T1__,
          stan::require_all_t<stan::is_col_vector<T0__>,
                              stan::is_vt_not_complex<T0__>,
                              std::is_integral<T1__>>* = nullptr>
stan::promote_args_t<stan::base_type_t<T0__>>
mo(const T0__& scale_arg__, const T1__& i, std::ostream* pstream__);
// real cumulative_logit_lpmf(int, real, real, vector)
template <bool propto__, typename T0__, typename T1__, typename T2__,
          typename T3__,
          stan::require_all_t<std::is_integral<T0__>,
                              stan::math::disjunction<stan::is_autodiff<T1__>,
                                                      std::is_floating_point<T1__>>,
                              stan::math::disjunction<stan::is_autodiff<T2__>,
                                                      std::is_floating_point<T2__>>,
                              stan::is_col_vector<T3__>,
                              stan::is_vt_not_complex<T3__>>*>
stan::promote_args_t<T1__, T2__, stan::base_type_t<T3__>>
cumulative_logit_lpmf(const T0__& y, const T1__& mu, const T2__& disc,
                      const T3__& thres_arg__, std::ostream* pstream__) {
  using local_scalar_t__ = stan::promote_args_t<T1__, T2__,
                             stan::base_type_t<T3__>>;
  int current_statement__ = 0;
  // suppress unused var warning
  (void) current_statement__;
  const auto& thres = stan::math::to_ref(thres_arg__);
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    int nthres = std::numeric_limits<int>::min();
    current_statement__ = 56;
    nthres = stan::math::num_elements(thres);
    current_statement__ = 64;
    if (stan::math::logical_eq(y, 1)) {
      current_statement__ = 62;
      return stan::math::log_inv_logit((disc *
               (stan::model::rvalue(thres, "thres", stan::model::index_uni(1))
               - mu)));
    } else {
      current_statement__ = 61;
      if (stan::math::logical_eq(y, (nthres + 1))) {
        current_statement__ = 59;
        return stan::math::log1m_inv_logit((disc *
                 (stan::model::rvalue(thres, "thres",
                    stan::model::index_uni(nthres)) - mu)));
      } else {
        current_statement__ = 57;
        return stan::math::log_inv_logit_diff((disc *
                 (stan::model::rvalue(thres, "thres",
                    stan::model::index_uni(y)) - mu)), (disc *
                 (stan::model::rvalue(thres, "thres",
                    stan::model::index_uni((y - 1))) - mu)));
      }
    }
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
// real cumulative_logit_merged_lpmf(int, real, real, vector, array[] int)
template <bool propto__, typename T0__, typename T1__, typename T2__,
          typename T3__, typename T4__,
          stan::require_all_t<std::is_integral<T0__>,
                              stan::math::disjunction<stan::is_autodiff<T1__>,
                                                      std::is_floating_point<T1__>>,
                              stan::math::disjunction<stan::is_autodiff<T2__>,
                                                      std::is_floating_point<T2__>>,
                              stan::is_col_vector<T3__>,
                              stan::is_vt_not_complex<T3__>,
                              stan::is_std_vector<T4__>,
                              std::is_integral<stan::value_type_t<T4__>>>*>
stan::promote_args_t<T1__, T2__, stan::base_type_t<T3__>>
cumulative_logit_merged_lpmf(const T0__& y, const T1__& mu, const T2__& disc,
                             const T3__& thres_arg__, const T4__& j,
                             std::ostream* pstream__) {
  using local_scalar_t__ = stan::promote_args_t<T1__, T2__,
                             stan::base_type_t<T3__>>;
  int current_statement__ = 0;
  // suppress unused var warning
  (void) current_statement__;
  const auto& thres = stan::math::to_ref(thres_arg__);
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    current_statement__ = 66;
    return cumulative_logit_lpmf<false>(y, mu, disc,
             stan::model::rvalue(thres, "thres",
               stan::model::index_min_max(
                 stan::model::rvalue(j, "j", stan::model::index_uni(1)),
                 stan::model::rvalue(j, "j", stan::model::index_uni(2)))),
             pstream__);
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
// real ordered_logistic_merged_lpmf(int, real, vector, array[] int)
template <bool propto__, typename T0__, typename T1__, typename T2__,
          typename T3__,
          stan::require_all_t<std::is_integral<T0__>,
                              stan::math::disjunction<stan::is_autodiff<T1__>,
                                                      std::is_floating_point<T1__>>,
                              stan::is_col_vector<T2__>,
                              stan::is_vt_not_complex<T2__>,
                              stan::is_std_vector<T3__>,
                              std::is_integral<stan::value_type_t<T3__>>>*>
stan::promote_args_t<T1__, stan::base_type_t<T2__>>
ordered_logistic_merged_lpmf(const T0__& y, const T1__& mu, const T2__&
                             thres_arg__, const T3__& j, std::ostream*
                             pstream__) {
  using local_scalar_t__ = stan::promote_args_t<T1__,
                             stan::base_type_t<T2__>>;
  int current_statement__ = 0;
  // suppress unused var warning
  (void) current_statement__;
  const auto& thres = stan::math::to_ref(thres_arg__);
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    current_statement__ = 68;
    return stan::math::ordered_logistic_lpmf<false>(y, mu,
             stan::model::rvalue(thres, "thres",
               stan::model::index_min_max(
                 stan::model::rvalue(j, "j", stan::model::index_uni(1)),
                 stan::model::rvalue(j, "j", stan::model::index_uni(2)))));
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
// real mo(vector, int)
template <typename T0__, typename T1__,
          stan::require_all_t<stan::is_col_vector<T0__>,
                              stan::is_vt_not_complex<T0__>,
                              std::is_integral<T1__>>*>
stan::promote_args_t<stan::base_type_t<T0__>>
mo(const T0__& scale_arg__, const T1__& i, std::ostream* pstream__) {
  using local_scalar_t__ = stan::promote_args_t<stan::base_type_t<T0__>>;
  int current_statement__ = 0;
  // suppress unused var warning
  (void) current_statement__;
  const auto& scale = stan::math::to_ref(scale_arg__);
  static constexpr bool propto__ = true;
  // suppress unused var warning
  (void) propto__;
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    current_statement__ = 74;
    if (stan::math::logical_eq(i, 0)) {
      current_statement__ = 72;
      return 0;
    } else {
      current_statement__ = 70;
      return (stan::math::rows(scale) *
             stan::math::sum(
               stan::model::rvalue(scale, "scale",
                 stan::model::index_min_max(1, i))));
    }
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
class model109c732fa5cb3_ final : public model_base_crtp<model109c732fa5cb3_> {
private:
  int N;
  std::vector<int> Y;
  int nthres;
  int K;
  Eigen::Matrix<double,-1,-1> X_data__;
  int Kc;
  int Ksp;
  int Imo;
  std::vector<int> Jmo;
  std::vector<int> Xmo_1;
  Eigen::Matrix<double,-1,1> con_simo_1_data__;
  int prior_only;
  Eigen::Matrix<double,-1,-1> Xc_data__;
  Eigen::Matrix<double,-1,1> means_X_data__;
  int simo_1_1dim__;
  Eigen::Map<Eigen::Matrix<double,-1,-1>> X{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> con_simo_1{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> Xc{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> means_X{nullptr, 0};
public:
  ~model109c732fa5cb3_() {}
  model109c732fa5cb3_(stan::io::var_context& context__, unsigned int
                      random_seed__ = 0, std::ostream* pstream__ = nullptr)
      : model_base_crtp(0) {
    int current_statement__ = 0;
    // suppress unused var warning
    (void) current_statement__;
    using local_scalar_t__ = double;
    auto base_rng__ = stan::services::util::create_rng(random_seed__, 0);
    // suppress unused var warning
    (void) base_rng__;
    static constexpr const char* function__ =
      "model109c732fa5cb3__namespace::model109c732fa5cb3_";
    // suppress unused var warning
    (void) function__;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    try {
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      current_statement__ = 24;
      context__.validate_dims("data initialization", "N", "int",
        std::vector<size_t>{});
      N = std::numeric_limits<int>::min();
      current_statement__ = 24;
      N = context__.vals_i("N")[(1 - 1)];
      current_statement__ = 24;
      stan::math::check_greater_or_equal(function__, "N", N, 1);
      current_statement__ = 25;
      stan::math::validate_non_negative_index("Y", "N", N);
      current_statement__ = 26;
      context__.validate_dims("data initialization", "Y", "int",
        std::vector<size_t>{static_cast<size_t>(N)});
      Y = std::vector<int>(N, std::numeric_limits<int>::min());
      current_statement__ = 26;
      Y = context__.vals_i("Y");
      current_statement__ = 27;
      context__.validate_dims("data initialization", "nthres", "int",
        std::vector<size_t>{});
      nthres = std::numeric_limits<int>::min();
      current_statement__ = 27;
      nthres = context__.vals_i("nthres")[(1 - 1)];
      current_statement__ = 27;
      stan::math::check_greater_or_equal(function__, "nthres", nthres, 2);
      current_statement__ = 28;
      context__.validate_dims("data initialization", "K", "int",
        std::vector<size_t>{});
      K = std::numeric_limits<int>::min();
      current_statement__ = 28;
      K = context__.vals_i("K")[(1 - 1)];
      current_statement__ = 28;
      stan::math::check_greater_or_equal(function__, "K", K, 1);
      current_statement__ = 29;
      stan::math::validate_non_negative_index("X", "N", N);
      current_statement__ = 30;
      stan::math::validate_non_negative_index("X", "K", K);
      current_statement__ = 31;
      context__.validate_dims("data initialization", "X", "double",
        std::vector<size_t>{static_cast<size_t>(N), static_cast<size_t>(K)});
      X_data__ = Eigen::Matrix<double,-1,-1>::Constant(N, K,
                   std::numeric_limits<double>::quiet_NaN());
      new (&X) Eigen::Map<Eigen::Matrix<double,-1,-1>>(X_data__.data(), N, K);
      {
        std::vector<local_scalar_t__> X_flat__;
        current_statement__ = 31;
        X_flat__ = context__.vals_r("X");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= K; ++sym1__) {
          for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
            stan::model::assign(X, X_flat__[(pos__ - 1)],
              "assigning variable X", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 32;
      context__.validate_dims("data initialization", "Kc", "int",
        std::vector<size_t>{});
      Kc = std::numeric_limits<int>::min();
      current_statement__ = 32;
      Kc = context__.vals_i("Kc")[(1 - 1)];
      current_statement__ = 32;
      stan::math::check_greater_or_equal(function__, "Kc", Kc, 1);
      current_statement__ = 33;
      context__.validate_dims("data initialization", "Ksp", "int",
        std::vector<size_t>{});
      Ksp = std::numeric_limits<int>::min();
      current_statement__ = 33;
      Ksp = context__.vals_i("Ksp")[(1 - 1)];
      current_statement__ = 33;
      stan::math::check_greater_or_equal(function__, "Ksp", Ksp, 1);
      current_statement__ = 34;
      context__.validate_dims("data initialization", "Imo", "int",
        std::vector<size_t>{});
      Imo = std::numeric_limits<int>::min();
      current_statement__ = 34;
      Imo = context__.vals_i("Imo")[(1 - 1)];
      current_statement__ = 34;
      stan::math::check_greater_or_equal(function__, "Imo", Imo, 1);
      current_statement__ = 35;
      stan::math::validate_non_negative_index("Jmo", "Imo", Imo);
      current_statement__ = 36;
      context__.validate_dims("data initialization", "Jmo", "int",
        std::vector<size_t>{static_cast<size_t>(Imo)});
      Jmo = std::vector<int>(Imo, std::numeric_limits<int>::min());
      current_statement__ = 36;
      Jmo = context__.vals_i("Jmo");
      current_statement__ = 36;
      stan::math::check_greater_or_equal(function__, "Jmo", Jmo, 1);
      current_statement__ = 37;
      stan::math::validate_non_negative_index("Xmo_1", "N", N);
      current_statement__ = 38;
      context__.validate_dims("data initialization", "Xmo_1", "int",
        std::vector<size_t>{static_cast<size_t>(N)});
      Xmo_1 = std::vector<int>(N, std::numeric_limits<int>::min());
      current_statement__ = 38;
      Xmo_1 = context__.vals_i("Xmo_1");
      current_statement__ = 39;
      stan::math::validate_non_negative_index("con_simo_1", "Jmo[1]",
        stan::model::rvalue(Jmo, "Jmo", stan::model::index_uni(1)));
      current_statement__ = 40;
      context__.validate_dims("data initialization", "con_simo_1", "double",
        std::vector<size_t>{static_cast<size_t>(
                              stan::model::rvalue(Jmo, "Jmo",
                                stan::model::index_uni(1)))});
      con_simo_1_data__ = Eigen::Matrix<double,-1,1>::Constant(stan::model::rvalue(
                                                                 Jmo, "Jmo",
                                                                 stan::model::index_uni(
                                                                   1)),
                            std::numeric_limits<double>::quiet_NaN());
      new (&con_simo_1)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(con_simo_1_data__.data(),
        stan::model::rvalue(Jmo, "Jmo", stan::model::index_uni(1)));
      {
        std::vector<local_scalar_t__> con_simo_1_flat__;
        current_statement__ = 40;
        con_simo_1_flat__ = context__.vals_r("con_simo_1");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <=
             stan::model::rvalue(Jmo, "Jmo", stan::model::index_uni(1)); ++sym1__) {
          stan::model::assign(con_simo_1, con_simo_1_flat__[(pos__ - 1)],
            "assigning variable con_simo_1", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 41;
      context__.validate_dims("data initialization", "prior_only", "int",
        std::vector<size_t>{});
      prior_only = std::numeric_limits<int>::min();
      current_statement__ = 41;
      prior_only = context__.vals_i("prior_only")[(1 - 1)];
      current_statement__ = 42;
      stan::math::validate_non_negative_index("Xc", "N", N);
      current_statement__ = 43;
      stan::math::validate_non_negative_index("Xc", "Kc", Kc);
      current_statement__ = 44;
      Xc_data__ = Eigen::Matrix<double,-1,-1>::Constant(N, Kc,
                    std::numeric_limits<double>::quiet_NaN());
      new (&Xc) Eigen::Map<Eigen::Matrix<double,-1,-1>>(Xc_data__.data(), N,
        Kc);
      current_statement__ = 45;
      stan::math::validate_non_negative_index("means_X", "Kc", Kc);
      current_statement__ = 46;
      means_X_data__ = Eigen::Matrix<double,-1,1>::Constant(Kc,
                         std::numeric_limits<double>::quiet_NaN());
      new (&means_X)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(means_X_data__.data(), Kc);
      current_statement__ = 50;
      for (int i = 1; i <= K; ++i) {
        current_statement__ = 47;
        stan::model::assign(means_X,
          stan::math::mean(
            stan::model::rvalue(X, "X", stan::model::index_omni(),
              stan::model::index_uni(i))), "assigning variable means_X",
          stan::model::index_uni(i));
        current_statement__ = 48;
        stan::model::assign(Xc,
          stan::math::subtract(
            stan::model::rvalue(X, "X", stan::model::index_omni(),
              stan::model::index_uni(i)),
            stan::model::rvalue(means_X, "means_X", stan::model::index_uni(i))),
          "assigning variable Xc", stan::model::index_omni(),
          stan::model::index_uni(i));
      }
      current_statement__ = 51;
      stan::math::validate_non_negative_index("b", "Kc", Kc);
      current_statement__ = 52;
      stan::math::validate_non_negative_index("Intercept", "nthres", nthres);
      current_statement__ = 53;
      simo_1_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 53;
      simo_1_1dim__ = stan::model::rvalue(Jmo, "Jmo",
                        stan::model::index_uni(1));
      current_statement__ = 53;
      stan::math::validate_positive_index("simo_1", "Jmo[1]", simo_1_1dim__);
      current_statement__ = 54;
      stan::math::validate_non_negative_index("bsp", "Ksp", Ksp);
      current_statement__ = 55;
      stan::math::validate_non_negative_index("b_Intercept", "nthres", nthres);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    num_params_r__ = Kc + nthres + (simo_1_1dim__ - 1) + Ksp;
  }
  inline std::string model_name() const final {
    return "model109c732fa5cb3_";
  }
  inline std::vector<std::string> model_compile_info() const noexcept {
    return std::vector<std::string>{"stanc_version = stanc3 v2.35.0",
             "stancflags = --"};
  }
  // Base log prob
  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,
            stan::require_not_st_var<VecR>* = 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__;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    int current_statement__ = 0;
    // suppress unused var warning
    (void) current_statement__;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    static constexpr const char* function__ =
      "model109c732fa5cb3__namespace::log_prob";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<local_scalar_t__,-1,1> b =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(Kc, DUMMY_VAR__);
      current_statement__ = 1;
      b = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(Kc);
      Eigen::Matrix<local_scalar_t__,-1,1> Intercept =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nthres, DUMMY_VAR__);
      current_statement__ = 2;
      Intercept = in__.template read_constrain_ordered<
                    Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
                    nthres);
      Eigen::Matrix<local_scalar_t__,-1,1> simo_1 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(simo_1_1dim__,
          DUMMY_VAR__);
      current_statement__ = 3;
      simo_1 = in__.template read_constrain_simplex<
                 Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
                 simo_1_1dim__);
      Eigen::Matrix<local_scalar_t__,-1,1> bsp =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(Ksp, DUMMY_VAR__);
      current_statement__ = 4;
      bsp = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(Ksp);
      local_scalar_t__ disc = DUMMY_VAR__;
      current_statement__ = 5;
      disc = 1;
      local_scalar_t__ lprior = DUMMY_VAR__;
      current_statement__ = 6;
      lprior = 0;
      current_statement__ = 8;
      lprior = (lprior + stan::math::normal_lpdf<false>(b, 0, 1));
      current_statement__ = 9;
      lprior = (lprior + stan::math::normal_lpdf<false>(Intercept, 0, 1.5));
      current_statement__ = 10;
      lprior = (lprior +
        stan::math::dirichlet_lpdf<false>(simo_1, con_simo_1));
      current_statement__ = 11;
      lprior = (lprior +
        stan::math::normal_lpdf<false>(
          stan::model::rvalue(bsp, "bsp", stan::model::index_uni(1)), 0,
          0.143));
      {
        current_statement__ = 22;
        if (stan::math::logical_negation(prior_only)) {
          current_statement__ = 12;
          stan::math::validate_non_negative_index("mu", "N", N);
          Eigen::Matrix<local_scalar_t__,-1,1> mu =
            Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N, DUMMY_VAR__);
          current_statement__ = 13;
          stan::model::assign(mu, stan::math::rep_vector(0.0, N),
            "assigning variable mu");
          current_statement__ = 14;
          stan::model::assign(mu,
            stan::math::add(stan::model::deep_copy(mu),
              stan::math::multiply(Xc, b)), "assigning variable mu");
          current_statement__ = 17;
          for (int n = 1; n <= N; ++n) {
            current_statement__ = 15;
            stan::model::assign(mu,
              (stan::model::rvalue(mu, "mu", stan::model::index_uni(n)) +
              (stan::model::rvalue(bsp, "bsp", stan::model::index_uni(1)) *
              mo(simo_1,
                stan::model::rvalue(Xmo_1, "Xmo_1", stan::model::index_uni(n)),
                pstream__))), "assigning variable mu",
              stan::model::index_uni(n));
          }
          current_statement__ = 20;
          for (int n = 1; n <= N; ++n) {
            current_statement__ = 18;
            lp_accum__.add(stan::math::ordered_logistic_lpmf<false>(
                             stan::model::rvalue(Y, "Y",
                               stan::model::index_uni(n)),
                             stan::model::rvalue(mu, "mu",
                               stan::model::index_uni(n)), Intercept));
          }
        }
        current_statement__ = 23;
        lp_accum__.add(lprior);
      }
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    lp_accum__.add(lp__);
    return lp_accum__.sum();
  }
  // Reverse mode autodiff log prob
  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,
            stan::require_st_var<VecR>* = 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__;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    int current_statement__ = 0;
    // suppress unused var warning
    (void) current_statement__;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    static constexpr const char* function__ =
      "model109c732fa5cb3__namespace::log_prob";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<local_scalar_t__,-1,1> b =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(Kc, DUMMY_VAR__);
      current_statement__ = 1;
      b = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(Kc);
      Eigen::Matrix<local_scalar_t__,-1,1> Intercept =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nthres, DUMMY_VAR__);
      current_statement__ = 2;
      Intercept = in__.template read_constrain_ordered<
                    Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
                    nthres);
      Eigen::Matrix<local_scalar_t__,-1,1> simo_1 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(simo_1_1dim__,
          DUMMY_VAR__);
      current_statement__ = 3;
      simo_1 = in__.template read_constrain_simplex<
                 Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
                 simo_1_1dim__);
      Eigen::Matrix<local_scalar_t__,-1,1> bsp =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(Ksp, DUMMY_VAR__);
      current_statement__ = 4;
      bsp = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(Ksp);
      local_scalar_t__ disc = DUMMY_VAR__;
      current_statement__ = 5;
      disc = 1;
      local_scalar_t__ lprior = DUMMY_VAR__;
      current_statement__ = 6;
      lprior = 0;
      current_statement__ = 8;
      lprior = (lprior + stan::math::normal_lpdf<false>(b, 0, 1));
      current_statement__ = 9;
      lprior = (lprior + stan::math::normal_lpdf<false>(Intercept, 0, 1.5));
      current_statement__ = 10;
      lprior = (lprior +
        stan::math::dirichlet_lpdf<false>(simo_1, con_simo_1));
      current_statement__ = 11;
      lprior = (lprior +
        stan::math::normal_lpdf<false>(
          stan::model::rvalue(bsp, "bsp", stan::model::index_uni(1)), 0,
          0.143));
      {
        current_statement__ = 22;
        if (stan::math::logical_negation(prior_only)) {
          current_statement__ = 12;
          stan::math::validate_non_negative_index("mu", "N", N);
          Eigen::Matrix<local_scalar_t__,-1,1> mu =
            Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N, DUMMY_VAR__);
          current_statement__ = 13;
          stan::model::assign(mu, stan::math::rep_vector(0.0, N),
            "assigning variable mu");
          current_statement__ = 14;
          stan::model::assign(mu,
            stan::math::add(stan::model::deep_copy(mu),
              stan::math::multiply(Xc, b)), "assigning variable mu");
          current_statement__ = 17;
          for (int n = 1; n <= N; ++n) {
            current_statement__ = 15;
            stan::model::assign(mu,
              (stan::model::rvalue(mu, "mu", stan::model::index_uni(n)) +
              (stan::model::rvalue(bsp, "bsp", stan::model::index_uni(1)) *
              mo(simo_1,
                stan::model::rvalue(Xmo_1, "Xmo_1", stan::model::index_uni(n)),
                pstream__))), "assigning variable mu",
              stan::model::index_uni(n));
          }
          current_statement__ = 20;
          for (int n = 1; n <= N; ++n) {
            current_statement__ = 18;
            lp_accum__.add(stan::math::ordered_logistic_lpmf<false>(
                             stan::model::rvalue(Y, "Y",
                               stan::model::index_uni(n)),
                             stan::model::rvalue(mu, "mu",
                               stan::model::index_uni(n)), Intercept));
          }
        }
        current_statement__ = 23;
        lp_accum__.add(lprior);
      }
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    lp_accum__.add(lp__);
    return lp_accum__.sum();
  }
  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_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;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    stan::io::serializer<local_scalar_t__> out__(vars__);
    static constexpr bool propto__ = true;
    // suppress unused var warning
    (void) propto__;
    double lp__ = 0.0;
    // suppress unused var warning
    (void) lp__;
    int current_statement__ = 0;
    // suppress unused var warning
    (void) current_statement__;
    stan::math::accumulator<double> lp_accum__;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    constexpr bool jacobian__ = false;
    // suppress unused var warning
    (void) jacobian__;
    static constexpr const char* function__ =
      "model109c732fa5cb3__namespace::write_array";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<double,-1,1> b =
        Eigen::Matrix<double,-1,1>::Constant(Kc,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 1;
      b = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(Kc);
      Eigen::Matrix<double,-1,1> Intercept =
        Eigen::Matrix<double,-1,1>::Constant(nthres,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 2;
      Intercept = in__.template read_constrain_ordered<
                    Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
                    nthres);
      Eigen::Matrix<double,-1,1> simo_1 =
        Eigen::Matrix<double,-1,1>::Constant(simo_1_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 3;
      simo_1 = in__.template read_constrain_simplex<
                 Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
                 simo_1_1dim__);
      Eigen::Matrix<double,-1,1> bsp =
        Eigen::Matrix<double,-1,1>::Constant(Ksp,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 4;
      bsp = in__.template read<Eigen::Matrix<local_scalar_t__,-1,1>>(Ksp);
      double disc = std::numeric_limits<double>::quiet_NaN();
      double lprior = std::numeric_limits<double>::quiet_NaN();
      out__.write(b);
      out__.write(Intercept);
      out__.write(simo_1);
      out__.write(bsp);
      if (stan::math::logical_negation(
            (stan::math::primitive_value(emit_transformed_parameters__) ||
            stan::math::primitive_value(emit_generated_quantities__)))) {
        return ;
      }
      current_statement__ = 5;
      disc = 1;
      current_statement__ = 6;
      lprior = 0;
      current_statement__ = 8;
      lprior = (lprior + stan::math::normal_lpdf<false>(b, 0, 1));
      current_statement__ = 9;
      lprior = (lprior + stan::math::normal_lpdf<false>(Intercept, 0, 1.5));
      current_statement__ = 10;
      lprior = (lprior +
        stan::math::dirichlet_lpdf<false>(simo_1, con_simo_1));
      current_statement__ = 11;
      lprior = (lprior +
        stan::math::normal_lpdf<false>(
          stan::model::rvalue(bsp, "bsp", stan::model::index_uni(1)), 0,
          0.143));
      if (emit_transformed_parameters__) {
        out__.write(disc);
        out__.write(lprior);
      }
      if (stan::math::logical_negation(emit_generated_quantities__)) {
        return ;
      }
      Eigen::Matrix<double,-1,1> b_Intercept =
        Eigen::Matrix<double,-1,1>::Constant(nthres,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 7;
      stan::model::assign(b_Intercept,
        stan::math::add(Intercept, stan::math::dot_product(means_X, b)),
        "assigning variable b_Intercept");
      out__.write(b_Intercept);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
  }
  template <typename VecVar, typename VecI,
            stan::require_vector_t<VecVar>* = nullptr,
            stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
  inline void
  unconstrain_array_impl(const VecVar& params_r__, const VecI& params_i__,
                         VecVar& vars__, std::ostream* pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    stan::io::serializer<local_scalar_t__> out__(vars__);
    int current_statement__ = 0;
    // suppress unused var warning
    (void) current_statement__;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    try {
      Eigen::Matrix<local_scalar_t__,-1,1> b =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(Kc, DUMMY_VAR__);
      current_statement__ = 1;
      stan::model::assign(b,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(Kc),
        "assigning variable b");
      out__.write(b);
      Eigen::Matrix<local_scalar_t__,-1,1> Intercept =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nthres, DUMMY_VAR__);
      current_statement__ = 2;
      stan::model::assign(Intercept,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(nthres),
        "assigning variable Intercept");
      out__.write_free_ordered(Intercept);
      Eigen::Matrix<local_scalar_t__,-1,1> simo_1 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(simo_1_1dim__,
          DUMMY_VAR__);
      current_statement__ = 3;
      stan::model::assign(simo_1,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(simo_1_1dim__),
        "assigning variable simo_1");
      out__.write_free_simplex(simo_1);
      Eigen::Matrix<local_scalar_t__,-1,1> bsp =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(Ksp, DUMMY_VAR__);
      current_statement__ = 4;
      stan::model::assign(bsp,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(Ksp),
        "assigning variable bsp");
      out__.write(bsp);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
  }
  template <typename VecVar, stan::require_vector_t<VecVar>* = nullptr>
  inline void
  transform_inits_impl(const stan::io::var_context& context__, VecVar&
                       vars__, std::ostream* pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    stan::io::serializer<local_scalar_t__> out__(vars__);
    int current_statement__ = 0;
    // suppress unused var warning
    (void) current_statement__;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    try {
      current_statement__ = 1;
      context__.validate_dims("parameter initialization", "b", "double",
        std::vector<size_t>{static_cast<size_t>(Kc)});
      current_statement__ = 2;
      context__.validate_dims("parameter initialization", "Intercept",
        "double", std::vector<size_t>{static_cast<size_t>(nthres)});
      current_statement__ = 3;
      context__.validate_dims("parameter initialization", "simo_1", "double",
        std::vector<size_t>{static_cast<size_t>(simo_1_1dim__)});
      current_statement__ = 4;
      context__.validate_dims("parameter initialization", "bsp", "double",
        std::vector<size_t>{static_cast<size_t>(Ksp)});
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      Eigen::Matrix<local_scalar_t__,-1,1> b =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(Kc, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> b_flat__;
        current_statement__ = 1;
        b_flat__ = context__.vals_r("b");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= Kc; ++sym1__) {
          stan::model::assign(b, b_flat__[(pos__ - 1)],
            "assigning variable b", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      out__.write(b);
      Eigen::Matrix<local_scalar_t__,-1,1> Intercept =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nthres, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> Intercept_flat__;
        current_statement__ = 2;
        Intercept_flat__ = context__.vals_r("Intercept");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= nthres; ++sym1__) {
          stan::model::assign(Intercept, Intercept_flat__[(pos__ - 1)],
            "assigning variable Intercept", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_ordered(Intercept);
      Eigen::Matrix<local_scalar_t__,-1,1> simo_1 =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(simo_1_1dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> simo_1_flat__;
        current_statement__ = 3;
        simo_1_flat__ = context__.vals_r("simo_1");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= simo_1_1dim__; ++sym1__) {
          stan::model::assign(simo_1, simo_1_flat__[(pos__ - 1)],
            "assigning variable simo_1", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_simplex(simo_1);
      Eigen::Matrix<local_scalar_t__,-1,1> bsp =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(Ksp, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> bsp_flat__;
        current_statement__ = 4;
        bsp_flat__ = context__.vals_r("bsp");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= Ksp; ++sym1__) {
          stan::model::assign(bsp, bsp_flat__[(pos__ - 1)],
            "assigning variable bsp", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      out__.write(bsp);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
  }
  inline void
  get_param_names(std::vector<std::string>& names__, const bool
                  emit_transformed_parameters__ = true, const bool
                  emit_generated_quantities__ = true) const {
    names__ = std::vector<std::string>{"b", "Intercept", "simo_1", "bsp"};
    if (emit_transformed_parameters__) {
      std::vector<std::string> temp{"disc", "lprior"};
      names__.reserve(names__.size() + temp.size());
      names__.insert(names__.end(), temp.begin(), temp.end());
    }
    if (emit_generated_quantities__) {
      std::vector<std::string> temp{"b_Intercept"};
      names__.reserve(names__.size() + temp.size());
      names__.insert(names__.end(), temp.begin(), temp.end());
    }
  }
  inline void
  get_dims(std::vector<std::vector<size_t>>& dimss__, const bool
           emit_transformed_parameters__ = true, const bool
           emit_generated_quantities__ = true) const {
    dimss__ = std::vector<std::vector<size_t>>{std::vector<size_t>{static_cast<
                                                                    size_t>(
                                                                    Kc)},
                std::vector<size_t>{static_cast<size_t>(nthres)},
                std::vector<size_t>{static_cast<size_t>(simo_1_1dim__)},
                std::vector<size_t>{static_cast<size_t>(Ksp)}};
    if (emit_transformed_parameters__) {
      std::vector<std::vector<size_t>>
        temp{std::vector<size_t>{}, std::vector<size_t>{}};
      dimss__.reserve(dimss__.size() + temp.size());
      dimss__.insert(dimss__.end(), temp.begin(), temp.end());
    }
    if (emit_generated_quantities__) {
      std::vector<std::vector<size_t>>
        temp{std::vector<size_t>{static_cast<size_t>(nthres)}};
      dimss__.reserve(dimss__.size() + temp.size());
      dimss__.insert(dimss__.end(), temp.begin(), temp.end());
    }
  }
  inline void
  constrained_param_names(std::vector<std::string>& param_names__, bool
                          emit_transformed_parameters__ = true, bool
                          emit_generated_quantities__ = true) const final {
    for (int sym1__ = 1; sym1__ <= Kc; ++sym1__) {
      param_names__.emplace_back(std::string() + "b" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= nthres; ++sym1__) {
      param_names__.emplace_back(std::string() + "Intercept" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= simo_1_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "simo_1" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= Ksp; ++sym1__) {
      param_names__.emplace_back(std::string() + "bsp" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {
      param_names__.emplace_back(std::string() + "disc");
      param_names__.emplace_back(std::string() + "lprior");
    }
    if (emit_generated_quantities__) {
      for (int sym1__ = 1; sym1__ <= nthres; ++sym1__) {
        param_names__.emplace_back(std::string() + "b_Intercept" + '.' +
          std::to_string(sym1__));
      }
    }
  }
  inline void
  unconstrained_param_names(std::vector<std::string>& param_names__, bool
                            emit_transformed_parameters__ = true, bool
                            emit_generated_quantities__ = true) const final {
    for (int sym1__ = 1; sym1__ <= Kc; ++sym1__) {
      param_names__.emplace_back(std::string() + "b" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= nthres; ++sym1__) {
      param_names__.emplace_back(std::string() + "Intercept" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= (simo_1_1dim__ - 1); ++sym1__) {
      param_names__.emplace_back(std::string() + "simo_1" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= Ksp; ++sym1__) {
      param_names__.emplace_back(std::string() + "bsp" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {
      param_names__.emplace_back(std::string() + "disc");
      param_names__.emplace_back(std::string() + "lprior");
    }
    if (emit_generated_quantities__) {
      for (int sym1__ = 1; sym1__ <= nthres; ++sym1__) {
        param_names__.emplace_back(std::string() + "b_Intercept" + '.' +
          std::to_string(sym1__));
      }
    }
  }
  inline std::string get_constrained_sizedtypes() const {
    return std::string("[{\"name\":\"b\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Kc) + "},\"block\":\"parameters\"},{\"name\":\"Intercept\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nthres) + "},\"block\":\"parameters\"},{\"name\":\"simo_1\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(simo_1_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"bsp\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Ksp) + "},\"block\":\"parameters\"},{\"name\":\"disc\",\"type\":{\"name\":\"real\"},\"block\":\"transformed_parameters\"},{\"name\":\"lprior\",\"type\":{\"name\":\"real\"},\"block\":\"transformed_parameters\"},{\"name\":\"b_Intercept\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nthres) + "},\"block\":\"generated_quantities\"}]");
  }
  inline std::string get_unconstrained_sizedtypes() const {
    return std::string("[{\"name\":\"b\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Kc) + "},\"block\":\"parameters\"},{\"name\":\"Intercept\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nthres) + "},\"block\":\"parameters\"},{\"name\":\"simo_1\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string((simo_1_1dim__ -1)) + "},\"block\":\"parameters\"},{\"name\":\"bsp\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Ksp) + "},\"block\":\"parameters\"},{\"name\":\"disc\",\"type\":{\"name\":\"real\"},\"block\":\"transformed_parameters\"},{\"name\":\"lprior\",\"type\":{\"name\":\"real\"},\"block\":\"transformed_parameters\"},{\"name\":\"b_Intercept\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nthres) + "},\"block\":\"generated_quantities\"}]");
  }
  // Begin method overload boilerplate
  template <typename RNG> inline void
  write_array(RNG& base_rng, Eigen::Matrix<double,-1,1>& params_r,
              Eigen::Matrix<double,-1,1>& vars, const bool
              emit_transformed_parameters = true, const bool
              emit_generated_quantities = true, std::ostream*
              pstream = nullptr) const {
    const size_t num_params__ = (((Kc + nthres) + simo_1_1dim__) + Ksp);
    const size_t num_transformed = emit_transformed_parameters * ((1 + 1));
    const size_t num_gen_quantities = emit_generated_quantities * (nthres);
    const size_t num_to_write = num_params__ + num_transformed +
      num_gen_quantities;
    std::vector<int> params_i;
    vars = Eigen::Matrix<double,-1,1>::Constant(num_to_write,
             std::numeric_limits<double>::quiet_NaN());
    write_array_impl(base_rng, params_r, params_i, vars,
      emit_transformed_parameters, emit_generated_quantities, pstream);
  }
  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 {
    const size_t num_params__ = (((Kc + nthres) + simo_1_1dim__) + Ksp);
    const size_t num_transformed = emit_transformed_parameters * ((1 + 1));
    const size_t num_gen_quantities = emit_generated_quantities * (nthres);
    const size_t num_to_write = num_params__ + num_transformed +
      num_gen_quantities;
    vars = std::vector<double>(num_to_write,
             std::numeric_limits<double>::quiet_NaN());
    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_,-1,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,-1,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(context, params_i, params_r_vec, pstream);
    params_r = Eigen::Map<Eigen::Matrix<double,-1,1>>(params_r_vec.data(),
                 params_r_vec.size());
  }
  inline void
  transform_inits(const stan::io::var_context& context, std::vector<int>&
                  params_i, std::vector<double>& vars, std::ostream*
                  pstream__ = nullptr) const {
    vars.resize(num_params_r__);
    transform_inits_impl(context, vars, pstream__);
  }
  inline void
  unconstrain_array(const std::vector<double>& params_constrained,
                    std::vector<double>& params_unconstrained, std::ostream*
                    pstream = nullptr) const {
    const std::vector<int> params_i;
    params_unconstrained = std::vector<double>(num_params_r__,
                             std::numeric_limits<double>::quiet_NaN());
    unconstrain_array_impl(params_constrained, params_i,
      params_unconstrained, pstream);
  }
  inline void
  unconstrain_array(const Eigen::Matrix<double,-1,1>& params_constrained,
                    Eigen::Matrix<double,-1,1>& params_unconstrained,
                    std::ostream* pstream = nullptr) const {
    const std::vector<int> params_i;
    params_unconstrained = Eigen::Matrix<double,-1,1>::Constant(num_params_r__,
                             std::numeric_limits<double>::quiet_NaN());
    unconstrain_array_impl(params_constrained, params_i,
      params_unconstrained, pstream);
  }
};
}
using stan_model = model109c732fa5cb3__namespace::model109c732fa5cb3_;
#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 model109c732fa5cb3__namespace::profiles__;
}
#endif
#endif