// Generated by rstantools.  Do not edit by hand.

/*
    hbamr is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    hbamr is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with hbamr.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MODELS_HPP
#define MODELS_HPP
#define STAN__SERVICES__COMMAND_HPP
#ifndef USE_STANC3
#define USE_STANC3
#endif
#include <rstan/rstaninc.hpp>
// Code generated by stanc v2.38.0-92-g9119e6c
#include <stan/model/model_header.hpp>
namespace model_omni_namespace {
using stan::model::model_base_crtp;
using namespace stan::math;
stan::math::profile_map profiles__;
static constexpr std::array<const char*, 291> locations_array__ =
  {" (found before start of program)",
  " (in 'omni', line 50, column 2 to column 32)",
  " (in 'omni', line 51, column 2 to column 31)",
  " (in 'omni', line 52, column 2 to column 37)",
  " (in 'omni', line 53, column 2 to column 26)",
  " (in 'omni', line 54, column 2 to column 43)",
  " (in 'omni', line 55, column 2 to column 42)",
  " (in 'omni', line 56, column 2 to column 72)",
  " (in 'omni', line 57, column 2 to column 82)",
  " (in 'omni', line 58, column 2 to column 75)",
  " (in 'omni', line 59, column 2 to column 57)",
  " (in 'omni', line 60, column 2 to column 42)",
  " (in 'omni', line 61, column 2 to column 32)",
  " (in 'omni', line 62, column 2 to column 39)",
  " (in 'omni', line 63, column 2 to column 65)",
  " (in 'omni', line 64, column 2 to column 59)",
  " (in 'omni', line 65, column 2 to column 35)",
  " (in 'omni', line 66, column 2 to column 35)",
  " (in 'omni', line 67, column 2 to column 54)",
  " (in 'omni', line 70, column 2 to column 37)",
  " (in 'omni', line 71, column 2 to column 22)",
  " (in 'omni', line 72, column 2 to column 29)",
  " (in 'omni', line 73, column 2 to column 28)",
  " (in 'omni', line 74, column 2 to column 24)",
  " (in 'omni', line 75, column 2 to column 57)",
  " (in 'omni', line 76, column 2 to column 38)",
  " (in 'omni', line 77, column 2 to column 37)",
  " (in 'omni', line 78, column 2 to column 39)",
  " (in 'omni', line 79, column 2 to column 45)",
  " (in 'omni', line 80, column 2 to column 55)",
  " (in 'omni', line 81, column 2 to column 44)",
  " (in 'omni', line 82, column 2 to column 22)",
  " (in 'omni', line 83, column 2 to column 34)",
  " (in 'omni', line 228, column 2 to column 37)",
  " (in 'omni', line 229, column 2 to column 34)",
  " (in 'omni', line 230, column 2 to column 18)",
  " (in 'omni', line 231, column 2 to column 17)",
  " (in 'omni', line 232, column 2 to column 16)",
  " (in 'omni', line 233, column 2 to column 51)",
  " (in 'omni', line 98, column 4 to column 20)",
  " (in 'omni', line 100, column 6 to column 41)",
  " (in 'omni', line 101, column 6 to column 39)",
  " (in 'omni', line 99, column 18 to line 102, column 5)",
  " (in 'omni', line 99, column 4 to line 102, column 5)",
  " (in 'omni', line 104, column 6 to column 23)",
  " (in 'omni', line 105, column 6 to column 29)",
  " (in 'omni', line 103, column 18 to line 106, column 5)",
  " (in 'omni', line 103, column 4 to line 106, column 5)",
  " (in 'omni', line 108, column 6 to column 25)",
  " (in 'omni', line 107, column 19 to line 109, column 5)",
  " (in 'omni', line 107, column 4 to line 109, column 5)",
  " (in 'omni', line 97, column 9 to line 110, column 3)",
  " (in 'omni', line 85, column 4 to column 21)",
  " (in 'omni', line 87, column 6 to column 36)",
  " (in 'omni', line 88, column 6 to column 34)",
  " (in 'omni', line 86, column 18 to line 89, column 5)",
  " (in 'omni', line 86, column 4 to line 89, column 5)",
  " (in 'omni', line 91, column 6 to column 18)",
  " (in 'omni', line 92, column 6 to column 29)",
  " (in 'omni', line 90, column 18 to line 93, column 5)",
  " (in 'omni', line 90, column 4 to line 93, column 5)",
  " (in 'omni', line 95, column 6 to column 20)",
  " (in 'omni', line 94, column 19 to line 96, column 5)",
  " (in 'omni', line 94, column 4 to line 96, column 5)",
  " (in 'omni', line 84, column 18 to line 97, column 3)",
  " (in 'omni', line 84, column 2 to line 110, column 3)",
  " (in 'omni', line 112, column 4 to column 87)",
  " (in 'omni', line 113, column 4 to column 84)",
  " (in 'omni', line 111, column 18 to line 114, column 3)",
  " (in 'omni', line 111, column 2 to line 114, column 3)",
  " (in 'omni', line 115, column 2 to column 20)",
  " (in 'omni', line 126, column 4 to column 27)",
  " (in 'omni', line 127, column 4 to column 27)",
  " (in 'omni', line 132, column 6 to column 67)",
  " (in 'omni', line 133, column 6 to column 68)",
  " (in 'omni', line 131, column 11 to line 134, column 5)",
  " (in 'omni', line 129, column 6 to column 52)",
  " (in 'omni', line 130, column 6 to column 54)",
  " (in 'omni', line 128, column 20 to line 131, column 5)",
  " (in 'omni', line 128, column 4 to line 134, column 5)",
  " (in 'omni', line 136, column 6 to column 50)",
  " (in 'omni', line 137, column 6 to column 55)",
  " (in 'omni', line 141, column 8 to column 69)",
  " (in 'omni', line 140, column 13 to line 142, column 7)",
  " (in 'omni', line 139, column 8 to column 54)",
  " (in 'omni', line 138, column 22 to line 140, column 7)",
  " (in 'omni', line 138, column 6 to line 142, column 7)",
  " (in 'omni', line 135, column 19 to line 143, column 5)",
  " (in 'omni', line 135, column 4 to line 143, column 5)",
  " (in 'omni', line 176, column 10 to line 177, column 43)",
  " (in 'omni', line 175, column 27 to line 178, column 9)",
  " (in 'omni', line 175, column 8 to line 178, column 9)",
  " (in 'omni', line 174, column 13 to line 179, column 7)",
  " (in 'omni', line 168, column 10 to line 172, column 47)",
  " (in 'omni', line 167, column 27 to line 173, column 9)",
  " (in 'omni', line 167, column 8 to line 173, column 9)",
  " (in 'omni', line 166, column 21 to line 174, column 7)",
  " (in 'omni', line 166, column 6 to line 179, column 7)",
  " (in 'omni', line 165, column 11 to line 180, column 5)",
  " (in 'omni', line 161, column 8 to line 163, column 87)",
  " (in 'omni', line 160, column 25 to line 164, column 7)",
  " (in 'omni', line 160, column 6 to line 164, column 7)",
  " (in 'omni', line 159, column 25 to line 165, column 5)",
  " (in 'omni', line 159, column 11 to line 180, column 5)",
  " (in 'omni', line 146, column 8 to column 22)",
  " (in 'omni', line 147, column 8 to column 67)",
  " (in 'omni', line 148, column 8 to column 67)",
  " (in 'omni', line 149, column 8 to line 150, column 88)",
  " (in 'omni', line 151, column 8 to line 152, column 88)",
  " (in 'omni', line 153, column 8 to line 154, column 88)",
  " (in 'omni', line 155, column 8 to line 156, column 88)",
  " (in 'omni', line 157, column 8 to column 44)",
  " (in 'omni', line 145, column 25 to line 158, column 7)",
  " (in 'omni', line 145, column 6 to line 158, column 7)",
  " (in 'omni', line 144, column 18 to line 159, column 5)",
  " (in 'omni', line 144, column 4 to line 180, column 5)",
  " (in 'omni', line 125, column 9 to line 181, column 3)",
  " (in 'omni', line 117, column 4 to column 28)",
  " (in 'omni', line 118, column 4 to column 28)",
  " (in 'omni', line 119, column 4 to column 33)",
  " (in 'omni', line 120, column 4 to column 31)",
  " (in 'omni', line 122, column 6 to line 123, column 39)",
  " (in 'omni', line 121, column 23 to line 124, column 5)",
  " (in 'omni', line 121, column 4 to line 124, column 5)",
  " (in 'omni', line 116, column 16 to line 125, column 3)",
  " (in 'omni', line 116, column 2 to line 181, column 3)",
  " (in 'omni', line 242, column 4 to column 24)",
  " (in 'omni', line 243, column 4 to column 22)",
  " (in 'omni', line 241, column 9 to line 244, column 3)",
  " (in 'omni', line 238, column 6 to column 39)",
  " (in 'omni', line 236, column 6 to column 47)",
  " (in 'omni', line 235, column 4 to line 238, column 39)",
  " (in 'omni', line 239, column 4 to column 66)",
  " (in 'omni', line 240, column 4 to column 63)",
  " (in 'omni', line 234, column 17 to line 241, column 3)",
  " (in 'omni', line 234, column 2 to line 244, column 3)",
  " (in 'omni', line 262, column 6 to column 43)",
  " (in 'omni', line 261, column 11 to line 263, column 5)",
  " (in 'omni', line 256, column 6 to column 90)",
  " (in 'omni', line 259, column 10 to column 81)",
  " (in 'omni', line 258, column 8 to line 259, column 81)",
  " (in 'omni', line 257, column 20 to line 260, column 7)",
  " (in 'omni', line 257, column 6 to line 260, column 7)",
  " (in 'omni', line 255, column 19 to line 261, column 5)",
  " (in 'omni', line 255, column 4 to line 263, column 5)",
  " (in 'omni', line 254, column 9 to line 264, column 3)",
  " (in 'omni', line 252, column 6 to column 43)",
  " (in 'omni', line 251, column 9 to line 253, column 5)",
  " (in 'omni', line 247, column 6 to column 91)",
  " (in 'omni', line 249, column 8 to column 105)",
  " (in 'omni', line 248, column 6 to line 249, column 105)",
  " (in 'omni', line 246, column 19 to line 250, column 5)",
  " (in 'omni', line 246, column 4 to line 253, column 5)",
  " (in 'omni', line 245, column 16 to line 254, column 3)",
  " (in 'omni', line 245, column 2 to line 264, column 3)",
  " (in 'omni', line 184, column 2 to column 33)",
  " (in 'omni', line 189, column 4 to column 34)",
  " (in 'omni', line 190, column 4 to column 34)",
  " (in 'omni', line 191, column 4 to column 55)",
  " (in 'omni', line 192, column 4 to column 33)",
  " (in 'omni', line 193, column 4 to column 34)",
  " (in 'omni', line 188, column 9 to line 194, column 3)",
  " (in 'omni', line 186, column 4 to column 40)",
  " (in 'omni', line 187, column 4 to column 39)",
  " (in 'omni', line 185, column 16 to line 188, column 3)",
  " (in 'omni', line 185, column 2 to line 194, column 3)",
  " (in 'omni', line 199, column 4 to column 48)",
  " (in 'omni', line 200, column 4 to column 47)",
  " (in 'omni', line 198, column 9 to line 201, column 3)",
  " (in 'omni', line 196, column 4 to column 48)",
  " (in 'omni', line 197, column 4 to column 47)",
  " (in 'omni', line 195, column 18 to line 198, column 3)",
  " (in 'omni', line 195, column 2 to line 201, column 3)",
  " (in 'omni', line 203, column 4 to column 34)",
  " (in 'omni', line 204, column 4 to column 33)",
  " (in 'omni', line 205, column 4 to column 30)",
  " (in 'omni', line 206, column 4 to column 33)",
  " (in 'omni', line 202, column 17 to line 207, column 3)",
  " (in 'omni', line 202, column 2 to line 207, column 3)",
  " (in 'omni', line 209, column 4 to column 37)",
  " (in 'omni', line 210, column 4 to column 27)",
  " (in 'omni', line 211, column 4 to column 27)",
  " (in 'omni', line 212, column 4 to column 26)",
  " (in 'omni', line 208, column 16 to line 213, column 3)",
  " (in 'omni', line 208, column 2 to line 213, column 3)",
  " (in 'omni', line 219, column 4 to column 39)",
  " (in 'omni', line 218, column 9 to line 220, column 3)",
  " (in 'omni', line 215, column 4 to column 53)",
  " (in 'omni', line 216, column 4 to column 28)",
  " (in 'omni', line 217, column 4 to column 39)",
  " (in 'omni', line 214, column 16 to line 218, column 3)",
  " (in 'omni', line 214, column 2 to line 220, column 3)",
  " (in 'omni', line 221, column 2 to column 37)",
  " (in 'omni', line 225, column 4 to column 42)",
  " (in 'omni', line 223, column 4 to column 27)",
  " (in 'omni', line 222, column 2 to line 225, column 42)",
  " (in 'omni', line 2, column 2 to column 19)",
  " (in 'omni', line 3, column 2 to column 19)",
  " (in 'omni', line 4, column 2 to column 19)",
  " (in 'omni', line 5, column 2 to column 23)",
  " (in 'omni', line 6, column 8 to column 13)",
  " (in 'omni', line 6, column 2 to column 33)",
  " (in 'omni', line 7, column 8 to column 13)",
  " (in 'omni', line 7, column 2 to column 33)",
  " (in 'omni', line 8, column 8 to column 9)",
  " (in 'omni', line 8, column 2 to column 29)",
  " (in 'omni', line 9, column 2 to column 20)",
  " (in 'omni', line 10, column 2 to column 30)",
  " (in 'omni', line 11, column 2 to column 30)",
  " (in 'omni', line 12, column 2 to column 19)",
  " (in 'omni', line 13, column 8 to column 13)",
  " (in 'omni', line 13, column 2 to column 45)",
  " (in 'omni', line 14, column 8 to column 13)",
  " (in 'omni', line 14, column 2 to column 44)",
  " (in 'omni', line 15, column 8 to column 9)",
  " (in 'omni', line 15, column 2 to column 41)",
  " (in 'omni', line 16, column 8 to column 9)",
  " (in 'omni', line 16, column 2 to column 18)",
  " (in 'omni', line 17, column 9 to column 10)",
  " (in 'omni', line 17, column 2 to column 22)",
  " (in 'omni', line 18, column 2 to column 33)",
  " (in 'omni', line 19, column 2 to column 32)",
  " (in 'omni', line 20, column 2 to column 36)",
  " (in 'omni', line 21, column 2 to column 35)",
  " (in 'omni', line 22, column 2 to column 33)",
  " (in 'omni', line 23, column 2 to column 32)",
  " (in 'omni', line 24, column 2 to column 32)",
  " (in 'omni', line 25, column 2 to column 34)",
  " (in 'omni', line 26, column 2 to column 32)",
  " (in 'omni', line 27, column 2 to column 34)",
  " (in 'omni', line 28, column 2 to column 31)",
  " (in 'omni', line 29, column 2 to column 33)",
  " (in 'omni', line 30, column 31 to column 36)",
  " (in 'omni', line 30, column 2 to column 46)",
  " (in 'omni', line 33, column 2 to column 20)",
  " (in 'omni', line 34, column 2 to column 27)",
  " (in 'omni', line 35, column 2 to column 39)",
  " (in 'omni', line 36, column 2 to column 21)",
  " (in 'omni', line 37, column 2 to column 63)",
  " (in 'omni', line 38, column 2 to column 55)",
  " (in 'omni', line 39, column 31 to column 36)",
  " (in 'omni', line 39, column 2 to column 64)",
  " (in 'omni', line 40, column 2 to column 35)",
  " (in 'omni', line 41, column 2 to column 90)",
  " (in 'omni', line 42, column 2 to column 36)",
  " (in 'omni', line 43, column 11 to column 16)",
  " (in 'omni', line 43, column 2 to column 48)",
  " (in 'omni', line 45, column 4 to column 45)",
  " (in 'omni', line 46, column 4 to column 45)",
  " (in 'omni', line 44, column 21 to line 47, column 3)",
  " (in 'omni', line 44, column 2 to line 47, column 3)",
  " (in 'omni', line 50, column 9 to column 10)",
  " (in 'omni', line 50, column 12 to column 20)",
  " (in 'omni', line 51, column 9 to column 10)",
  " (in 'omni', line 51, column 12 to column 20)",
  " (in 'omni', line 52, column 10 to column 26)",
  " (in 'omni', line 53, column 8 to column 9)",
  " (in 'omni', line 54, column 10 to column 28)",
  " (in 'omni', line 55, column 10 to column 28)",
  " (in 'omni', line 56, column 8 to column 38)",
  " (in 'omni', line 57, column 8 to column 38)",
  " (in 'omni', line 58, column 8 to column 38)",
  " (in 'omni', line 59, column 8 to column 17)",
  " (in 'omni', line 60, column 20 to column 36)",
  " (in 'omni', line 61, column 10 to column 26)",
  " (in 'omni', line 62, column 9 to column 26)",
  " (in 'omni', line 63, column 8 to column 39)",
  " (in 'omni', line 64, column 8 to column 24)",
  " (in 'omni', line 65, column 8 to column 11)",
  " (in 'omni', line 66, column 8 to column 11)",
  " (in 'omni', line 67, column 31 to column 47)",
  " (in 'omni', line 70, column 9 to column 25)",
  " (in 'omni', line 71, column 8 to column 9)",
  " (in 'omni', line 72, column 9 to column 10)",
  " (in 'omni', line 72, column 12 to column 20)",
  " (in 'omni', line 73, column 9 to column 10)",
  " (in 'omni', line 73, column 12 to column 20)",
  " (in 'omni', line 74, column 9 to column 14)",
  " (in 'omni', line 75, column 31 to column 48)",
  " (in 'omni', line 76, column 9 to column 27)",
  " (in 'omni', line 77, column 9 to column 27)",
  " (in 'omni', line 78, column 8 to column 11)",
  " (in 'omni', line 79, column 8 to column 15)",
  " (in 'omni', line 80, column 8 to column 15)",
  " (in 'omni', line 81, column 8 to column 11)",
  " (in 'omni', line 83, column 8 to column 12)",
  " (in 'omni', line 229, column 9 to column 26)",
  " (in 'omni', line 230, column 9 to column 10)",
  " (in 'omni', line 231, column 9 to column 10)",
  " (in 'omni', line 232, column 9 to column 10)",
  " (in 'omni', line 233, column 9 to column 42)"};
#include <stan_meta_header.hpp>
class model_omni final : public model_base_crtp<model_omni> {
private:
  int N;
  int J;
  int G;
  int N_obs;
  std::vector<int> ii;
  std::vector<int> jj;
  std::vector<int> gg;
  double B;
  int L;
  int R;
  int K;
  std::vector<double> Y;
  std::vector<double> U;
  std::vector<double> V;
  std::vector<int> Vi;
  Eigen::Matrix<double,-1,1> mean_spos_data__;
  double sigma_mu_alpha;
  double sigma_mu_beta;
  double sigma_alpha_fixed;
  double sigma_beta_fixed;
  int flip;
  int het;
  int rat;
  int group;
  int bam;
  int fixed;
  int CV;
  int MCMC;
  Eigen::Matrix<double,-1,1> holdout_data__;
  double nu_fixed;
  double tau_fixed;
  double eta_scale_fixed;
  double psi_fixed;
  double sigma_alpha_prior_rate;
  double tau_prior_rate;
  Eigen::Matrix<double,-1,1> not_holdout_data__;
  double mean_mu_simplexes;
  double sd_mu_simplexes;
  double tau_multip;
  std::vector<std::vector<double>> p;
  int alpha_raw_2dim__;
  int beta_raw_2dim__;
  int theta_lr_1dim__;
  int mu_alpha_raw_1dim__;
  int mu_beta_raw_1dim__;
  int sigma_alpha_par_1dim__;
  int sigma_beta_par_1dim__;
  int nu_par_1dim__;
  int tau_par_1dim__;
  int eta_1dim__;
  int rho_1dim__;
  int lambda_raw_1dim__;
  int psi_par_1dim__;
  int gamma_1dim__;
  int zeta_1dim__;
  int log_probs_1dim__;
  int alpha0_2dim__;
  int beta0_2dim__;
  int lambda_1dim__;
  int mu_alpha_1dim__;
  int mu_beta_1dim__;
  int sigma_alpha_1dim__;
  int sigma_beta_1dim__;
  int kappa_1dim__;
  int Y_pred_1dim__;
  Eigen::Map<Eigen::Matrix<double,-1,1>> mean_spos{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> holdout{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> not_holdout{nullptr, 0};
public:
  ~model_omni() {}
  model_omni(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__ =
      "model_omni_namespace::model_omni";
    // 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__ = 196;
      context__.validate_dims("data initialization", "N", "int",
        std::vector<size_t>{});
      N = std::numeric_limits<int>::min();
      current_statement__ = 196;
      N = context__.vals_i("N")[(1 - 1)];
      current_statement__ = 196;
      stan::math::check_greater_or_equal(function__, "N", N, 1);
      current_statement__ = 197;
      context__.validate_dims("data initialization", "J", "int",
        std::vector<size_t>{});
      J = std::numeric_limits<int>::min();
      current_statement__ = 197;
      J = context__.vals_i("J")[(1 - 1)];
      current_statement__ = 197;
      stan::math::check_greater_or_equal(function__, "J", J, 1);
      current_statement__ = 198;
      context__.validate_dims("data initialization", "G", "int",
        std::vector<size_t>{});
      G = std::numeric_limits<int>::min();
      current_statement__ = 198;
      G = context__.vals_i("G")[(1 - 1)];
      current_statement__ = 198;
      stan::math::check_greater_or_equal(function__, "G", G, 0);
      current_statement__ = 199;
      context__.validate_dims("data initialization", "N_obs", "int",
        std::vector<size_t>{});
      N_obs = std::numeric_limits<int>::min();
      current_statement__ = 199;
      N_obs = context__.vals_i("N_obs")[(1 - 1)];
      current_statement__ = 199;
      stan::math::check_greater_or_equal(function__, "N_obs", N_obs, 1);
      current_statement__ = 200;
      stan::math::validate_non_negative_index("ii", "N_obs", N_obs);
      current_statement__ = 201;
      context__.validate_dims("data initialization", "ii", "int",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      ii = std::vector<int>(N_obs, std::numeric_limits<int>::min());
      current_statement__ = 201;
      ii = context__.vals_i("ii");
      current_statement__ = 201;
      stan::math::check_greater_or_equal(function__, "ii", ii, 1);
      current_statement__ = 202;
      stan::math::validate_non_negative_index("jj", "N_obs", N_obs);
      current_statement__ = 203;
      context__.validate_dims("data initialization", "jj", "int",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      jj = std::vector<int>(N_obs, std::numeric_limits<int>::min());
      current_statement__ = 203;
      jj = context__.vals_i("jj");
      current_statement__ = 203;
      stan::math::check_greater_or_equal(function__, "jj", jj, 1);
      current_statement__ = 204;
      stan::math::validate_non_negative_index("gg", "N", N);
      current_statement__ = 205;
      context__.validate_dims("data initialization", "gg", "int",
        std::vector<size_t>{static_cast<size_t>(N)});
      gg = std::vector<int>(N, std::numeric_limits<int>::min());
      current_statement__ = 205;
      gg = context__.vals_i("gg");
      current_statement__ = 205;
      stan::math::check_greater_or_equal(function__, "gg", gg, 1);
      current_statement__ = 206;
      context__.validate_dims("data initialization", "B", "double",
        std::vector<size_t>{});
      B = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 206;
      B = context__.vals_r("B")[(1 - 1)];
      current_statement__ = 206;
      stan::math::check_greater_or_equal(function__, "B", B, 0);
      current_statement__ = 207;
      context__.validate_dims("data initialization", "L", "int",
        std::vector<size_t>{});
      L = std::numeric_limits<int>::min();
      current_statement__ = 207;
      L = context__.vals_i("L")[(1 - 1)];
      current_statement__ = 207;
      stan::math::check_greater_or_equal(function__, "L", L, 1);
      current_statement__ = 207;
      stan::math::check_less_or_equal(function__, "L", L, J);
      current_statement__ = 208;
      context__.validate_dims("data initialization", "R", "int",
        std::vector<size_t>{});
      R = std::numeric_limits<int>::min();
      current_statement__ = 208;
      R = context__.vals_i("R")[(1 - 1)];
      current_statement__ = 208;
      stan::math::check_greater_or_equal(function__, "R", R, 1);
      current_statement__ = 208;
      stan::math::check_less_or_equal(function__, "R", R, J);
      current_statement__ = 209;
      context__.validate_dims("data initialization", "K", "int",
        std::vector<size_t>{});
      K = std::numeric_limits<int>::min();
      current_statement__ = 209;
      K = context__.vals_i("K")[(1 - 1)];
      current_statement__ = 209;
      stan::math::check_greater_or_equal(function__, "K", K, 1);
      current_statement__ = 210;
      stan::math::validate_non_negative_index("Y", "N_obs", N_obs);
      current_statement__ = 211;
      context__.validate_dims("data initialization", "Y", "double",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      Y = std::vector<double>(N_obs,
            std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 211;
      Y = context__.vals_r("Y");
      current_statement__ = 211;
      stan::math::check_greater_or_equal(function__, "Y", Y, -(B));
      current_statement__ = 211;
      stan::math::check_less_or_equal(function__, "Y", Y, B);
      current_statement__ = 212;
      stan::math::validate_non_negative_index("U", "N_obs", N_obs);
      current_statement__ = 213;
      context__.validate_dims("data initialization", "U", "double",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      U = std::vector<double>(N_obs,
            std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 213;
      U = context__.vals_r("U");
      current_statement__ = 213;
      stan::math::check_greater_or_equal(function__, "U", U, 0);
      current_statement__ = 213;
      stan::math::check_less_or_equal(function__, "U", U, 1);
      current_statement__ = 214;
      stan::math::validate_non_negative_index("V", "N", N);
      current_statement__ = 215;
      context__.validate_dims("data initialization", "V", "double",
        std::vector<size_t>{static_cast<size_t>(N)});
      V = std::vector<double>(N, std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 215;
      V = context__.vals_r("V");
      current_statement__ = 215;
      stan::math::check_greater_or_equal(function__, "V", V, -(B));
      current_statement__ = 215;
      stan::math::check_less_or_equal(function__, "V", V, B);
      current_statement__ = 216;
      stan::math::validate_non_negative_index("Vi", "N", N);
      current_statement__ = 217;
      context__.validate_dims("data initialization", "Vi", "int",
        std::vector<size_t>{static_cast<size_t>(N)});
      Vi = std::vector<int>(N, std::numeric_limits<int>::min());
      current_statement__ = 217;
      Vi = context__.vals_i("Vi");
      current_statement__ = 218;
      stan::math::validate_non_negative_index("mean_spos", "J", J);
      current_statement__ = 219;
      context__.validate_dims("data initialization", "mean_spos", "double",
        std::vector<size_t>{static_cast<size_t>(J)});
      mean_spos_data__ = Eigen::Matrix<double,-1,1>::Constant(J,
                           std::numeric_limits<double>::quiet_NaN());
      new (&mean_spos)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(mean_spos_data__.data(), J);
      {
        std::vector<local_scalar_t__> mean_spos_flat__;
        current_statement__ = 219;
        mean_spos_flat__ = context__.vals_r("mean_spos");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= J; ++sym1__) {
          stan::model::assign(mean_spos, mean_spos_flat__[(pos__ - 1)],
            "assigning variable mean_spos", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 220;
      context__.validate_dims("data initialization", "sigma_mu_alpha",
        "double", std::vector<size_t>{});
      sigma_mu_alpha = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 220;
      sigma_mu_alpha = context__.vals_r("sigma_mu_alpha")[(1 - 1)];
      current_statement__ = 220;
      stan::math::check_greater_or_equal(function__, "sigma_mu_alpha",
        sigma_mu_alpha, 0);
      current_statement__ = 221;
      context__.validate_dims("data initialization", "sigma_mu_beta",
        "double", std::vector<size_t>{});
      sigma_mu_beta = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 221;
      sigma_mu_beta = context__.vals_r("sigma_mu_beta")[(1 - 1)];
      current_statement__ = 221;
      stan::math::check_greater_or_equal(function__, "sigma_mu_beta",
        sigma_mu_beta, 0);
      current_statement__ = 222;
      context__.validate_dims("data initialization", "sigma_alpha_fixed",
        "double", std::vector<size_t>{});
      sigma_alpha_fixed = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 222;
      sigma_alpha_fixed = context__.vals_r("sigma_alpha_fixed")[(1 - 1)];
      current_statement__ = 222;
      stan::math::check_greater_or_equal(function__, "sigma_alpha_fixed",
        sigma_alpha_fixed, 0);
      current_statement__ = 223;
      context__.validate_dims("data initialization", "sigma_beta_fixed",
        "double", std::vector<size_t>{});
      sigma_beta_fixed = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 223;
      sigma_beta_fixed = context__.vals_r("sigma_beta_fixed")[(1 - 1)];
      current_statement__ = 223;
      stan::math::check_greater_or_equal(function__, "sigma_beta_fixed",
        sigma_beta_fixed, 0);
      current_statement__ = 224;
      context__.validate_dims("data initialization", "flip", "int",
        std::vector<size_t>{});
      flip = std::numeric_limits<int>::min();
      current_statement__ = 224;
      flip = context__.vals_i("flip")[(1 - 1)];
      current_statement__ = 224;
      stan::math::check_greater_or_equal(function__, "flip", flip, 0);
      current_statement__ = 224;
      stan::math::check_less_or_equal(function__, "flip", flip, 1);
      current_statement__ = 225;
      context__.validate_dims("data initialization", "het", "int",
        std::vector<size_t>{});
      het = std::numeric_limits<int>::min();
      current_statement__ = 225;
      het = context__.vals_i("het")[(1 - 1)];
      current_statement__ = 225;
      stan::math::check_greater_or_equal(function__, "het", het, 0);
      current_statement__ = 225;
      stan::math::check_less_or_equal(function__, "het", het, 1);
      current_statement__ = 226;
      context__.validate_dims("data initialization", "rat", "int",
        std::vector<size_t>{});
      rat = std::numeric_limits<int>::min();
      current_statement__ = 226;
      rat = context__.vals_i("rat")[(1 - 1)];
      current_statement__ = 226;
      stan::math::check_greater_or_equal(function__, "rat", rat, 0);
      current_statement__ = 226;
      stan::math::check_less_or_equal(function__, "rat", rat, 1);
      current_statement__ = 227;
      context__.validate_dims("data initialization", "group", "int",
        std::vector<size_t>{});
      group = std::numeric_limits<int>::min();
      current_statement__ = 227;
      group = context__.vals_i("group")[(1 - 1)];
      current_statement__ = 227;
      stan::math::check_greater_or_equal(function__, "group", group, 0);
      current_statement__ = 227;
      stan::math::check_less_or_equal(function__, "group", group, 1);
      current_statement__ = 228;
      context__.validate_dims("data initialization", "bam", "int",
        std::vector<size_t>{});
      bam = std::numeric_limits<int>::min();
      current_statement__ = 228;
      bam = context__.vals_i("bam")[(1 - 1)];
      current_statement__ = 228;
      stan::math::check_greater_or_equal(function__, "bam", bam, 0);
      current_statement__ = 228;
      stan::math::check_less_or_equal(function__, "bam", bam, 1);
      current_statement__ = 229;
      context__.validate_dims("data initialization", "fixed", "int",
        std::vector<size_t>{});
      fixed = std::numeric_limits<int>::min();
      current_statement__ = 229;
      fixed = context__.vals_i("fixed")[(1 - 1)];
      current_statement__ = 229;
      stan::math::check_greater_or_equal(function__, "fixed", fixed, 0);
      current_statement__ = 229;
      stan::math::check_less_or_equal(function__, "fixed", fixed, 1);
      current_statement__ = 230;
      context__.validate_dims("data initialization", "CV", "int",
        std::vector<size_t>{});
      CV = std::numeric_limits<int>::min();
      current_statement__ = 230;
      CV = context__.vals_i("CV")[(1 - 1)];
      current_statement__ = 230;
      stan::math::check_greater_or_equal(function__, "CV", CV, 0);
      current_statement__ = 230;
      stan::math::check_less_or_equal(function__, "CV", CV, 1);
      current_statement__ = 231;
      context__.validate_dims("data initialization", "MCMC", "int",
        std::vector<size_t>{});
      MCMC = std::numeric_limits<int>::min();
      current_statement__ = 231;
      MCMC = context__.vals_i("MCMC")[(1 - 1)];
      current_statement__ = 231;
      stan::math::check_greater_or_equal(function__, "MCMC", MCMC, 0);
      current_statement__ = 231;
      stan::math::check_less_or_equal(function__, "MCMC", MCMC, 1);
      current_statement__ = 232;
      stan::math::validate_non_negative_index("holdout", "N_obs", N_obs);
      current_statement__ = 233;
      context__.validate_dims("data initialization", "holdout", "double",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      holdout_data__ = Eigen::Matrix<double,-1,1>::Constant(N_obs,
                         std::numeric_limits<double>::quiet_NaN());
      new (&holdout)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(holdout_data__.data(), N_obs);
      {
        std::vector<local_scalar_t__> holdout_flat__;
        current_statement__ = 233;
        holdout_flat__ = context__.vals_r("holdout");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= N_obs; ++sym1__) {
          stan::model::assign(holdout, holdout_flat__[(pos__ - 1)],
            "assigning variable holdout", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 233;
      stan::math::check_greater_or_equal(function__, "holdout", holdout, 0);
      current_statement__ = 233;
      stan::math::check_less_or_equal(function__, "holdout", holdout, 1);
      current_statement__ = 234;
      nu_fixed = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 234;
      nu_fixed = static_cast<double>(6);
      current_statement__ = 235;
      tau_fixed = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 235;
      tau_fixed = (B / 4.0);
      current_statement__ = 236;
      eta_scale_fixed = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 236;
      eta_scale_fixed = (tau_fixed * J);
      current_statement__ = 237;
      psi_fixed = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 237;
      psi_fixed = static_cast<double>(6);
      current_statement__ = 238;
      sigma_alpha_prior_rate = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 238;
      sigma_alpha_prior_rate = ((5 - 1) / (B / 8.0));
      current_statement__ = 239;
      tau_prior_rate = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 239;
      tau_prior_rate = ((2 - 1) / (B / 5.0));
      current_statement__ = 240;
      stan::math::validate_non_negative_index("not_holdout", "N_obs", N_obs);
      current_statement__ = 241;
      not_holdout_data__ = Eigen::Matrix<double,-1,1>::Constant(N_obs,
                             std::numeric_limits<double>::quiet_NaN());
      new (&not_holdout)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(not_holdout_data__.data(),
        N_obs);
      current_statement__ = 241;
      stan::model::assign(not_holdout,
        stan::math::subtract(static_cast<double>(1), holdout),
        "assigning variable not_holdout");
      current_statement__ = 242;
      mean_mu_simplexes = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 242;
      mean_mu_simplexes = (1.0 / G);
      current_statement__ = 243;
      sd_mu_simplexes = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 243;
      sd_mu_simplexes = stan::math::sqrt(((mean_mu_simplexes * (1 -
                          mean_mu_simplexes)) / ((50 * G) + 1)));
      current_statement__ = 244;
      tau_multip = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 244;
      tau_multip = (1 / stan::math::sqrt(N_obs));
      current_statement__ = 245;
      stan::math::validate_non_negative_index("p", "N_obs", N_obs);
      current_statement__ = 246;
      p = std::vector<std::vector<double>>(2,
            std::vector<double>(N_obs,
              std::numeric_limits<double>::quiet_NaN()));
      current_statement__ = 250;
      for (int n = 1; n <= N_obs; ++n) {
        current_statement__ = 247;
        stan::model::assign(p,
          (((stan::model::rvalue(U, "U", stan::model::index_uni(n)) *
          stan::model::rvalue(V, "V",
            stan::model::index_uni(
              stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))) +
          (B * stan::model::rvalue(U, "U", stan::model::index_uni(n)))) - B),
          "assigning variable p", stan::model::index_uni(1),
          stan::model::index_uni(n));
        current_statement__ = 248;
        stan::model::assign(p,
          (((stan::model::rvalue(U, "U", stan::model::index_uni(n)) *
          stan::model::rvalue(V, "V",
            stan::model::index_uni(
              stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))) -
          (B * stan::model::rvalue(U, "U", stan::model::index_uni(n)))) + B),
          "assigning variable p", stan::model::index_uni(2),
          stan::model::index_uni(n));
      }
      current_statement__ = 238;
      stan::math::check_greater_or_equal(function__,
        "sigma_alpha_prior_rate", sigma_alpha_prior_rate, 0);
      current_statement__ = 239;
      stan::math::check_greater_or_equal(function__, "tau_prior_rate",
        tau_prior_rate, 0);
      current_statement__ = 241;
      stan::math::check_greater_or_equal(function__, "not_holdout",
        not_holdout, 0);
      current_statement__ = 241;
      stan::math::check_less_or_equal(function__, "not_holdout", not_holdout,
        1);
      current_statement__ = 246;
      stan::math::check_greater_or_equal(function__, "p", p, -(B));
      current_statement__ = 246;
      stan::math::check_less_or_equal(function__, "p", p, B);
      current_statement__ = 251;
      stan::math::validate_non_negative_index("alpha_raw", "N", N);
      current_statement__ = 252;
      alpha_raw_2dim__ = std::numeric_limits<int>::min();
      current_statement__ = 252;
      alpha_raw_2dim__ = (1 + flip);
      current_statement__ = 252;
      stan::math::validate_non_negative_index("alpha_raw", "1 + flip",
        alpha_raw_2dim__);
      current_statement__ = 253;
      stan::math::validate_non_negative_index("beta_raw", "N", N);
      current_statement__ = 254;
      beta_raw_2dim__ = std::numeric_limits<int>::min();
      current_statement__ = 254;
      beta_raw_2dim__ = (1 + flip);
      current_statement__ = 254;
      stan::math::validate_non_negative_index("beta_raw", "1 + flip",
        beta_raw_2dim__);
      current_statement__ = 255;
      theta_lr_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 255;
      theta_lr_1dim__ = (stan::math::logical_eq(bam, 0) ? 2 : 0);
      current_statement__ = 255;
      stan::math::validate_non_negative_index("theta_lr", "bam == 0 ? 2 : 0",
        theta_lr_1dim__);
      current_statement__ = 256;
      stan::math::validate_non_negative_index("theta_raw", "J", J);
      current_statement__ = 257;
      mu_alpha_raw_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 257;
      mu_alpha_raw_1dim__ = (stan::math::logical_eq(group, 1) ? G : 1);
      current_statement__ = 257;
      stan::math::validate_positive_index("mu_alpha_raw",
        "group == 1 ? G : 1", mu_alpha_raw_1dim__);
      current_statement__ = 258;
      mu_beta_raw_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 258;
      mu_beta_raw_1dim__ = (stan::math::logical_eq(group, 1) ? G : 1);
      current_statement__ = 258;
      stan::math::validate_positive_index("mu_beta_raw",
        "group == 1 ? G : 1", mu_beta_raw_1dim__);
      current_statement__ = 259;
      sigma_alpha_par_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 259;
      sigma_alpha_par_1dim__ = ((stan::math::primitive_value(
                                   stan::math::logical_eq(bam, 0))
        &&
        stan::math::primitive_value(stan::math::logical_eq(fixed, 0))) ? 1 : 0);
      current_statement__ = 259;
      stan::math::validate_non_negative_index("sigma_alpha_par",
        "bam == 0 && fixed == 0 ? 1 : 0", sigma_alpha_par_1dim__);
      current_statement__ = 260;
      sigma_beta_par_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 260;
      sigma_beta_par_1dim__ = ((stan::math::primitive_value(
                                  stan::math::logical_eq(bam, 0))
        &&
        stan::math::primitive_value(stan::math::logical_eq(fixed, 0))) ? 1 : 0);
      current_statement__ = 260;
      stan::math::validate_non_negative_index("sigma_beta_par",
        "bam == 0 && fixed == 0 ? 1 : 0", sigma_beta_par_1dim__);
      current_statement__ = 261;
      nu_par_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 261;
      nu_par_1dim__ = ((stan::math::primitive_value(
                          stan::math::logical_eq(het, 1))
        &&
        stan::math::primitive_value(stan::math::logical_eq(fixed, 0))) ? 1 : 0);
      current_statement__ = 261;
      stan::math::validate_non_negative_index("nu_par",
        "het == 1 && fixed == 0 ? 1 : 0", nu_par_1dim__);
      current_statement__ = 262;
      tau_par_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 262;
      tau_par_1dim__ = (1 - fixed);
      current_statement__ = 262;
      stan::math::validate_non_negative_index("tau_par", "1 - fixed",
        tau_par_1dim__);
      current_statement__ = 263;
      eta_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 263;
      eta_1dim__ = (stan::math::logical_eq(het, 1) ? N : 0);
      current_statement__ = 263;
      stan::math::validate_non_negative_index("eta", "het == 1 ? N : 0",
        eta_1dim__);
      current_statement__ = 264;
      rho_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 264;
      rho_1dim__ = (stan::math::logical_eq(het, 1) ? J : 1);
      current_statement__ = 264;
      stan::math::validate_positive_index("rho", "het == 1 ? J : 1",
        rho_1dim__);
      current_statement__ = 265;
      lambda_raw_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 265;
      lambda_raw_1dim__ = (stan::math::logical_eq(flip, 1) ? N : 0);
      current_statement__ = 265;
      stan::math::validate_non_negative_index("lambda_raw",
        "flip == 1 ? N : 0", lambda_raw_1dim__);
      current_statement__ = 266;
      psi_par_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 266;
      psi_par_1dim__ = ((stan::math::primitive_value(
                           stan::math::logical_eq(flip, 1))
        &&
        stan::math::primitive_value(stan::math::logical_eq(fixed, 0))) ? 1 : 0);
      current_statement__ = 266;
      stan::math::validate_non_negative_index("psi_par",
        "flip == 1 && fixed == 0 ? 1 : 0", psi_par_1dim__);
      current_statement__ = 267;
      gamma_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 267;
      gamma_1dim__ = (stan::math::logical_eq(rat, 1) ? N : 0);
      current_statement__ = 267;
      stan::math::validate_non_negative_index("gamma", "rat == 1 ? N : 0",
        gamma_1dim__);
      current_statement__ = 268;
      stan::math::validate_non_negative_index("gam_a", "rat", rat);
      current_statement__ = 269;
      stan::math::validate_non_negative_index("gam_b", "rat", rat);
      current_statement__ = 270;
      zeta_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 270;
      zeta_1dim__ = (stan::math::logical_eq(rat, 1) ? K : 0);
      current_statement__ = 270;
      stan::math::validate_non_negative_index("zeta", "rat == 1 ? K : 0",
        zeta_1dim__);
      current_statement__ = 271;
      log_probs_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 271;
      log_probs_1dim__ = (stan::math::logical_eq(rat, 1) ? 4 : 0);
      current_statement__ = 271;
      stan::math::validate_non_negative_index("log_probs",
        "rat == 1 ? 4 : 0", log_probs_1dim__);
      current_statement__ = 272;
      stan::math::validate_non_negative_index("theta", "J", J);
      current_statement__ = 273;
      stan::math::validate_non_negative_index("alpha0", "N", N);
      current_statement__ = 274;
      alpha0_2dim__ = std::numeric_limits<int>::min();
      current_statement__ = 274;
      alpha0_2dim__ = (1 + flip);
      current_statement__ = 274;
      stan::math::validate_non_negative_index("alpha0", "1 + flip",
        alpha0_2dim__);
      current_statement__ = 275;
      stan::math::validate_non_negative_index("beta0", "N", N);
      current_statement__ = 276;
      beta0_2dim__ = std::numeric_limits<int>::min();
      current_statement__ = 276;
      beta0_2dim__ = (1 + flip);
      current_statement__ = 276;
      stan::math::validate_non_negative_index("beta0", "1 + flip",
        beta0_2dim__);
      current_statement__ = 277;
      stan::math::validate_non_negative_index("log_lik", "N_obs", N_obs);
      current_statement__ = 278;
      lambda_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 278;
      lambda_1dim__ = (stan::math::logical_eq(flip, 1) ? N : 0);
      current_statement__ = 278;
      stan::math::validate_non_negative_index("lambda", "flip == 1 ? N : 0",
        lambda_1dim__);
      current_statement__ = 279;
      mu_alpha_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 279;
      mu_alpha_1dim__ = (stan::math::logical_eq(group, 1) ? G : 0);
      current_statement__ = 279;
      stan::math::validate_non_negative_index("mu_alpha",
        "group == 1 ? G : 0", mu_alpha_1dim__);
      current_statement__ = 280;
      mu_beta_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 280;
      mu_beta_1dim__ = (stan::math::logical_eq(group, 1) ? G : 0);
      current_statement__ = 280;
      stan::math::validate_non_negative_index("mu_beta",
        "group == 1 ? G : 0", mu_beta_1dim__);
      current_statement__ = 281;
      stan::math::validate_non_negative_index("eta_scale", "het", het);
      current_statement__ = 282;
      sigma_alpha_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 282;
      sigma_alpha_1dim__ = (1 - bam);
      current_statement__ = 282;
      stan::math::validate_non_negative_index("sigma_alpha", "1 - bam",
        sigma_alpha_1dim__);
      current_statement__ = 283;
      sigma_beta_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 283;
      sigma_beta_1dim__ = (1 - bam);
      current_statement__ = 283;
      stan::math::validate_non_negative_index("sigma_beta", "1 - bam",
        sigma_beta_1dim__);
      current_statement__ = 284;
      stan::math::validate_non_negative_index("nu", "het", het);
      current_statement__ = 285;
      stan::math::validate_non_negative_index("psi", "flip", flip);
      current_statement__ = 286;
      kappa_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 286;
      kappa_1dim__ = (stan::math::logical_eq(flip, 1) ? N : 0);
      current_statement__ = 286;
      stan::math::validate_non_negative_index("kappa", "flip == 1 ? N : 0",
        kappa_1dim__);
      current_statement__ = 287;
      stan::math::validate_non_negative_index("alpha", "N", N);
      current_statement__ = 288;
      stan::math::validate_non_negative_index("beta", "N", N);
      current_statement__ = 289;
      stan::math::validate_non_negative_index("chi", "N", N);
      current_statement__ = 290;
      Y_pred_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 290;
      Y_pred_1dim__ = ((stan::math::primitive_value(
                          stan::math::logical_eq(rat, 0))
        &&
        stan::math::primitive_value(stan::math::logical_eq(MCMC, 1))) ? N_obs : 0);
      current_statement__ = 290;
      stan::math::validate_non_negative_index("Y_pred",
        "rat == 0 && MCMC == 1 ? N_obs : 0", Y_pred_1dim__);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    num_params_r__ = (N * alpha_raw_2dim__) + (N * beta_raw_2dim__) +
      theta_lr_1dim__ + J + (mu_alpha_raw_1dim__ - 1) + (mu_beta_raw_1dim__ -
      1) + sigma_alpha_par_1dim__ + sigma_beta_par_1dim__ + nu_par_1dim__ +
      tau_par_1dim__ + eta_1dim__ + (rho_1dim__ - 1) + lambda_raw_1dim__ +
      psi_par_1dim__ + gamma_1dim__ + rat + rat + zeta_1dim__;
  }
  inline std::string model_name() const final {
    return "model_omni";
  }
  inline std::vector<std::string> model_compile_info() const noexcept {
    return std::vector<std::string>{"stanc_version = stanc3 v2.38.0-92-g9119e6c",
             "stancflags = --allow-undefined"};
  }
  // 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__ =
      "model_omni_namespace::log_prob";
    // suppress unused var warning
    (void) function__;
    try {
      current_statement__ = 1;
      auto alpha_raw =
        in__.template read<Eigen::Matrix<local_scalar_t__,-1,-1>>(N,
          alpha_raw_2dim__);
      current_statement__ = 2;
      auto beta_raw =
        in__.template read<Eigen::Matrix<local_scalar_t__,-1,-1>>(N,
          beta_raw_2dim__);
      current_statement__ = 3;
      auto theta_lr =
        in__.template read_constrain_ordered<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
          theta_lr_1dim__);
      current_statement__ = 4;
      auto theta_raw = in__.template read<std::vector<local_scalar_t__>>(J);
      current_statement__ = 5;
      auto mu_alpha_raw =
        in__.template read_constrain_simplex<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
          mu_alpha_raw_1dim__);
      current_statement__ = 6;
      auto mu_beta_raw =
        in__.template read_constrain_simplex<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
          mu_beta_raw_1dim__);
      current_statement__ = 7;
      auto sigma_alpha_par =
        in__.template read_constrain_lb<std::vector<local_scalar_t__>,
          jacobian__>(0, lp__, sigma_alpha_par_1dim__);
      current_statement__ = 8;
      auto sigma_beta_par =
        in__.template read_constrain_lub<std::vector<local_scalar_t__>,
          jacobian__>(0, 2, lp__, sigma_beta_par_1dim__);
      current_statement__ = 9;
      auto nu_par =
        in__.template read_constrain_lub<std::vector<local_scalar_t__>,
          jacobian__>(3, 30, lp__, nu_par_1dim__);
      current_statement__ = 10;
      auto tau_par =
        in__.template read_constrain_offset_multiplier<
          std::vector<local_scalar_t__>, jacobian__>(0, tau_multip, lp__,
          tau_par_1dim__);
      current_statement__ = 11;
      auto eta =
        in__.template read_constrain_lb<Eigen::Matrix<local_scalar_t__,-1,1>,
          jacobian__>(0, lp__, eta_1dim__);
      current_statement__ = 12;
      auto rho =
        in__.template read_constrain_simplex<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__, rho_1dim__);
      current_statement__ = 13;
      auto lambda_raw =
        in__.template read<
          Eigen::Matrix<local_scalar_t__,-1,1>>(lambda_raw_1dim__);
      current_statement__ = 14;
      auto psi_par =
        in__.template read_constrain_lb<std::vector<local_scalar_t__>,
          jacobian__>(0, lp__, psi_par_1dim__);
      current_statement__ = 15;
      auto gamma =
        in__.template read_constrain_lub<std::vector<local_scalar_t__>,
          jacobian__>(0, 1, lp__, gamma_1dim__);
      current_statement__ = 16;
      auto gam_a =
        in__.template read_constrain_lb<std::vector<local_scalar_t__>,
          jacobian__>(1, lp__, rat);
      current_statement__ = 17;
      auto gam_b =
        in__.template read_constrain_lb<std::vector<local_scalar_t__>,
          jacobian__>(1, lp__, rat);
      current_statement__ = 18;
      auto zeta =
        in__.template read_constrain_lub<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0, 1, lp__,
          zeta_1dim__);
      Eigen::Matrix<local_scalar_t__,-1,1> log_probs =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(log_probs_1dim__,
          DUMMY_VAR__);
      std::vector<local_scalar_t__> theta =
        std::vector<local_scalar_t__>(J, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,-1> alpha0 =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(N, alpha0_2dim__,
          DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,-1> beta0 =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(N, beta0_2dim__,
          DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> log_lik =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_obs, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> lambda =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(lambda_1dim__,
          DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> mu_alpha =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(mu_alpha_1dim__,
          DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> mu_beta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(mu_beta_1dim__,
          DUMMY_VAR__);
      std::vector<local_scalar_t__> eta_scale =
        std::vector<local_scalar_t__>(het, DUMMY_VAR__);
      std::vector<local_scalar_t__> sigma_alpha =
        std::vector<local_scalar_t__>(sigma_alpha_1dim__, DUMMY_VAR__);
      std::vector<local_scalar_t__> sigma_beta =
        std::vector<local_scalar_t__>(sigma_beta_1dim__, DUMMY_VAR__);
      std::vector<local_scalar_t__> nu =
        std::vector<local_scalar_t__>(het, DUMMY_VAR__);
      local_scalar_t__ tau = DUMMY_VAR__;
      std::vector<local_scalar_t__> psi =
        std::vector<local_scalar_t__>(flip, DUMMY_VAR__);
      current_statement__ = 65;
      if (stan::math::logical_eq(fixed, 0)) {
        current_statement__ = 52;
        tau = stan::model::rvalue(tau_par, "tau_par",
                stan::model::index_uni(1));
        current_statement__ = 56;
        if (stan::math::logical_eq(bam, 0)) {
          current_statement__ = 53;
          stan::model::assign(sigma_alpha, sigma_alpha_par,
            "assigning variable sigma_alpha");
          current_statement__ = 54;
          stan::model::assign(sigma_beta, sigma_beta_par,
            "assigning variable sigma_beta");
        }
        current_statement__ = 60;
        if (stan::math::logical_eq(het, 1)) {
          current_statement__ = 57;
          stan::model::assign(nu, nu_par, "assigning variable nu");
          current_statement__ = 58;
          stan::model::assign(eta_scale, (tau * J),
            "assigning variable eta_scale", stan::model::index_uni(1));
        }
        current_statement__ = 63;
        if (stan::math::logical_eq(flip, 1)) {
          current_statement__ = 61;
          stan::model::assign(psi, psi_par, "assigning variable psi");
        }
      } else {
        current_statement__ = 39;
        tau = tau_fixed;
        current_statement__ = 43;
        if (stan::math::logical_eq(bam, 0)) {
          current_statement__ = 40;
          stan::model::assign(sigma_alpha, sigma_alpha_fixed,
            "assigning variable sigma_alpha", stan::model::index_uni(1));
          current_statement__ = 41;
          stan::model::assign(sigma_beta, sigma_beta_fixed,
            "assigning variable sigma_beta", stan::model::index_uni(1));
        }
        current_statement__ = 47;
        if (stan::math::logical_eq(het, 1)) {
          current_statement__ = 44;
          stan::model::assign(nu, nu_fixed, "assigning variable nu",
            stan::model::index_uni(1));
          current_statement__ = 45;
          stan::model::assign(eta_scale, (tau * J),
            "assigning variable eta_scale", stan::model::index_uni(1));
        }
        current_statement__ = 50;
        if (stan::math::logical_eq(flip, 1)) {
          current_statement__ = 48;
          stan::model::assign(psi, psi_fixed, "assigning variable psi",
            stan::model::index_uni(1));
        }
      }
      current_statement__ = 69;
      if (stan::math::logical_eq(group, 1)) {
        current_statement__ = 66;
        stan::model::assign(mu_alpha,
          stan::math::multiply(
            stan::math::divide(
              stan::math::subtract(mu_alpha_raw, mean_mu_simplexes),
              sd_mu_simplexes), sigma_mu_alpha),
          "assigning variable mu_alpha");
        current_statement__ = 67;
        stan::model::assign(mu_beta,
          stan::math::multiply(
            stan::math::divide(
              stan::math::subtract(mu_beta_raw, mean_mu_simplexes),
              sd_mu_simplexes), sigma_mu_beta), "assigning variable mu_beta");
      }
      current_statement__ = 70;
      stan::model::assign(theta, theta_raw, "assigning variable theta");
      current_statement__ = 125;
      if (stan::math::logical_eq(bam, 1)) {
        current_statement__ = 117;
        stan::model::assign(theta,
          stan::model::rvalue(mean_spos, "mean_spos",
            stan::model::index_uni(L)), "assigning variable theta",
          stan::model::index_uni(L));
        current_statement__ = 118;
        stan::model::assign(theta,
          stan::model::rvalue(mean_spos, "mean_spos",
            stan::model::index_uni(R)), "assigning variable theta",
          stan::model::index_uni(R));
        current_statement__ = 119;
        stan::model::assign(alpha0,
          stan::model::rvalue(alpha_raw, "alpha_raw",
            stan::model::index_omni(), stan::model::index_uni(1)),
          "assigning variable alpha0", stan::model::index_omni(),
          stan::model::index_uni(1));
        current_statement__ = 120;
        stan::model::assign(beta0,
          stan::model::rvalue(beta_raw, "beta_raw",
            stan::model::index_omni(), stan::model::index_uni(1)),
          "assigning variable beta0", stan::model::index_omni(),
          stan::model::index_uni(1));
        current_statement__ = 123;
        for (int n = 1; n <= N_obs; ++n) {
          current_statement__ = 121;
          stan::model::assign(log_lik,
            stan::math::normal_lpdf<false>(
              stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
              (stan::model::rvalue(alpha0, "alpha0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(1)) +
              (stan::model::rvalue(beta0, "beta0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(1)) *
              stan::model::rvalue(theta, "theta",
                stan::model::index_uni(
                  stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
              (stan::math::sqrt(
                 stan::model::rvalue(eta, "eta",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
              *
              stan::model::rvalue(rho, "rho",
                stan::model::index_uni(
                  stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
            "assigning variable log_lik", stan::model::index_uni(n));
        }
      } else {
        current_statement__ = 71;
        stan::model::assign(theta,
          stan::model::rvalue(theta_lr, "theta_lr", stan::model::index_uni(1)),
          "assigning variable theta", stan::model::index_uni(L));
        current_statement__ = 72;
        stan::model::assign(theta,
          stan::model::rvalue(theta_lr, "theta_lr", stan::model::index_uni(2)),
          "assigning variable theta", stan::model::index_uni(R));
        current_statement__ = 79;
        if (stan::math::logical_eq(group, 0)) {
          current_statement__ = 76;
          stan::model::assign(alpha0,
            stan::math::multiply(
              stan::model::rvalue(alpha_raw, "alpha_raw",
                stan::model::index_omni(), stan::model::index_uni(1)),
              stan::model::rvalue(sigma_alpha, "sigma_alpha",
                stan::model::index_uni(1))), "assigning variable alpha0",
            stan::model::index_omni(), stan::model::index_uni(1));
          current_statement__ = 77;
          stan::model::assign(beta0,
            stan::math::exp(
              stan::math::multiply(
                stan::model::rvalue(beta_raw, "beta_raw",
                  stan::model::index_omni(), stan::model::index_uni(1)),
                stan::model::rvalue(sigma_beta, "sigma_beta",
                  stan::model::index_uni(1)))), "assigning variable beta0",
            stan::model::index_omni(), stan::model::index_uni(1));
        } else {
          current_statement__ = 73;
          stan::model::assign(alpha0,
            stan::math::add(
              stan::math::multiply(
                stan::model::rvalue(alpha_raw, "alpha_raw",
                  stan::model::index_omni(), stan::model::index_uni(1)),
                stan::model::rvalue(sigma_alpha, "sigma_alpha",
                  stan::model::index_uni(1))),
              stan::model::rvalue(mu_alpha, "mu_alpha",
                stan::model::index_multi(gg))), "assigning variable alpha0",
            stan::model::index_omni(), stan::model::index_uni(1));
          current_statement__ = 74;
          stan::model::assign(beta0,
            stan::math::exp(
              stan::math::add(
                stan::math::multiply(
                  stan::model::rvalue(beta_raw, "beta_raw",
                    stan::model::index_omni(), stan::model::index_uni(1)),
                  stan::model::rvalue(sigma_beta, "sigma_beta",
                    stan::model::index_uni(1))),
                stan::model::rvalue(mu_beta, "mu_beta",
                  stan::model::index_multi(gg)))),
            "assigning variable beta0", stan::model::index_omni(),
            stan::model::index_uni(1));
        }
        current_statement__ = 88;
        if (stan::math::logical_eq(flip, 1)) {
          current_statement__ = 80;
          stan::model::assign(lambda,
            stan::math::inv_logit(
              stan::math::add(
                stan::model::rvalue(psi, "psi", stan::model::index_uni(1)),
                stan::math::multiply(lambda_raw, static_cast<double>(3)))),
            "assigning variable lambda");
          current_statement__ = 81;
          stan::model::assign(beta0,
            stan::math::minus(
              stan::math::exp(
                stan::math::multiply(
                  stan::model::rvalue(beta_raw, "beta_raw",
                    stan::model::index_omni(), stan::model::index_uni(2)),
                  stan::model::rvalue(sigma_beta, "sigma_beta",
                    stan::model::index_uni(1))))),
            "assigning variable beta0", stan::model::index_omni(),
            stan::model::index_uni(2));
          current_statement__ = 86;
          if (stan::math::logical_eq(group, 0)) {
            current_statement__ = 84;
            stan::model::assign(alpha0,
              stan::math::multiply(
                stan::model::rvalue(alpha_raw, "alpha_raw",
                  stan::model::index_omni(), stan::model::index_uni(2)),
                stan::model::rvalue(sigma_alpha, "sigma_alpha",
                  stan::model::index_uni(1))), "assigning variable alpha0",
              stan::model::index_omni(), stan::model::index_uni(2));
          } else {
            current_statement__ = 82;
            stan::model::assign(alpha0,
              stan::math::add(
                stan::math::multiply(
                  stan::model::rvalue(alpha_raw, "alpha_raw",
                    stan::model::index_omni(), stan::model::index_uni(2)),
                  stan::model::rvalue(sigma_alpha, "sigma_alpha",
                    stan::model::index_uni(1))),
                stan::model::rvalue(mu_alpha, "mu_alpha",
                  stan::model::index_multi(gg))),
              "assigning variable alpha0", stan::model::index_omni(),
              stan::model::index_uni(2));
          }
        }
        current_statement__ = 115;
        if (stan::math::logical_eq(rat, 1)) {
          current_statement__ = 113;
          for (int n = 1; n <= N_obs; ++n) {
            Eigen::Matrix<local_scalar_t__,-1,1> mu0 =
              Eigen::Matrix<local_scalar_t__,-1,1>::Constant(2, DUMMY_VAR__);
            current_statement__ = 105;
            stan::model::assign(mu0,
              (stan::model::rvalue(alpha0, "alpha0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(1)) +
              (stan::model::rvalue(beta0, "beta0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(1)) *
              stan::model::rvalue(theta, "theta",
                stan::model::index_uni(
                  stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
              "assigning variable mu0", stan::model::index_uni(1));
            current_statement__ = 106;
            stan::model::assign(mu0,
              (stan::model::rvalue(alpha0, "alpha0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(2)) +
              (stan::model::rvalue(beta0, "beta0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(2)) *
              stan::model::rvalue(theta, "theta",
                stan::model::index_uni(
                  stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
              "assigning variable mu0", stan::model::index_uni(2));
            current_statement__ = 107;
            stan::model::assign(log_probs,
              ((stan::math::log(
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
              +
              stan::math::log(
                stan::model::rvalue(zeta, "zeta",
                  stan::model::index_uni(
                    stan::model::rvalue(Vi, "Vi",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n)))))))) +
              stan::math::normal_lpdf<false>(
                stan::model::rvalue(Y, "Y", stan::model::index_uni(n)), (((1
                -
                stan::model::rvalue(gamma, "gamma",
                  stan::model::index_uni(
                    stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
                * stan::model::rvalue(mu0, "mu0", stan::model::index_uni(1)))
                +
                (stan::model::rvalue(gamma, "gamma",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                *
                stan::model::rvalue(p, "p", stan::model::index_uni(1),
                  stan::model::index_uni(n)))), tau)),
              "assigning variable log_probs", stan::model::index_uni(1));
            current_statement__ = 108;
            stan::model::assign(log_probs,
              ((stan::math::log(
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
              +
              stan::math::log((1 -
                stan::model::rvalue(zeta, "zeta",
                  stan::model::index_uni(
                    stan::model::rvalue(Vi, "Vi",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n))))))))) +
              stan::math::normal_lpdf<false>(
                stan::model::rvalue(Y, "Y", stan::model::index_uni(n)), (((1
                -
                stan::model::rvalue(gamma, "gamma",
                  stan::model::index_uni(
                    stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
                * stan::model::rvalue(mu0, "mu0", stan::model::index_uni(1)))
                +
                (stan::model::rvalue(gamma, "gamma",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                *
                stan::model::rvalue(p, "p", stan::model::index_uni(2),
                  stan::model::index_uni(n)))), tau)),
              "assigning variable log_probs", stan::model::index_uni(2));
            current_statement__ = 109;
            stan::model::assign(log_probs,
              ((stan::math::log((1 -
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))))
              +
              stan::math::log(
                stan::model::rvalue(zeta, "zeta",
                  stan::model::index_uni(
                    stan::model::rvalue(Vi, "Vi",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n)))))))) +
              stan::math::normal_lpdf<false>(
                stan::model::rvalue(Y, "Y", stan::model::index_uni(n)), (((1
                -
                stan::model::rvalue(gamma, "gamma",
                  stan::model::index_uni(
                    stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
                * stan::model::rvalue(mu0, "mu0", stan::model::index_uni(2)))
                +
                (stan::model::rvalue(gamma, "gamma",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                *
                stan::model::rvalue(p, "p", stan::model::index_uni(1),
                  stan::model::index_uni(n)))), tau)),
              "assigning variable log_probs", stan::model::index_uni(3));
            current_statement__ = 110;
            stan::model::assign(log_probs,
              ((stan::math::log((1 -
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))))
              +
              stan::math::log((1 -
                stan::model::rvalue(zeta, "zeta",
                  stan::model::index_uni(
                    stan::model::rvalue(Vi, "Vi",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n))))))))) +
              stan::math::normal_lpdf<false>(
                stan::model::rvalue(Y, "Y", stan::model::index_uni(n)), (((1
                -
                stan::model::rvalue(gamma, "gamma",
                  stan::model::index_uni(
                    stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
                * stan::model::rvalue(mu0, "mu0", stan::model::index_uni(2)))
                +
                (stan::model::rvalue(gamma, "gamma",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                *
                stan::model::rvalue(p, "p", stan::model::index_uni(2),
                  stan::model::index_uni(n)))), tau)),
              "assigning variable log_probs", stan::model::index_uni(4));
            current_statement__ = 111;
            stan::model::assign(log_lik, stan::math::log_sum_exp(log_probs),
              "assigning variable log_lik", stan::model::index_uni(n));
          }
        } else {
          current_statement__ = 103;
          if (stan::math::logical_eq(het, 0)) {
            current_statement__ = 101;
            for (int n = 1; n <= N_obs; ++n) {
              current_statement__ = 99;
              stan::model::assign(log_lik,
                stan::math::log_mix(
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))),
                  stan::math::normal_lpdf<false>(
                    stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                    (stan::model::rvalue(alpha0, "alpha0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(1)) +
                    (stan::model::rvalue(beta0, "beta0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(1)) *
                    stan::model::rvalue(theta, "theta",
                      stan::model::index_uni(
                        stan::model::rvalue(jj, "jj",
                          stan::model::index_uni(n)))))), tau),
                  stan::math::normal_lpdf<false>(
                    stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                    (stan::model::rvalue(alpha0, "alpha0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(2)) +
                    (stan::model::rvalue(beta0, "beta0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(2)) *
                    stan::model::rvalue(theta, "theta",
                      stan::model::index_uni(
                        stan::model::rvalue(jj, "jj",
                          stan::model::index_uni(n)))))), tau)),
                "assigning variable log_lik", stan::model::index_uni(n));
            }
          } else {
            current_statement__ = 97;
            if (stan::math::logical_eq(flip, 1)) {
              current_statement__ = 95;
              for (int n = 1; n <= N_obs; ++n) {
                current_statement__ = 93;
                stan::model::assign(log_lik,
                  stan::math::log_mix(
                    stan::model::rvalue(lambda, "lambda",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n)))),
                    stan::math::normal_lpdf<false>(
                      stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                      (stan::model::rvalue(alpha0, "alpha0",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))),
                         stan::model::index_uni(1)) +
                      (stan::model::rvalue(beta0, "beta0",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))),
                         stan::model::index_uni(1)) *
                      stan::model::rvalue(theta, "theta",
                        stan::model::index_uni(
                          stan::model::rvalue(jj, "jj",
                            stan::model::index_uni(n)))))),
                      (stan::math::sqrt(
                         stan::model::rvalue(eta, "eta",
                           stan::model::index_uni(
                             stan::model::rvalue(ii, "ii",
                               stan::model::index_uni(n))))) *
                      stan::model::rvalue(rho, "rho",
                        stan::model::index_uni(
                          stan::model::rvalue(jj, "jj",
                            stan::model::index_uni(n)))))),
                    stan::math::normal_lpdf<false>(
                      stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                      (stan::model::rvalue(alpha0, "alpha0",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))),
                         stan::model::index_uni(2)) +
                      (stan::model::rvalue(beta0, "beta0",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))),
                         stan::model::index_uni(2)) *
                      stan::model::rvalue(theta, "theta",
                        stan::model::index_uni(
                          stan::model::rvalue(jj, "jj",
                            stan::model::index_uni(n)))))),
                      (stan::math::sqrt(
                         stan::model::rvalue(eta, "eta",
                           stan::model::index_uni(
                             stan::model::rvalue(ii, "ii",
                               stan::model::index_uni(n))))) *
                      stan::model::rvalue(rho, "rho",
                        stan::model::index_uni(
                          stan::model::rvalue(jj, "jj",
                            stan::model::index_uni(n))))))),
                  "assigning variable log_lik", stan::model::index_uni(n));
              }
            } else {
              current_statement__ = 91;
              for (int n = 1; n <= N_obs; ++n) {
                current_statement__ = 89;
                stan::model::assign(log_lik,
                  stan::math::normal_lpdf<false>(
                    stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                    (stan::model::rvalue(alpha0, "alpha0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(1)) +
                    (stan::model::rvalue(beta0, "beta0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(1)) *
                    stan::model::rvalue(theta, "theta",
                      stan::model::index_uni(
                        stan::model::rvalue(jj, "jj",
                          stan::model::index_uni(n)))))),
                    (stan::math::sqrt(
                       stan::model::rvalue(eta, "eta",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))))) *
                    stan::model::rvalue(rho, "rho",
                      stan::model::index_uni(
                        stan::model::rvalue(jj, "jj",
                          stan::model::index_uni(n)))))),
                  "assigning variable log_lik", stan::model::index_uni(n));
              }
            }
          }
        }
      }
      current_statement__ = 24;
      stan::math::check_greater_or_equal(function__, "lambda", lambda, 0);
      current_statement__ = 24;
      stan::math::check_less_or_equal(function__, "lambda", lambda, 1);
      current_statement__ = 27;
      stan::math::check_greater_or_equal(function__, "eta_scale", eta_scale,
        0);
      current_statement__ = 28;
      stan::math::check_greater_or_equal(function__, "sigma_alpha",
        sigma_alpha, 0);
      current_statement__ = 29;
      stan::math::check_greater_or_equal(function__, "sigma_beta",
        sigma_beta, 0);
      current_statement__ = 29;
      stan::math::check_less_or_equal(function__, "sigma_beta", sigma_beta, 2);
      current_statement__ = 30;
      stan::math::check_greater_or_equal(function__, "nu", nu, 3);
      current_statement__ = 30;
      stan::math::check_less_or_equal(function__, "nu", nu, 30);
      current_statement__ = 31;
      stan::math::check_greater_or_equal(function__, "tau", tau, 0);
      current_statement__ = 32;
      stan::math::check_greater_or_equal(function__, "psi", psi, 0);
      {
        current_statement__ = 155;
        lp_accum__.add(stan::math::normal_lpdf<propto__>(theta_raw,
                         static_cast<double>(0), (B / 2.0)));
        current_statement__ = 165;
        if (stan::math::logical_eq(bam, 1)) {
          current_statement__ = 162;
          lp_accum__.add(stan::math::uniform_lpdf<propto__>(
                           stan::model::rvalue(alpha_raw, "alpha_raw",
                             stan::model::index_omni(),
                             stan::model::index_uni(1)),
                           static_cast<double>(-(100)),
                           static_cast<double>(100)));
          current_statement__ = 163;
          lp_accum__.add(stan::math::uniform_lpdf<propto__>(
                           stan::model::rvalue(beta_raw, "beta_raw",
                             stan::model::index_omni(),
                             stan::model::index_uni(1)),
                           static_cast<double>(-(100)),
                           static_cast<double>(100)));
        } else {
          current_statement__ = 156;
          lp_accum__.add(stan::math::normal_lpdf<propto__>(theta_lr,
                           static_cast<double>(0), (B / 2.0)));
          current_statement__ = 157;
          lp_accum__.add(stan::math::normal_lpdf<propto__>(
                           stan::model::rvalue(alpha_raw, "alpha_raw",
                             stan::model::index_omni(),
                             stan::model::index_uni(1)),
                           static_cast<double>(0), static_cast<double>(1)));
          current_statement__ = 158;
          lp_accum__.add(stan::math::gamma_lpdf<propto__>(sigma_alpha_par,
                           static_cast<double>(5), sigma_alpha_prior_rate));
          current_statement__ = 159;
          lp_accum__.add(stan::math::normal_lpdf<propto__>(
                           stan::model::rvalue(beta_raw, "beta_raw",
                             stan::model::index_omni(),
                             stan::model::index_uni(1)),
                           static_cast<double>(0), static_cast<double>(1)));
          current_statement__ = 160;
          lp_accum__.add(stan::math::gamma_lpdf<propto__>(sigma_beta_par,
                           static_cast<double>(9), static_cast<double>(40)));
        }
        current_statement__ = 172;
        if (stan::math::logical_eq(group, 1)) {
          current_statement__ = 169;
          lp_accum__.add(stan::math::dirichlet_lpdf<propto__>(mu_alpha_raw,
                           stan::math::rep_vector(static_cast<double>(50), G)));
          current_statement__ = 170;
          lp_accum__.add(stan::math::dirichlet_lpdf<propto__>(mu_beta_raw,
                           stan::math::rep_vector(static_cast<double>(50), G)));
        } else {
          current_statement__ = 166;
          lp_accum__.add(stan::math::dirichlet_lpdf<propto__>(mu_alpha_raw,
                           stan::math::rep_vector(static_cast<double>(50), 1)));
          current_statement__ = 167;
          lp_accum__.add(stan::math::dirichlet_lpdf<propto__>(mu_beta_raw,
                           stan::math::rep_vector(static_cast<double>(50), 1)));
        }
        current_statement__ = 178;
        if (stan::math::logical_eq(flip, 1)) {
          current_statement__ = 173;
          lp_accum__.add(stan::math::normal_lpdf<propto__>(
                           stan::model::rvalue(alpha_raw, "alpha_raw",
                             stan::model::index_omni(),
                             stan::model::index_uni(2)),
                           static_cast<double>(0), static_cast<double>(1)));
          current_statement__ = 174;
          lp_accum__.add(stan::math::normal_lpdf<propto__>(
                           stan::model::rvalue(beta_raw, "beta_raw",
                             stan::model::index_omni(),
                             stan::model::index_uni(2)),
                           static_cast<double>(0), static_cast<double>(1)));
          current_statement__ = 175;
          lp_accum__.add(stan::math::normal_lpdf<propto__>(lambda_raw,
                           static_cast<double>(0), static_cast<double>(1)));
          current_statement__ = 176;
          lp_accum__.add(stan::math::lognormal_lpdf<propto__>(psi_par, 1.4,
                           .5));
        }
        current_statement__ = 184;
        if (stan::math::logical_eq(rat, 1)) {
          current_statement__ = 179;
          lp_accum__.add(stan::math::beta_lpdf<propto__>(gamma,
                           stan::model::rvalue(gam_a, "gam_a",
                             stan::model::index_uni(1)),
                           stan::model::rvalue(gam_b, "gam_b",
                             stan::model::index_uni(1))));
          current_statement__ = 180;
          lp_accum__.add(stan::math::gamma_lpdf<propto__>(gam_a, 1.5, .5));
          current_statement__ = 181;
          lp_accum__.add(stan::math::gamma_lpdf<propto__>(gam_b, 1.5, .5));
          current_statement__ = 182;
          lp_accum__.add(stan::math::beta_lpdf<propto__>(zeta, 1.2, 1.2));
        }
        current_statement__ = 191;
        if (stan::math::logical_eq(het, 1)) {
          current_statement__ = 187;
          lp_accum__.add(stan::math::scaled_inv_chi_square_lpdf<propto__>(
                           eta,
                           stan::model::rvalue(nu, "nu",
                             stan::model::index_uni(1)),
                           stan::model::rvalue(eta_scale, "eta_scale",
                             stan::model::index_uni(1))));
          current_statement__ = 188;
          lp_accum__.add(stan::math::gamma_lpdf<propto__>(nu_par,
                           static_cast<double>(25), 2.5));
          current_statement__ = 189;
          lp_accum__.add(stan::math::dirichlet_lpdf<propto__>(rho,
                           stan::math::rep_vector(static_cast<double>(50), J)));
        } else {
          current_statement__ = 185;
          lp_accum__.add(stan::math::dirichlet_lpdf<propto__>(rho,
                           stan::math::rep_vector(static_cast<double>(50), 1)));
        }
        current_statement__ = 192;
        lp_accum__.add(stan::math::gamma_lpdf<propto__>(tau_par,
                         static_cast<double>(2), tau_prior_rate));
        current_statement__ = 195;
        if (stan::math::logical_eq(CV, 0)) {
          current_statement__ = 194;
          lp_accum__.add(stan::math::sum(log_lik));
        } else {
          current_statement__ = 193;
          lp_accum__.add(stan::math::sum(
                           stan::math::elt_multiply(log_lik, not_holdout)));
        }
      }
    } 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__ =
      "model_omni_namespace::log_prob";
    // suppress unused var warning
    (void) function__;
    try {
      current_statement__ = 1;
      auto alpha_raw =
        in__.template read<Eigen::Matrix<local_scalar_t__,-1,-1>>(N,
          alpha_raw_2dim__);
      current_statement__ = 2;
      auto beta_raw =
        in__.template read<Eigen::Matrix<local_scalar_t__,-1,-1>>(N,
          beta_raw_2dim__);
      current_statement__ = 3;
      auto theta_lr =
        in__.template read_constrain_ordered<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
          theta_lr_1dim__);
      current_statement__ = 4;
      auto theta_raw = in__.template read<std::vector<local_scalar_t__>>(J);
      current_statement__ = 5;
      auto mu_alpha_raw =
        in__.template read_constrain_simplex<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
          mu_alpha_raw_1dim__);
      current_statement__ = 6;
      auto mu_beta_raw =
        in__.template read_constrain_simplex<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
          mu_beta_raw_1dim__);
      current_statement__ = 7;
      auto sigma_alpha_par =
        in__.template read_constrain_lb<std::vector<local_scalar_t__>,
          jacobian__>(0, lp__, sigma_alpha_par_1dim__);
      current_statement__ = 8;
      auto sigma_beta_par =
        in__.template read_constrain_lub<std::vector<local_scalar_t__>,
          jacobian__>(0, 2, lp__, sigma_beta_par_1dim__);
      current_statement__ = 9;
      auto nu_par =
        in__.template read_constrain_lub<std::vector<local_scalar_t__>,
          jacobian__>(3, 30, lp__, nu_par_1dim__);
      current_statement__ = 10;
      auto tau_par =
        in__.template read_constrain_offset_multiplier<
          std::vector<local_scalar_t__>, jacobian__>(0, tau_multip, lp__,
          tau_par_1dim__);
      current_statement__ = 11;
      auto eta =
        in__.template read_constrain_lb<Eigen::Matrix<local_scalar_t__,-1,1>,
          jacobian__>(0, lp__, eta_1dim__);
      current_statement__ = 12;
      auto rho =
        in__.template read_constrain_simplex<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__, rho_1dim__);
      current_statement__ = 13;
      auto lambda_raw =
        in__.template read<
          Eigen::Matrix<local_scalar_t__,-1,1>>(lambda_raw_1dim__);
      current_statement__ = 14;
      auto psi_par =
        in__.template read_constrain_lb<std::vector<local_scalar_t__>,
          jacobian__>(0, lp__, psi_par_1dim__);
      current_statement__ = 15;
      auto gamma =
        in__.template read_constrain_lub<std::vector<local_scalar_t__>,
          jacobian__>(0, 1, lp__, gamma_1dim__);
      current_statement__ = 16;
      auto gam_a =
        in__.template read_constrain_lb<std::vector<local_scalar_t__>,
          jacobian__>(1, lp__, rat);
      current_statement__ = 17;
      auto gam_b =
        in__.template read_constrain_lb<std::vector<local_scalar_t__>,
          jacobian__>(1, lp__, rat);
      current_statement__ = 18;
      auto zeta =
        in__.template read_constrain_lub<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0, 1, lp__,
          zeta_1dim__);
      Eigen::Matrix<local_scalar_t__,-1,1> log_probs =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(log_probs_1dim__,
          DUMMY_VAR__);
      std::vector<local_scalar_t__> theta =
        std::vector<local_scalar_t__>(J, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,-1> alpha0 =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(N, alpha0_2dim__,
          DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,-1> beta0 =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(N, beta0_2dim__,
          DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> log_lik =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_obs, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> lambda =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(lambda_1dim__,
          DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> mu_alpha =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(mu_alpha_1dim__,
          DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> mu_beta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(mu_beta_1dim__,
          DUMMY_VAR__);
      std::vector<local_scalar_t__> eta_scale =
        std::vector<local_scalar_t__>(het, DUMMY_VAR__);
      std::vector<local_scalar_t__> sigma_alpha =
        std::vector<local_scalar_t__>(sigma_alpha_1dim__, DUMMY_VAR__);
      std::vector<local_scalar_t__> sigma_beta =
        std::vector<local_scalar_t__>(sigma_beta_1dim__, DUMMY_VAR__);
      std::vector<local_scalar_t__> nu =
        std::vector<local_scalar_t__>(het, DUMMY_VAR__);
      local_scalar_t__ tau = DUMMY_VAR__;
      std::vector<local_scalar_t__> psi =
        std::vector<local_scalar_t__>(flip, DUMMY_VAR__);
      current_statement__ = 65;
      if (stan::math::logical_eq(fixed, 0)) {
        current_statement__ = 52;
        tau = stan::model::rvalue(tau_par, "tau_par",
                stan::model::index_uni(1));
        current_statement__ = 56;
        if (stan::math::logical_eq(bam, 0)) {
          current_statement__ = 53;
          stan::model::assign(sigma_alpha, sigma_alpha_par,
            "assigning variable sigma_alpha");
          current_statement__ = 54;
          stan::model::assign(sigma_beta, sigma_beta_par,
            "assigning variable sigma_beta");
        }
        current_statement__ = 60;
        if (stan::math::logical_eq(het, 1)) {
          current_statement__ = 57;
          stan::model::assign(nu, nu_par, "assigning variable nu");
          current_statement__ = 58;
          stan::model::assign(eta_scale, (tau * J),
            "assigning variable eta_scale", stan::model::index_uni(1));
        }
        current_statement__ = 63;
        if (stan::math::logical_eq(flip, 1)) {
          current_statement__ = 61;
          stan::model::assign(psi, psi_par, "assigning variable psi");
        }
      } else {
        current_statement__ = 39;
        tau = tau_fixed;
        current_statement__ = 43;
        if (stan::math::logical_eq(bam, 0)) {
          current_statement__ = 40;
          stan::model::assign(sigma_alpha, sigma_alpha_fixed,
            "assigning variable sigma_alpha", stan::model::index_uni(1));
          current_statement__ = 41;
          stan::model::assign(sigma_beta, sigma_beta_fixed,
            "assigning variable sigma_beta", stan::model::index_uni(1));
        }
        current_statement__ = 47;
        if (stan::math::logical_eq(het, 1)) {
          current_statement__ = 44;
          stan::model::assign(nu, nu_fixed, "assigning variable nu",
            stan::model::index_uni(1));
          current_statement__ = 45;
          stan::model::assign(eta_scale, (tau * J),
            "assigning variable eta_scale", stan::model::index_uni(1));
        }
        current_statement__ = 50;
        if (stan::math::logical_eq(flip, 1)) {
          current_statement__ = 48;
          stan::model::assign(psi, psi_fixed, "assigning variable psi",
            stan::model::index_uni(1));
        }
      }
      current_statement__ = 69;
      if (stan::math::logical_eq(group, 1)) {
        current_statement__ = 66;
        stan::model::assign(mu_alpha,
          stan::math::multiply(
            stan::math::divide(
              stan::math::subtract(mu_alpha_raw, mean_mu_simplexes),
              sd_mu_simplexes), sigma_mu_alpha),
          "assigning variable mu_alpha");
        current_statement__ = 67;
        stan::model::assign(mu_beta,
          stan::math::multiply(
            stan::math::divide(
              stan::math::subtract(mu_beta_raw, mean_mu_simplexes),
              sd_mu_simplexes), sigma_mu_beta), "assigning variable mu_beta");
      }
      current_statement__ = 70;
      stan::model::assign(theta, theta_raw, "assigning variable theta");
      current_statement__ = 125;
      if (stan::math::logical_eq(bam, 1)) {
        current_statement__ = 117;
        stan::model::assign(theta,
          stan::model::rvalue(mean_spos, "mean_spos",
            stan::model::index_uni(L)), "assigning variable theta",
          stan::model::index_uni(L));
        current_statement__ = 118;
        stan::model::assign(theta,
          stan::model::rvalue(mean_spos, "mean_spos",
            stan::model::index_uni(R)), "assigning variable theta",
          stan::model::index_uni(R));
        current_statement__ = 119;
        stan::model::assign(alpha0,
          stan::model::rvalue(alpha_raw, "alpha_raw",
            stan::model::index_omni(), stan::model::index_uni(1)),
          "assigning variable alpha0", stan::model::index_omni(),
          stan::model::index_uni(1));
        current_statement__ = 120;
        stan::model::assign(beta0,
          stan::model::rvalue(beta_raw, "beta_raw",
            stan::model::index_omni(), stan::model::index_uni(1)),
          "assigning variable beta0", stan::model::index_omni(),
          stan::model::index_uni(1));
        current_statement__ = 123;
        for (int n = 1; n <= N_obs; ++n) {
          current_statement__ = 121;
          stan::model::assign(log_lik,
            stan::math::normal_lpdf<false>(
              stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
              (stan::model::rvalue(alpha0, "alpha0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(1)) +
              (stan::model::rvalue(beta0, "beta0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(1)) *
              stan::model::rvalue(theta, "theta",
                stan::model::index_uni(
                  stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
              (stan::math::sqrt(
                 stan::model::rvalue(eta, "eta",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
              *
              stan::model::rvalue(rho, "rho",
                stan::model::index_uni(
                  stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
            "assigning variable log_lik", stan::model::index_uni(n));
        }
      } else {
        current_statement__ = 71;
        stan::model::assign(theta,
          stan::model::rvalue(theta_lr, "theta_lr", stan::model::index_uni(1)),
          "assigning variable theta", stan::model::index_uni(L));
        current_statement__ = 72;
        stan::model::assign(theta,
          stan::model::rvalue(theta_lr, "theta_lr", stan::model::index_uni(2)),
          "assigning variable theta", stan::model::index_uni(R));
        current_statement__ = 79;
        if (stan::math::logical_eq(group, 0)) {
          current_statement__ = 76;
          stan::model::assign(alpha0,
            stan::math::multiply(
              stan::model::rvalue(alpha_raw, "alpha_raw",
                stan::model::index_omni(), stan::model::index_uni(1)),
              stan::model::rvalue(sigma_alpha, "sigma_alpha",
                stan::model::index_uni(1))), "assigning variable alpha0",
            stan::model::index_omni(), stan::model::index_uni(1));
          current_statement__ = 77;
          stan::model::assign(beta0,
            stan::math::exp(
              stan::math::multiply(
                stan::model::rvalue(beta_raw, "beta_raw",
                  stan::model::index_omni(), stan::model::index_uni(1)),
                stan::model::rvalue(sigma_beta, "sigma_beta",
                  stan::model::index_uni(1)))), "assigning variable beta0",
            stan::model::index_omni(), stan::model::index_uni(1));
        } else {
          current_statement__ = 73;
          stan::model::assign(alpha0,
            stan::math::add(
              stan::math::multiply(
                stan::model::rvalue(alpha_raw, "alpha_raw",
                  stan::model::index_omni(), stan::model::index_uni(1)),
                stan::model::rvalue(sigma_alpha, "sigma_alpha",
                  stan::model::index_uni(1))),
              stan::model::rvalue(mu_alpha, "mu_alpha",
                stan::model::index_multi(gg))), "assigning variable alpha0",
            stan::model::index_omni(), stan::model::index_uni(1));
          current_statement__ = 74;
          stan::model::assign(beta0,
            stan::math::exp(
              stan::math::add(
                stan::math::multiply(
                  stan::model::rvalue(beta_raw, "beta_raw",
                    stan::model::index_omni(), stan::model::index_uni(1)),
                  stan::model::rvalue(sigma_beta, "sigma_beta",
                    stan::model::index_uni(1))),
                stan::model::rvalue(mu_beta, "mu_beta",
                  stan::model::index_multi(gg)))),
            "assigning variable beta0", stan::model::index_omni(),
            stan::model::index_uni(1));
        }
        current_statement__ = 88;
        if (stan::math::logical_eq(flip, 1)) {
          current_statement__ = 80;
          stan::model::assign(lambda,
            stan::math::inv_logit(
              stan::math::add(
                stan::model::rvalue(psi, "psi", stan::model::index_uni(1)),
                stan::math::multiply(lambda_raw, static_cast<double>(3)))),
            "assigning variable lambda");
          current_statement__ = 81;
          stan::model::assign(beta0,
            stan::math::minus(
              stan::math::exp(
                stan::math::multiply(
                  stan::model::rvalue(beta_raw, "beta_raw",
                    stan::model::index_omni(), stan::model::index_uni(2)),
                  stan::model::rvalue(sigma_beta, "sigma_beta",
                    stan::model::index_uni(1))))),
            "assigning variable beta0", stan::model::index_omni(),
            stan::model::index_uni(2));
          current_statement__ = 86;
          if (stan::math::logical_eq(group, 0)) {
            current_statement__ = 84;
            stan::model::assign(alpha0,
              stan::math::multiply(
                stan::model::rvalue(alpha_raw, "alpha_raw",
                  stan::model::index_omni(), stan::model::index_uni(2)),
                stan::model::rvalue(sigma_alpha, "sigma_alpha",
                  stan::model::index_uni(1))), "assigning variable alpha0",
              stan::model::index_omni(), stan::model::index_uni(2));
          } else {
            current_statement__ = 82;
            stan::model::assign(alpha0,
              stan::math::add(
                stan::math::multiply(
                  stan::model::rvalue(alpha_raw, "alpha_raw",
                    stan::model::index_omni(), stan::model::index_uni(2)),
                  stan::model::rvalue(sigma_alpha, "sigma_alpha",
                    stan::model::index_uni(1))),
                stan::model::rvalue(mu_alpha, "mu_alpha",
                  stan::model::index_multi(gg))),
              "assigning variable alpha0", stan::model::index_omni(),
              stan::model::index_uni(2));
          }
        }
        current_statement__ = 115;
        if (stan::math::logical_eq(rat, 1)) {
          current_statement__ = 113;
          for (int n = 1; n <= N_obs; ++n) {
            Eigen::Matrix<local_scalar_t__,-1,1> mu0 =
              Eigen::Matrix<local_scalar_t__,-1,1>::Constant(2, DUMMY_VAR__);
            current_statement__ = 105;
            stan::model::assign(mu0,
              (stan::model::rvalue(alpha0, "alpha0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(1)) +
              (stan::model::rvalue(beta0, "beta0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(1)) *
              stan::model::rvalue(theta, "theta",
                stan::model::index_uni(
                  stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
              "assigning variable mu0", stan::model::index_uni(1));
            current_statement__ = 106;
            stan::model::assign(mu0,
              (stan::model::rvalue(alpha0, "alpha0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(2)) +
              (stan::model::rvalue(beta0, "beta0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(2)) *
              stan::model::rvalue(theta, "theta",
                stan::model::index_uni(
                  stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
              "assigning variable mu0", stan::model::index_uni(2));
            current_statement__ = 107;
            stan::model::assign(log_probs,
              ((stan::math::log(
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
              +
              stan::math::log(
                stan::model::rvalue(zeta, "zeta",
                  stan::model::index_uni(
                    stan::model::rvalue(Vi, "Vi",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n)))))))) +
              stan::math::normal_lpdf<false>(
                stan::model::rvalue(Y, "Y", stan::model::index_uni(n)), (((1
                -
                stan::model::rvalue(gamma, "gamma",
                  stan::model::index_uni(
                    stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
                * stan::model::rvalue(mu0, "mu0", stan::model::index_uni(1)))
                +
                (stan::model::rvalue(gamma, "gamma",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                *
                stan::model::rvalue(p, "p", stan::model::index_uni(1),
                  stan::model::index_uni(n)))), tau)),
              "assigning variable log_probs", stan::model::index_uni(1));
            current_statement__ = 108;
            stan::model::assign(log_probs,
              ((stan::math::log(
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
              +
              stan::math::log((1 -
                stan::model::rvalue(zeta, "zeta",
                  stan::model::index_uni(
                    stan::model::rvalue(Vi, "Vi",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n))))))))) +
              stan::math::normal_lpdf<false>(
                stan::model::rvalue(Y, "Y", stan::model::index_uni(n)), (((1
                -
                stan::model::rvalue(gamma, "gamma",
                  stan::model::index_uni(
                    stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
                * stan::model::rvalue(mu0, "mu0", stan::model::index_uni(1)))
                +
                (stan::model::rvalue(gamma, "gamma",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                *
                stan::model::rvalue(p, "p", stan::model::index_uni(2),
                  stan::model::index_uni(n)))), tau)),
              "assigning variable log_probs", stan::model::index_uni(2));
            current_statement__ = 109;
            stan::model::assign(log_probs,
              ((stan::math::log((1 -
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))))
              +
              stan::math::log(
                stan::model::rvalue(zeta, "zeta",
                  stan::model::index_uni(
                    stan::model::rvalue(Vi, "Vi",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n)))))))) +
              stan::math::normal_lpdf<false>(
                stan::model::rvalue(Y, "Y", stan::model::index_uni(n)), (((1
                -
                stan::model::rvalue(gamma, "gamma",
                  stan::model::index_uni(
                    stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
                * stan::model::rvalue(mu0, "mu0", stan::model::index_uni(2)))
                +
                (stan::model::rvalue(gamma, "gamma",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                *
                stan::model::rvalue(p, "p", stan::model::index_uni(1),
                  stan::model::index_uni(n)))), tau)),
              "assigning variable log_probs", stan::model::index_uni(3));
            current_statement__ = 110;
            stan::model::assign(log_probs,
              ((stan::math::log((1 -
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))))
              +
              stan::math::log((1 -
                stan::model::rvalue(zeta, "zeta",
                  stan::model::index_uni(
                    stan::model::rvalue(Vi, "Vi",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n))))))))) +
              stan::math::normal_lpdf<false>(
                stan::model::rvalue(Y, "Y", stan::model::index_uni(n)), (((1
                -
                stan::model::rvalue(gamma, "gamma",
                  stan::model::index_uni(
                    stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
                * stan::model::rvalue(mu0, "mu0", stan::model::index_uni(2)))
                +
                (stan::model::rvalue(gamma, "gamma",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                *
                stan::model::rvalue(p, "p", stan::model::index_uni(2),
                  stan::model::index_uni(n)))), tau)),
              "assigning variable log_probs", stan::model::index_uni(4));
            current_statement__ = 111;
            stan::model::assign(log_lik, stan::math::log_sum_exp(log_probs),
              "assigning variable log_lik", stan::model::index_uni(n));
          }
        } else {
          current_statement__ = 103;
          if (stan::math::logical_eq(het, 0)) {
            current_statement__ = 101;
            for (int n = 1; n <= N_obs; ++n) {
              current_statement__ = 99;
              stan::model::assign(log_lik,
                stan::math::log_mix(
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))),
                  stan::math::normal_lpdf<false>(
                    stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                    (stan::model::rvalue(alpha0, "alpha0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(1)) +
                    (stan::model::rvalue(beta0, "beta0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(1)) *
                    stan::model::rvalue(theta, "theta",
                      stan::model::index_uni(
                        stan::model::rvalue(jj, "jj",
                          stan::model::index_uni(n)))))), tau),
                  stan::math::normal_lpdf<false>(
                    stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                    (stan::model::rvalue(alpha0, "alpha0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(2)) +
                    (stan::model::rvalue(beta0, "beta0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(2)) *
                    stan::model::rvalue(theta, "theta",
                      stan::model::index_uni(
                        stan::model::rvalue(jj, "jj",
                          stan::model::index_uni(n)))))), tau)),
                "assigning variable log_lik", stan::model::index_uni(n));
            }
          } else {
            current_statement__ = 97;
            if (stan::math::logical_eq(flip, 1)) {
              current_statement__ = 95;
              for (int n = 1; n <= N_obs; ++n) {
                current_statement__ = 93;
                stan::model::assign(log_lik,
                  stan::math::log_mix(
                    stan::model::rvalue(lambda, "lambda",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n)))),
                    stan::math::normal_lpdf<false>(
                      stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                      (stan::model::rvalue(alpha0, "alpha0",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))),
                         stan::model::index_uni(1)) +
                      (stan::model::rvalue(beta0, "beta0",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))),
                         stan::model::index_uni(1)) *
                      stan::model::rvalue(theta, "theta",
                        stan::model::index_uni(
                          stan::model::rvalue(jj, "jj",
                            stan::model::index_uni(n)))))),
                      (stan::math::sqrt(
                         stan::model::rvalue(eta, "eta",
                           stan::model::index_uni(
                             stan::model::rvalue(ii, "ii",
                               stan::model::index_uni(n))))) *
                      stan::model::rvalue(rho, "rho",
                        stan::model::index_uni(
                          stan::model::rvalue(jj, "jj",
                            stan::model::index_uni(n)))))),
                    stan::math::normal_lpdf<false>(
                      stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                      (stan::model::rvalue(alpha0, "alpha0",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))),
                         stan::model::index_uni(2)) +
                      (stan::model::rvalue(beta0, "beta0",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))),
                         stan::model::index_uni(2)) *
                      stan::model::rvalue(theta, "theta",
                        stan::model::index_uni(
                          stan::model::rvalue(jj, "jj",
                            stan::model::index_uni(n)))))),
                      (stan::math::sqrt(
                         stan::model::rvalue(eta, "eta",
                           stan::model::index_uni(
                             stan::model::rvalue(ii, "ii",
                               stan::model::index_uni(n))))) *
                      stan::model::rvalue(rho, "rho",
                        stan::model::index_uni(
                          stan::model::rvalue(jj, "jj",
                            stan::model::index_uni(n))))))),
                  "assigning variable log_lik", stan::model::index_uni(n));
              }
            } else {
              current_statement__ = 91;
              for (int n = 1; n <= N_obs; ++n) {
                current_statement__ = 89;
                stan::model::assign(log_lik,
                  stan::math::normal_lpdf<false>(
                    stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                    (stan::model::rvalue(alpha0, "alpha0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(1)) +
                    (stan::model::rvalue(beta0, "beta0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(1)) *
                    stan::model::rvalue(theta, "theta",
                      stan::model::index_uni(
                        stan::model::rvalue(jj, "jj",
                          stan::model::index_uni(n)))))),
                    (stan::math::sqrt(
                       stan::model::rvalue(eta, "eta",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))))) *
                    stan::model::rvalue(rho, "rho",
                      stan::model::index_uni(
                        stan::model::rvalue(jj, "jj",
                          stan::model::index_uni(n)))))),
                  "assigning variable log_lik", stan::model::index_uni(n));
              }
            }
          }
        }
      }
      current_statement__ = 24;
      stan::math::check_greater_or_equal(function__, "lambda", lambda, 0);
      current_statement__ = 24;
      stan::math::check_less_or_equal(function__, "lambda", lambda, 1);
      current_statement__ = 27;
      stan::math::check_greater_or_equal(function__, "eta_scale", eta_scale,
        0);
      current_statement__ = 28;
      stan::math::check_greater_or_equal(function__, "sigma_alpha",
        sigma_alpha, 0);
      current_statement__ = 29;
      stan::math::check_greater_or_equal(function__, "sigma_beta",
        sigma_beta, 0);
      current_statement__ = 29;
      stan::math::check_less_or_equal(function__, "sigma_beta", sigma_beta, 2);
      current_statement__ = 30;
      stan::math::check_greater_or_equal(function__, "nu", nu, 3);
      current_statement__ = 30;
      stan::math::check_less_or_equal(function__, "nu", nu, 30);
      current_statement__ = 31;
      stan::math::check_greater_or_equal(function__, "tau", tau, 0);
      current_statement__ = 32;
      stan::math::check_greater_or_equal(function__, "psi", psi, 0);
      {
        current_statement__ = 155;
        lp_accum__.add(stan::math::normal_lpdf<propto__>(theta_raw,
                         static_cast<double>(0), (B / 2.0)));
        current_statement__ = 165;
        if (stan::math::logical_eq(bam, 1)) {
          current_statement__ = 162;
          lp_accum__.add(stan::math::uniform_lpdf<propto__>(
                           stan::model::rvalue(alpha_raw, "alpha_raw",
                             stan::model::index_omni(),
                             stan::model::index_uni(1)),
                           static_cast<double>(-(100)),
                           static_cast<double>(100)));
          current_statement__ = 163;
          lp_accum__.add(stan::math::uniform_lpdf<propto__>(
                           stan::model::rvalue(beta_raw, "beta_raw",
                             stan::model::index_omni(),
                             stan::model::index_uni(1)),
                           static_cast<double>(-(100)),
                           static_cast<double>(100)));
        } else {
          current_statement__ = 156;
          lp_accum__.add(stan::math::normal_lpdf<propto__>(theta_lr,
                           static_cast<double>(0), (B / 2.0)));
          current_statement__ = 157;
          lp_accum__.add(stan::math::normal_lpdf<propto__>(
                           stan::model::rvalue(alpha_raw, "alpha_raw",
                             stan::model::index_omni(),
                             stan::model::index_uni(1)),
                           static_cast<double>(0), static_cast<double>(1)));
          current_statement__ = 158;
          lp_accum__.add(stan::math::gamma_lpdf<propto__>(sigma_alpha_par,
                           static_cast<double>(5), sigma_alpha_prior_rate));
          current_statement__ = 159;
          lp_accum__.add(stan::math::normal_lpdf<propto__>(
                           stan::model::rvalue(beta_raw, "beta_raw",
                             stan::model::index_omni(),
                             stan::model::index_uni(1)),
                           static_cast<double>(0), static_cast<double>(1)));
          current_statement__ = 160;
          lp_accum__.add(stan::math::gamma_lpdf<propto__>(sigma_beta_par,
                           static_cast<double>(9), static_cast<double>(40)));
        }
        current_statement__ = 172;
        if (stan::math::logical_eq(group, 1)) {
          current_statement__ = 169;
          lp_accum__.add(stan::math::dirichlet_lpdf<propto__>(mu_alpha_raw,
                           stan::math::rep_vector(static_cast<double>(50), G)));
          current_statement__ = 170;
          lp_accum__.add(stan::math::dirichlet_lpdf<propto__>(mu_beta_raw,
                           stan::math::rep_vector(static_cast<double>(50), G)));
        } else {
          current_statement__ = 166;
          lp_accum__.add(stan::math::dirichlet_lpdf<propto__>(mu_alpha_raw,
                           stan::math::rep_vector(static_cast<double>(50), 1)));
          current_statement__ = 167;
          lp_accum__.add(stan::math::dirichlet_lpdf<propto__>(mu_beta_raw,
                           stan::math::rep_vector(static_cast<double>(50), 1)));
        }
        current_statement__ = 178;
        if (stan::math::logical_eq(flip, 1)) {
          current_statement__ = 173;
          lp_accum__.add(stan::math::normal_lpdf<propto__>(
                           stan::model::rvalue(alpha_raw, "alpha_raw",
                             stan::model::index_omni(),
                             stan::model::index_uni(2)),
                           static_cast<double>(0), static_cast<double>(1)));
          current_statement__ = 174;
          lp_accum__.add(stan::math::normal_lpdf<propto__>(
                           stan::model::rvalue(beta_raw, "beta_raw",
                             stan::model::index_omni(),
                             stan::model::index_uni(2)),
                           static_cast<double>(0), static_cast<double>(1)));
          current_statement__ = 175;
          lp_accum__.add(stan::math::normal_lpdf<propto__>(lambda_raw,
                           static_cast<double>(0), static_cast<double>(1)));
          current_statement__ = 176;
          lp_accum__.add(stan::math::lognormal_lpdf<propto__>(psi_par, 1.4,
                           .5));
        }
        current_statement__ = 184;
        if (stan::math::logical_eq(rat, 1)) {
          current_statement__ = 179;
          lp_accum__.add(stan::math::beta_lpdf<propto__>(gamma,
                           stan::model::rvalue(gam_a, "gam_a",
                             stan::model::index_uni(1)),
                           stan::model::rvalue(gam_b, "gam_b",
                             stan::model::index_uni(1))));
          current_statement__ = 180;
          lp_accum__.add(stan::math::gamma_lpdf<propto__>(gam_a, 1.5, .5));
          current_statement__ = 181;
          lp_accum__.add(stan::math::gamma_lpdf<propto__>(gam_b, 1.5, .5));
          current_statement__ = 182;
          lp_accum__.add(stan::math::beta_lpdf<propto__>(zeta, 1.2, 1.2));
        }
        current_statement__ = 191;
        if (stan::math::logical_eq(het, 1)) {
          current_statement__ = 187;
          lp_accum__.add(stan::math::scaled_inv_chi_square_lpdf<propto__>(
                           eta,
                           stan::model::rvalue(nu, "nu",
                             stan::model::index_uni(1)),
                           stan::model::rvalue(eta_scale, "eta_scale",
                             stan::model::index_uni(1))));
          current_statement__ = 188;
          lp_accum__.add(stan::math::gamma_lpdf<propto__>(nu_par,
                           static_cast<double>(25), 2.5));
          current_statement__ = 189;
          lp_accum__.add(stan::math::dirichlet_lpdf<propto__>(rho,
                           stan::math::rep_vector(static_cast<double>(50), J)));
        } else {
          current_statement__ = 185;
          lp_accum__.add(stan::math::dirichlet_lpdf<propto__>(rho,
                           stan::math::rep_vector(static_cast<double>(50), 1)));
        }
        current_statement__ = 192;
        lp_accum__.add(stan::math::gamma_lpdf<propto__>(tau_par,
                         static_cast<double>(2), tau_prior_rate));
        current_statement__ = 195;
        if (stan::math::logical_eq(CV, 0)) {
          current_statement__ = 194;
          lp_accum__.add(stan::math::sum(log_lik));
        } else {
          current_statement__ = 193;
          lp_accum__.add(stan::math::sum(
                           stan::math::elt_multiply(log_lik, not_holdout)));
        }
      }
    } 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__ =
      "model_omni_namespace::write_array";
    // suppress unused var warning
    (void) function__;
    try {
      current_statement__ = 1;
      auto alpha_raw =
        in__.template read<Eigen::Matrix<local_scalar_t__,-1,-1>>(N,
          alpha_raw_2dim__);
      current_statement__ = 2;
      auto beta_raw =
        in__.template read<Eigen::Matrix<local_scalar_t__,-1,-1>>(N,
          beta_raw_2dim__);
      current_statement__ = 3;
      auto theta_lr =
        in__.template read_constrain_ordered<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
          theta_lr_1dim__);
      current_statement__ = 4;
      auto theta_raw = in__.template read<std::vector<local_scalar_t__>>(J);
      current_statement__ = 5;
      auto mu_alpha_raw =
        in__.template read_constrain_simplex<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
          mu_alpha_raw_1dim__);
      current_statement__ = 6;
      auto mu_beta_raw =
        in__.template read_constrain_simplex<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
          mu_beta_raw_1dim__);
      current_statement__ = 7;
      auto sigma_alpha_par =
        in__.template read_constrain_lb<std::vector<local_scalar_t__>,
          jacobian__>(0, lp__, sigma_alpha_par_1dim__);
      current_statement__ = 8;
      auto sigma_beta_par =
        in__.template read_constrain_lub<std::vector<local_scalar_t__>,
          jacobian__>(0, 2, lp__, sigma_beta_par_1dim__);
      current_statement__ = 9;
      auto nu_par =
        in__.template read_constrain_lub<std::vector<local_scalar_t__>,
          jacobian__>(3, 30, lp__, nu_par_1dim__);
      current_statement__ = 10;
      auto tau_par =
        in__.template read_constrain_offset_multiplier<
          std::vector<local_scalar_t__>, jacobian__>(0, tau_multip, lp__,
          tau_par_1dim__);
      current_statement__ = 11;
      auto eta =
        in__.template read_constrain_lb<Eigen::Matrix<local_scalar_t__,-1,1>,
          jacobian__>(0, lp__, eta_1dim__);
      current_statement__ = 12;
      auto rho =
        in__.template read_constrain_simplex<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__, rho_1dim__);
      current_statement__ = 13;
      auto lambda_raw =
        in__.template read<
          Eigen::Matrix<local_scalar_t__,-1,1>>(lambda_raw_1dim__);
      current_statement__ = 14;
      auto psi_par =
        in__.template read_constrain_lb<std::vector<local_scalar_t__>,
          jacobian__>(0, lp__, psi_par_1dim__);
      current_statement__ = 15;
      auto gamma =
        in__.template read_constrain_lub<std::vector<local_scalar_t__>,
          jacobian__>(0, 1, lp__, gamma_1dim__);
      current_statement__ = 16;
      auto gam_a =
        in__.template read_constrain_lb<std::vector<local_scalar_t__>,
          jacobian__>(1, lp__, rat);
      current_statement__ = 17;
      auto gam_b =
        in__.template read_constrain_lb<std::vector<local_scalar_t__>,
          jacobian__>(1, lp__, rat);
      current_statement__ = 18;
      auto zeta =
        in__.template read_constrain_lub<
          Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0, 1, lp__,
          zeta_1dim__);
      Eigen::Matrix<double,-1,1> log_probs =
        Eigen::Matrix<double,-1,1>::Constant(log_probs_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      std::vector<double> theta =
        std::vector<double>(J, std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,-1> alpha0 =
        Eigen::Matrix<double,-1,-1>::Constant(N, alpha0_2dim__,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,-1> beta0 =
        Eigen::Matrix<double,-1,-1>::Constant(N, beta0_2dim__,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> log_lik =
        Eigen::Matrix<double,-1,1>::Constant(N_obs,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> lambda =
        Eigen::Matrix<double,-1,1>::Constant(lambda_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> mu_alpha =
        Eigen::Matrix<double,-1,1>::Constant(mu_alpha_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> mu_beta =
        Eigen::Matrix<double,-1,1>::Constant(mu_beta_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      std::vector<double> eta_scale =
        std::vector<double>(het, std::numeric_limits<double>::quiet_NaN());
      std::vector<double> sigma_alpha =
        std::vector<double>(sigma_alpha_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      std::vector<double> sigma_beta =
        std::vector<double>(sigma_beta_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      std::vector<double> nu =
        std::vector<double>(het, std::numeric_limits<double>::quiet_NaN());
      double tau = std::numeric_limits<double>::quiet_NaN();
      std::vector<double> psi =
        std::vector<double>(flip, std::numeric_limits<double>::quiet_NaN());
      out__.write(alpha_raw);
      out__.write(beta_raw);
      out__.write(theta_lr);
      out__.write(theta_raw);
      out__.write(mu_alpha_raw);
      out__.write(mu_beta_raw);
      out__.write(sigma_alpha_par);
      out__.write(sigma_beta_par);
      out__.write(nu_par);
      out__.write(tau_par);
      out__.write(eta);
      out__.write(rho);
      out__.write(lambda_raw);
      out__.write(psi_par);
      out__.write(gamma);
      out__.write(gam_a);
      out__.write(gam_b);
      out__.write(zeta);
      if (stan::math::logical_negation(
            (stan::math::primitive_value(emit_transformed_parameters__) ||
            stan::math::primitive_value(emit_generated_quantities__)))) {
        return ;
      }
      current_statement__ = 65;
      if (stan::math::logical_eq(fixed, 0)) {
        current_statement__ = 52;
        tau = stan::model::rvalue(tau_par, "tau_par",
                stan::model::index_uni(1));
        current_statement__ = 56;
        if (stan::math::logical_eq(bam, 0)) {
          current_statement__ = 53;
          stan::model::assign(sigma_alpha, sigma_alpha_par,
            "assigning variable sigma_alpha");
          current_statement__ = 54;
          stan::model::assign(sigma_beta, sigma_beta_par,
            "assigning variable sigma_beta");
        }
        current_statement__ = 60;
        if (stan::math::logical_eq(het, 1)) {
          current_statement__ = 57;
          stan::model::assign(nu, nu_par, "assigning variable nu");
          current_statement__ = 58;
          stan::model::assign(eta_scale, (tau * J),
            "assigning variable eta_scale", stan::model::index_uni(1));
        }
        current_statement__ = 63;
        if (stan::math::logical_eq(flip, 1)) {
          current_statement__ = 61;
          stan::model::assign(psi, psi_par, "assigning variable psi");
        }
      } else {
        current_statement__ = 39;
        tau = tau_fixed;
        current_statement__ = 43;
        if (stan::math::logical_eq(bam, 0)) {
          current_statement__ = 40;
          stan::model::assign(sigma_alpha, sigma_alpha_fixed,
            "assigning variable sigma_alpha", stan::model::index_uni(1));
          current_statement__ = 41;
          stan::model::assign(sigma_beta, sigma_beta_fixed,
            "assigning variable sigma_beta", stan::model::index_uni(1));
        }
        current_statement__ = 47;
        if (stan::math::logical_eq(het, 1)) {
          current_statement__ = 44;
          stan::model::assign(nu, nu_fixed, "assigning variable nu",
            stan::model::index_uni(1));
          current_statement__ = 45;
          stan::model::assign(eta_scale, (tau * J),
            "assigning variable eta_scale", stan::model::index_uni(1));
        }
        current_statement__ = 50;
        if (stan::math::logical_eq(flip, 1)) {
          current_statement__ = 48;
          stan::model::assign(psi, psi_fixed, "assigning variable psi",
            stan::model::index_uni(1));
        }
      }
      current_statement__ = 69;
      if (stan::math::logical_eq(group, 1)) {
        current_statement__ = 66;
        stan::model::assign(mu_alpha,
          stan::math::multiply(
            stan::math::divide(
              stan::math::subtract(mu_alpha_raw, mean_mu_simplexes),
              sd_mu_simplexes), sigma_mu_alpha),
          "assigning variable mu_alpha");
        current_statement__ = 67;
        stan::model::assign(mu_beta,
          stan::math::multiply(
            stan::math::divide(
              stan::math::subtract(mu_beta_raw, mean_mu_simplexes),
              sd_mu_simplexes), sigma_mu_beta), "assigning variable mu_beta");
      }
      current_statement__ = 70;
      stan::model::assign(theta, theta_raw, "assigning variable theta");
      current_statement__ = 125;
      if (stan::math::logical_eq(bam, 1)) {
        current_statement__ = 117;
        stan::model::assign(theta,
          stan::model::rvalue(mean_spos, "mean_spos",
            stan::model::index_uni(L)), "assigning variable theta",
          stan::model::index_uni(L));
        current_statement__ = 118;
        stan::model::assign(theta,
          stan::model::rvalue(mean_spos, "mean_spos",
            stan::model::index_uni(R)), "assigning variable theta",
          stan::model::index_uni(R));
        current_statement__ = 119;
        stan::model::assign(alpha0,
          stan::model::rvalue(alpha_raw, "alpha_raw",
            stan::model::index_omni(), stan::model::index_uni(1)),
          "assigning variable alpha0", stan::model::index_omni(),
          stan::model::index_uni(1));
        current_statement__ = 120;
        stan::model::assign(beta0,
          stan::model::rvalue(beta_raw, "beta_raw",
            stan::model::index_omni(), stan::model::index_uni(1)),
          "assigning variable beta0", stan::model::index_omni(),
          stan::model::index_uni(1));
        current_statement__ = 123;
        for (int n = 1; n <= N_obs; ++n) {
          current_statement__ = 121;
          stan::model::assign(log_lik,
            stan::math::normal_lpdf<false>(
              stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
              (stan::model::rvalue(alpha0, "alpha0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(1)) +
              (stan::model::rvalue(beta0, "beta0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(1)) *
              stan::model::rvalue(theta, "theta",
                stan::model::index_uni(
                  stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
              (stan::math::sqrt(
                 stan::model::rvalue(eta, "eta",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
              *
              stan::model::rvalue(rho, "rho",
                stan::model::index_uni(
                  stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
            "assigning variable log_lik", stan::model::index_uni(n));
        }
      } else {
        current_statement__ = 71;
        stan::model::assign(theta,
          stan::model::rvalue(theta_lr, "theta_lr", stan::model::index_uni(1)),
          "assigning variable theta", stan::model::index_uni(L));
        current_statement__ = 72;
        stan::model::assign(theta,
          stan::model::rvalue(theta_lr, "theta_lr", stan::model::index_uni(2)),
          "assigning variable theta", stan::model::index_uni(R));
        current_statement__ = 79;
        if (stan::math::logical_eq(group, 0)) {
          current_statement__ = 76;
          stan::model::assign(alpha0,
            stan::math::multiply(
              stan::model::rvalue(alpha_raw, "alpha_raw",
                stan::model::index_omni(), stan::model::index_uni(1)),
              stan::model::rvalue(sigma_alpha, "sigma_alpha",
                stan::model::index_uni(1))), "assigning variable alpha0",
            stan::model::index_omni(), stan::model::index_uni(1));
          current_statement__ = 77;
          stan::model::assign(beta0,
            stan::math::exp(
              stan::math::multiply(
                stan::model::rvalue(beta_raw, "beta_raw",
                  stan::model::index_omni(), stan::model::index_uni(1)),
                stan::model::rvalue(sigma_beta, "sigma_beta",
                  stan::model::index_uni(1)))), "assigning variable beta0",
            stan::model::index_omni(), stan::model::index_uni(1));
        } else {
          current_statement__ = 73;
          stan::model::assign(alpha0,
            stan::math::add(
              stan::math::multiply(
                stan::model::rvalue(alpha_raw, "alpha_raw",
                  stan::model::index_omni(), stan::model::index_uni(1)),
                stan::model::rvalue(sigma_alpha, "sigma_alpha",
                  stan::model::index_uni(1))),
              stan::model::rvalue(mu_alpha, "mu_alpha",
                stan::model::index_multi(gg))), "assigning variable alpha0",
            stan::model::index_omni(), stan::model::index_uni(1));
          current_statement__ = 74;
          stan::model::assign(beta0,
            stan::math::exp(
              stan::math::add(
                stan::math::multiply(
                  stan::model::rvalue(beta_raw, "beta_raw",
                    stan::model::index_omni(), stan::model::index_uni(1)),
                  stan::model::rvalue(sigma_beta, "sigma_beta",
                    stan::model::index_uni(1))),
                stan::model::rvalue(mu_beta, "mu_beta",
                  stan::model::index_multi(gg)))),
            "assigning variable beta0", stan::model::index_omni(),
            stan::model::index_uni(1));
        }
        current_statement__ = 88;
        if (stan::math::logical_eq(flip, 1)) {
          current_statement__ = 80;
          stan::model::assign(lambda,
            stan::math::inv_logit(
              stan::math::add(
                stan::model::rvalue(psi, "psi", stan::model::index_uni(1)),
                stan::math::multiply(lambda_raw, static_cast<double>(3)))),
            "assigning variable lambda");
          current_statement__ = 81;
          stan::model::assign(beta0,
            stan::math::minus(
              stan::math::exp(
                stan::math::multiply(
                  stan::model::rvalue(beta_raw, "beta_raw",
                    stan::model::index_omni(), stan::model::index_uni(2)),
                  stan::model::rvalue(sigma_beta, "sigma_beta",
                    stan::model::index_uni(1))))),
            "assigning variable beta0", stan::model::index_omni(),
            stan::model::index_uni(2));
          current_statement__ = 86;
          if (stan::math::logical_eq(group, 0)) {
            current_statement__ = 84;
            stan::model::assign(alpha0,
              stan::math::multiply(
                stan::model::rvalue(alpha_raw, "alpha_raw",
                  stan::model::index_omni(), stan::model::index_uni(2)),
                stan::model::rvalue(sigma_alpha, "sigma_alpha",
                  stan::model::index_uni(1))), "assigning variable alpha0",
              stan::model::index_omni(), stan::model::index_uni(2));
          } else {
            current_statement__ = 82;
            stan::model::assign(alpha0,
              stan::math::add(
                stan::math::multiply(
                  stan::model::rvalue(alpha_raw, "alpha_raw",
                    stan::model::index_omni(), stan::model::index_uni(2)),
                  stan::model::rvalue(sigma_alpha, "sigma_alpha",
                    stan::model::index_uni(1))),
                stan::model::rvalue(mu_alpha, "mu_alpha",
                  stan::model::index_multi(gg))),
              "assigning variable alpha0", stan::model::index_omni(),
              stan::model::index_uni(2));
          }
        }
        current_statement__ = 115;
        if (stan::math::logical_eq(rat, 1)) {
          current_statement__ = 113;
          for (int n = 1; n <= N_obs; ++n) {
            Eigen::Matrix<double,-1,1> mu0 =
              Eigen::Matrix<double,-1,1>::Constant(2,
                std::numeric_limits<double>::quiet_NaN());
            current_statement__ = 105;
            stan::model::assign(mu0,
              (stan::model::rvalue(alpha0, "alpha0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(1)) +
              (stan::model::rvalue(beta0, "beta0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(1)) *
              stan::model::rvalue(theta, "theta",
                stan::model::index_uni(
                  stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
              "assigning variable mu0", stan::model::index_uni(1));
            current_statement__ = 106;
            stan::model::assign(mu0,
              (stan::model::rvalue(alpha0, "alpha0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(2)) +
              (stan::model::rvalue(beta0, "beta0",
                 stan::model::index_uni(
                   stan::model::rvalue(ii, "ii", stan::model::index_uni(n))),
                 stan::model::index_uni(2)) *
              stan::model::rvalue(theta, "theta",
                stan::model::index_uni(
                  stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
              "assigning variable mu0", stan::model::index_uni(2));
            current_statement__ = 107;
            stan::model::assign(log_probs,
              ((stan::math::log(
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
              +
              stan::math::log(
                stan::model::rvalue(zeta, "zeta",
                  stan::model::index_uni(
                    stan::model::rvalue(Vi, "Vi",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n)))))))) +
              stan::math::normal_lpdf<false>(
                stan::model::rvalue(Y, "Y", stan::model::index_uni(n)), (((1
                -
                stan::model::rvalue(gamma, "gamma",
                  stan::model::index_uni(
                    stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
                * stan::model::rvalue(mu0, "mu0", stan::model::index_uni(1)))
                +
                (stan::model::rvalue(gamma, "gamma",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                *
                stan::model::rvalue(p, "p", stan::model::index_uni(1),
                  stan::model::index_uni(n)))), tau)),
              "assigning variable log_probs", stan::model::index_uni(1));
            current_statement__ = 108;
            stan::model::assign(log_probs,
              ((stan::math::log(
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
              +
              stan::math::log((1 -
                stan::model::rvalue(zeta, "zeta",
                  stan::model::index_uni(
                    stan::model::rvalue(Vi, "Vi",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n))))))))) +
              stan::math::normal_lpdf<false>(
                stan::model::rvalue(Y, "Y", stan::model::index_uni(n)), (((1
                -
                stan::model::rvalue(gamma, "gamma",
                  stan::model::index_uni(
                    stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
                * stan::model::rvalue(mu0, "mu0", stan::model::index_uni(1)))
                +
                (stan::model::rvalue(gamma, "gamma",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                *
                stan::model::rvalue(p, "p", stan::model::index_uni(2),
                  stan::model::index_uni(n)))), tau)),
              "assigning variable log_probs", stan::model::index_uni(2));
            current_statement__ = 109;
            stan::model::assign(log_probs,
              ((stan::math::log((1 -
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))))
              +
              stan::math::log(
                stan::model::rvalue(zeta, "zeta",
                  stan::model::index_uni(
                    stan::model::rvalue(Vi, "Vi",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n)))))))) +
              stan::math::normal_lpdf<false>(
                stan::model::rvalue(Y, "Y", stan::model::index_uni(n)), (((1
                -
                stan::model::rvalue(gamma, "gamma",
                  stan::model::index_uni(
                    stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
                * stan::model::rvalue(mu0, "mu0", stan::model::index_uni(2)))
                +
                (stan::model::rvalue(gamma, "gamma",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                *
                stan::model::rvalue(p, "p", stan::model::index_uni(1),
                  stan::model::index_uni(n)))), tau)),
              "assigning variable log_probs", stan::model::index_uni(3));
            current_statement__ = 110;
            stan::model::assign(log_probs,
              ((stan::math::log((1 -
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))))
              +
              stan::math::log((1 -
                stan::model::rvalue(zeta, "zeta",
                  stan::model::index_uni(
                    stan::model::rvalue(Vi, "Vi",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n))))))))) +
              stan::math::normal_lpdf<false>(
                stan::model::rvalue(Y, "Y", stan::model::index_uni(n)), (((1
                -
                stan::model::rvalue(gamma, "gamma",
                  stan::model::index_uni(
                    stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))))
                * stan::model::rvalue(mu0, "mu0", stan::model::index_uni(2)))
                +
                (stan::model::rvalue(gamma, "gamma",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                *
                stan::model::rvalue(p, "p", stan::model::index_uni(2),
                  stan::model::index_uni(n)))), tau)),
              "assigning variable log_probs", stan::model::index_uni(4));
            current_statement__ = 111;
            stan::model::assign(log_lik, stan::math::log_sum_exp(log_probs),
              "assigning variable log_lik", stan::model::index_uni(n));
          }
        } else {
          current_statement__ = 103;
          if (stan::math::logical_eq(het, 0)) {
            current_statement__ = 101;
            for (int n = 1; n <= N_obs; ++n) {
              current_statement__ = 99;
              stan::model::assign(log_lik,
                stan::math::log_mix(
                  stan::model::rvalue(lambda, "lambda",
                    stan::model::index_uni(
                      stan::model::rvalue(ii, "ii", stan::model::index_uni(n)))),
                  stan::math::normal_lpdf<false>(
                    stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                    (stan::model::rvalue(alpha0, "alpha0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(1)) +
                    (stan::model::rvalue(beta0, "beta0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(1)) *
                    stan::model::rvalue(theta, "theta",
                      stan::model::index_uni(
                        stan::model::rvalue(jj, "jj",
                          stan::model::index_uni(n)))))), tau),
                  stan::math::normal_lpdf<false>(
                    stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                    (stan::model::rvalue(alpha0, "alpha0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(2)) +
                    (stan::model::rvalue(beta0, "beta0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(2)) *
                    stan::model::rvalue(theta, "theta",
                      stan::model::index_uni(
                        stan::model::rvalue(jj, "jj",
                          stan::model::index_uni(n)))))), tau)),
                "assigning variable log_lik", stan::model::index_uni(n));
            }
          } else {
            current_statement__ = 97;
            if (stan::math::logical_eq(flip, 1)) {
              current_statement__ = 95;
              for (int n = 1; n <= N_obs; ++n) {
                current_statement__ = 93;
                stan::model::assign(log_lik,
                  stan::math::log_mix(
                    stan::model::rvalue(lambda, "lambda",
                      stan::model::index_uni(
                        stan::model::rvalue(ii, "ii",
                          stan::model::index_uni(n)))),
                    stan::math::normal_lpdf<false>(
                      stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                      (stan::model::rvalue(alpha0, "alpha0",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))),
                         stan::model::index_uni(1)) +
                      (stan::model::rvalue(beta0, "beta0",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))),
                         stan::model::index_uni(1)) *
                      stan::model::rvalue(theta, "theta",
                        stan::model::index_uni(
                          stan::model::rvalue(jj, "jj",
                            stan::model::index_uni(n)))))),
                      (stan::math::sqrt(
                         stan::model::rvalue(eta, "eta",
                           stan::model::index_uni(
                             stan::model::rvalue(ii, "ii",
                               stan::model::index_uni(n))))) *
                      stan::model::rvalue(rho, "rho",
                        stan::model::index_uni(
                          stan::model::rvalue(jj, "jj",
                            stan::model::index_uni(n)))))),
                    stan::math::normal_lpdf<false>(
                      stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                      (stan::model::rvalue(alpha0, "alpha0",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))),
                         stan::model::index_uni(2)) +
                      (stan::model::rvalue(beta0, "beta0",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))),
                         stan::model::index_uni(2)) *
                      stan::model::rvalue(theta, "theta",
                        stan::model::index_uni(
                          stan::model::rvalue(jj, "jj",
                            stan::model::index_uni(n)))))),
                      (stan::math::sqrt(
                         stan::model::rvalue(eta, "eta",
                           stan::model::index_uni(
                             stan::model::rvalue(ii, "ii",
                               stan::model::index_uni(n))))) *
                      stan::model::rvalue(rho, "rho",
                        stan::model::index_uni(
                          stan::model::rvalue(jj, "jj",
                            stan::model::index_uni(n))))))),
                  "assigning variable log_lik", stan::model::index_uni(n));
              }
            } else {
              current_statement__ = 91;
              for (int n = 1; n <= N_obs; ++n) {
                current_statement__ = 89;
                stan::model::assign(log_lik,
                  stan::math::normal_lpdf<false>(
                    stan::model::rvalue(Y, "Y", stan::model::index_uni(n)),
                    (stan::model::rvalue(alpha0, "alpha0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(1)) +
                    (stan::model::rvalue(beta0, "beta0",
                       stan::model::index_uni(
                         stan::model::rvalue(ii, "ii",
                           stan::model::index_uni(n))),
                       stan::model::index_uni(1)) *
                    stan::model::rvalue(theta, "theta",
                      stan::model::index_uni(
                        stan::model::rvalue(jj, "jj",
                          stan::model::index_uni(n)))))),
                    (stan::math::sqrt(
                       stan::model::rvalue(eta, "eta",
                         stan::model::index_uni(
                           stan::model::rvalue(ii, "ii",
                             stan::model::index_uni(n))))) *
                    stan::model::rvalue(rho, "rho",
                      stan::model::index_uni(
                        stan::model::rvalue(jj, "jj",
                          stan::model::index_uni(n)))))),
                  "assigning variable log_lik", stan::model::index_uni(n));
              }
            }
          }
        }
      }
      current_statement__ = 24;
      stan::math::check_greater_or_equal(function__, "lambda", lambda, 0);
      current_statement__ = 24;
      stan::math::check_less_or_equal(function__, "lambda", lambda, 1);
      current_statement__ = 27;
      stan::math::check_greater_or_equal(function__, "eta_scale", eta_scale,
        0);
      current_statement__ = 28;
      stan::math::check_greater_or_equal(function__, "sigma_alpha",
        sigma_alpha, 0);
      current_statement__ = 29;
      stan::math::check_greater_or_equal(function__, "sigma_beta",
        sigma_beta, 0);
      current_statement__ = 29;
      stan::math::check_less_or_equal(function__, "sigma_beta", sigma_beta, 2);
      current_statement__ = 30;
      stan::math::check_greater_or_equal(function__, "nu", nu, 3);
      current_statement__ = 30;
      stan::math::check_less_or_equal(function__, "nu", nu, 30);
      current_statement__ = 31;
      stan::math::check_greater_or_equal(function__, "tau", tau, 0);
      current_statement__ = 32;
      stan::math::check_greater_or_equal(function__, "psi", psi, 0);
      if (emit_transformed_parameters__) {
        out__.write(log_probs);
        out__.write(theta);
        out__.write(alpha0);
        out__.write(beta0);
        out__.write(log_lik);
        out__.write(lambda);
        out__.write(mu_alpha);
        out__.write(mu_beta);
        out__.write(eta_scale);
        out__.write(sigma_alpha);
        out__.write(sigma_beta);
        out__.write(nu);
        out__.write(tau);
        out__.write(psi);
      }
      if (stan::math::logical_negation(emit_generated_quantities__)) {
        return ;
      }
      double min_rho = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 33;
      min_rho = stan::math::min(rho);
      Eigen::Matrix<double,-1,1> kappa =
        Eigen::Matrix<double,-1,1>::Constant(kappa_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> alpha =
        Eigen::Matrix<double,-1,1>::Constant(N,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> beta =
        Eigen::Matrix<double,-1,1>::Constant(N,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> chi =
        Eigen::Matrix<double,-1,1>::Constant(N,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> Y_pred =
        Eigen::Matrix<double,-1,1>::Constant(Y_pred_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 135;
      if (stan::math::logical_eq(flip, 1)) {
        current_statement__ = 131;
        if (stan::math::logical_eq(MCMC, 1)) {
          current_statement__ = 130;
          stan::model::assign(kappa,
            stan::math::to_vector(
              stan::math::bernoulli_rng(lambda, base_rng__)),
            "assigning variable kappa");
        } else {
          current_statement__ = 129;
          stan::model::assign(kappa,
            stan::math::to_vector(stan::math::round(lambda)),
            "assigning variable kappa");
        }
        current_statement__ = 132;
        stan::model::assign(alpha,
          stan::math::add(
            stan::math::elt_multiply(kappa,
              stan::model::rvalue(alpha0, "alpha0",
                stan::model::index_omni(), stan::model::index_uni(1))),
            stan::math::elt_multiply(
              stan::math::subtract(static_cast<double>(1), kappa),
              stan::model::rvalue(alpha0, "alpha0",
                stan::model::index_omni(), stan::model::index_uni(2)))),
          "assigning variable alpha");
        current_statement__ = 133;
        stan::model::assign(beta,
          stan::math::add(
            stan::math::elt_multiply(kappa,
              stan::model::rvalue(beta0, "beta0", stan::model::index_omni(),
                stan::model::index_uni(1))),
            stan::math::elt_multiply(
              stan::math::subtract(static_cast<double>(1), kappa),
              stan::model::rvalue(beta0, "beta0", stan::model::index_omni(),
                stan::model::index_uni(2)))), "assigning variable beta");
      } else {
        current_statement__ = 126;
        stan::model::assign(alpha,
          stan::model::rvalue(alpha0, "alpha0", stan::model::index_omni(),
            stan::model::index_uni(1)), "assigning variable alpha");
        current_statement__ = 127;
        stan::model::assign(beta,
          stan::model::rvalue(beta0, "beta0", stan::model::index_omni(),
            stan::model::index_uni(1)), "assigning variable beta");
      }
      current_statement__ = 154;
      if (stan::math::logical_eq(het, 1)) {
        current_statement__ = 152;
        if (stan::math::logical_eq(MCMC, 1)) {
          current_statement__ = 148;
          stan::model::assign(chi,
            stan::math::elt_divide(
              stan::math::subtract(
                stan::math::subtract(stan::math::to_vector(V),
                  stan::math::to_vector(
                    stan::math::normal_rng(0,
                      stan::math::multiply(stan::math::sqrt(eta), min_rho),
                      base_rng__))), alpha), beta), "assigning variable chi");
          current_statement__ = 150;
          for (int n = 1; n <= N_obs; ++n) {
            current_statement__ = 149;
            stan::model::assign(Y_pred,
              stan::math::normal_rng(
                (stan::model::rvalue(alpha, "alpha",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                +
                (stan::model::rvalue(beta, "beta",
                   stan::model::index_uni(
                     stan::model::rvalue(ii, "ii", stan::model::index_uni(n))))
                *
                stan::model::rvalue(theta, "theta",
                  stan::model::index_uni(
                    stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
                (stan::math::sqrt(
                   stan::model::rvalue(eta, "eta",
                     stan::model::index_uni(
                       stan::model::rvalue(ii, "ii",
                         stan::model::index_uni(n))))) *
                stan::model::rvalue(rho, "rho",
                  stan::model::index_uni(
                    stan::model::rvalue(jj, "jj", stan::model::index_uni(n))))),
                base_rng__), "assigning variable Y_pred",
              stan::model::index_uni(n));
          }
        } else {
          current_statement__ = 146;
          stan::model::assign(chi,
            stan::math::elt_divide(
              stan::math::subtract(stan::math::to_vector(V), alpha), beta),
            "assigning variable chi");
        }
      } else {
        current_statement__ = 144;
        if (stan::math::logical_eq(MCMC, 1)) {
          current_statement__ = 138;
          stan::model::assign(chi,
            stan::math::elt_divide(
              stan::math::subtract(
                stan::math::subtract(stan::math::to_vector(V),
                  stan::math::to_vector(
                    stan::math::normal_rng(0, stan::math::rep_vector(tau, N),
                      base_rng__))), alpha), beta), "assigning variable chi");
          current_statement__ = 142;
          if (stan::math::logical_eq(rat, 0)) {
            current_statement__ = 140;
            for (int n = 1; n <= N_obs; ++n) {
              current_statement__ = 139;
              stan::model::assign(Y_pred,
                stan::math::normal_rng(
                  (stan::model::rvalue(alpha, "alpha",
                     stan::model::index_uni(
                       stan::model::rvalue(ii, "ii",
                         stan::model::index_uni(n)))) +
                  (stan::model::rvalue(beta, "beta",
                     stan::model::index_uni(
                       stan::model::rvalue(ii, "ii",
                         stan::model::index_uni(n)))) *
                  stan::model::rvalue(theta, "theta",
                    stan::model::index_uni(
                      stan::model::rvalue(jj, "jj", stan::model::index_uni(n)))))),
                  tau, base_rng__), "assigning variable Y_pred",
                stan::model::index_uni(n));
            }
          }
        } else {
          current_statement__ = 136;
          stan::model::assign(chi,
            stan::math::elt_divide(
              stan::math::subtract(stan::math::to_vector(V), alpha), beta),
            "assigning variable chi");
        }
      }
      current_statement__ = 33;
      stan::math::check_greater_or_equal(function__, "min_rho", min_rho, 0);
      out__.write(min_rho);
      out__.write(kappa);
      out__.write(alpha);
      out__.write(beta);
      out__.write(chi);
      out__.write(Y_pred);
    } 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> alpha_raw =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(N, alpha_raw_2dim__,
          DUMMY_VAR__);
      current_statement__ = 1;
      stan::model::assign(alpha_raw,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,-1>>(N, alpha_raw_2dim__),
        "assigning variable alpha_raw");
      out__.write(alpha_raw);
      Eigen::Matrix<local_scalar_t__,-1,-1> beta_raw =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(N, beta_raw_2dim__,
          DUMMY_VAR__);
      current_statement__ = 2;
      stan::model::assign(beta_raw,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,-1>>(N, beta_raw_2dim__),
        "assigning variable beta_raw");
      out__.write(beta_raw);
      Eigen::Matrix<local_scalar_t__,-1,1> theta_lr =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(theta_lr_1dim__,
          DUMMY_VAR__);
      current_statement__ = 3;
      stan::model::assign(theta_lr,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(theta_lr_1dim__),
        "assigning variable theta_lr");
      out__.write_free_ordered(theta_lr);
      std::vector<local_scalar_t__> theta_raw =
        std::vector<local_scalar_t__>(J, DUMMY_VAR__);
      current_statement__ = 4;
      stan::model::assign(theta_raw,
        in__.read<std::vector<local_scalar_t__>>(J),
        "assigning variable theta_raw");
      out__.write(theta_raw);
      Eigen::Matrix<local_scalar_t__,-1,1> mu_alpha_raw =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(mu_alpha_raw_1dim__,
          DUMMY_VAR__);
      current_statement__ = 5;
      stan::model::assign(mu_alpha_raw,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(mu_alpha_raw_1dim__),
        "assigning variable mu_alpha_raw");
      out__.write_free_simplex(mu_alpha_raw);
      Eigen::Matrix<local_scalar_t__,-1,1> mu_beta_raw =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(mu_beta_raw_1dim__,
          DUMMY_VAR__);
      current_statement__ = 6;
      stan::model::assign(mu_beta_raw,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(mu_beta_raw_1dim__),
        "assigning variable mu_beta_raw");
      out__.write_free_simplex(mu_beta_raw);
      std::vector<local_scalar_t__> sigma_alpha_par =
        std::vector<local_scalar_t__>(sigma_alpha_par_1dim__, DUMMY_VAR__);
      current_statement__ = 7;
      stan::model::assign(sigma_alpha_par,
        in__.read<std::vector<local_scalar_t__>>(sigma_alpha_par_1dim__),
        "assigning variable sigma_alpha_par");
      out__.write_free_lb(0, sigma_alpha_par);
      std::vector<local_scalar_t__> sigma_beta_par =
        std::vector<local_scalar_t__>(sigma_beta_par_1dim__, DUMMY_VAR__);
      current_statement__ = 8;
      stan::model::assign(sigma_beta_par,
        in__.read<std::vector<local_scalar_t__>>(sigma_beta_par_1dim__),
        "assigning variable sigma_beta_par");
      out__.write_free_lub(0, 2, sigma_beta_par);
      std::vector<local_scalar_t__> nu_par =
        std::vector<local_scalar_t__>(nu_par_1dim__, DUMMY_VAR__);
      current_statement__ = 9;
      stan::model::assign(nu_par,
        in__.read<std::vector<local_scalar_t__>>(nu_par_1dim__),
        "assigning variable nu_par");
      out__.write_free_lub(3, 30, nu_par);
      std::vector<local_scalar_t__> tau_par =
        std::vector<local_scalar_t__>(tau_par_1dim__, DUMMY_VAR__);
      current_statement__ = 10;
      stan::model::assign(tau_par,
        in__.read<std::vector<local_scalar_t__>>(tau_par_1dim__),
        "assigning variable tau_par");
      out__.write_free_offset_multiplier(0, tau_multip, tau_par);
      Eigen::Matrix<local_scalar_t__,-1,1> eta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(eta_1dim__,
          DUMMY_VAR__);
      current_statement__ = 11;
      stan::model::assign(eta,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(eta_1dim__),
        "assigning variable eta");
      out__.write_free_lb(0, eta);
      Eigen::Matrix<local_scalar_t__,-1,1> rho =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(rho_1dim__,
          DUMMY_VAR__);
      current_statement__ = 12;
      stan::model::assign(rho,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(rho_1dim__),
        "assigning variable rho");
      out__.write_free_simplex(rho);
      Eigen::Matrix<local_scalar_t__,-1,1> lambda_raw =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(lambda_raw_1dim__,
          DUMMY_VAR__);
      current_statement__ = 13;
      stan::model::assign(lambda_raw,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(lambda_raw_1dim__),
        "assigning variable lambda_raw");
      out__.write(lambda_raw);
      std::vector<local_scalar_t__> psi_par =
        std::vector<local_scalar_t__>(psi_par_1dim__, DUMMY_VAR__);
      current_statement__ = 14;
      stan::model::assign(psi_par,
        in__.read<std::vector<local_scalar_t__>>(psi_par_1dim__),
        "assigning variable psi_par");
      out__.write_free_lb(0, psi_par);
      std::vector<local_scalar_t__> gamma =
        std::vector<local_scalar_t__>(gamma_1dim__, DUMMY_VAR__);
      current_statement__ = 15;
      stan::model::assign(gamma,
        in__.read<std::vector<local_scalar_t__>>(gamma_1dim__),
        "assigning variable gamma");
      out__.write_free_lub(0, 1, gamma);
      std::vector<local_scalar_t__> gam_a =
        std::vector<local_scalar_t__>(rat, DUMMY_VAR__);
      current_statement__ = 16;
      stan::model::assign(gam_a,
        in__.read<std::vector<local_scalar_t__>>(rat),
        "assigning variable gam_a");
      out__.write_free_lb(1, gam_a);
      std::vector<local_scalar_t__> gam_b =
        std::vector<local_scalar_t__>(rat, DUMMY_VAR__);
      current_statement__ = 17;
      stan::model::assign(gam_b,
        in__.read<std::vector<local_scalar_t__>>(rat),
        "assigning variable gam_b");
      out__.write_free_lb(1, gam_b);
      Eigen::Matrix<local_scalar_t__,-1,1> zeta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(zeta_1dim__,
          DUMMY_VAR__);
      current_statement__ = 18;
      stan::model::assign(zeta,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(zeta_1dim__),
        "assigning variable zeta");
      out__.write_free_lub(0, 1, zeta);
    } 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", "alpha_raw",
        "double",
        std::vector<size_t>{static_cast<size_t>(N),
          static_cast<size_t>(alpha_raw_2dim__)});
      current_statement__ = 2;
      context__.validate_dims("parameter initialization", "beta_raw",
        "double",
        std::vector<size_t>{static_cast<size_t>(N),
          static_cast<size_t>(beta_raw_2dim__)});
      current_statement__ = 3;
      context__.validate_dims("parameter initialization", "theta_lr",
        "double", std::vector<size_t>{static_cast<size_t>(theta_lr_1dim__)});
      current_statement__ = 4;
      context__.validate_dims("parameter initialization", "theta_raw",
        "double", std::vector<size_t>{static_cast<size_t>(J)});
      current_statement__ = 5;
      context__.validate_dims("parameter initialization", "mu_alpha_raw",
        "double",
        std::vector<size_t>{static_cast<size_t>(mu_alpha_raw_1dim__)});
      current_statement__ = 6;
      context__.validate_dims("parameter initialization", "mu_beta_raw",
        "double",
        std::vector<size_t>{static_cast<size_t>(mu_beta_raw_1dim__)});
      current_statement__ = 7;
      context__.validate_dims("parameter initialization", "sigma_alpha_par",
        "double",
        std::vector<size_t>{static_cast<size_t>(sigma_alpha_par_1dim__)});
      current_statement__ = 8;
      context__.validate_dims("parameter initialization", "sigma_beta_par",
        "double",
        std::vector<size_t>{static_cast<size_t>(sigma_beta_par_1dim__)});
      current_statement__ = 9;
      context__.validate_dims("parameter initialization", "nu_par", "double",
        std::vector<size_t>{static_cast<size_t>(nu_par_1dim__)});
      current_statement__ = 10;
      context__.validate_dims("parameter initialization", "tau_par",
        "double", std::vector<size_t>{static_cast<size_t>(tau_par_1dim__)});
      current_statement__ = 11;
      context__.validate_dims("parameter initialization", "eta", "double",
        std::vector<size_t>{static_cast<size_t>(eta_1dim__)});
      current_statement__ = 12;
      context__.validate_dims("parameter initialization", "rho", "double",
        std::vector<size_t>{static_cast<size_t>(rho_1dim__)});
      current_statement__ = 13;
      context__.validate_dims("parameter initialization", "lambda_raw",
        "double",
        std::vector<size_t>{static_cast<size_t>(lambda_raw_1dim__)});
      current_statement__ = 14;
      context__.validate_dims("parameter initialization", "psi_par",
        "double", std::vector<size_t>{static_cast<size_t>(psi_par_1dim__)});
      current_statement__ = 15;
      context__.validate_dims("parameter initialization", "gamma", "double",
        std::vector<size_t>{static_cast<size_t>(gamma_1dim__)});
      current_statement__ = 16;
      context__.validate_dims("parameter initialization", "gam_a", "double",
        std::vector<size_t>{static_cast<size_t>(rat)});
      current_statement__ = 17;
      context__.validate_dims("parameter initialization", "gam_b", "double",
        std::vector<size_t>{static_cast<size_t>(rat)});
      current_statement__ = 18;
      context__.validate_dims("parameter initialization", "zeta", "double",
        std::vector<size_t>{static_cast<size_t>(zeta_1dim__)});
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      Eigen::Matrix<local_scalar_t__,-1,-1> alpha_raw =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(N, alpha_raw_2dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> alpha_raw_flat__;
        current_statement__ = 1;
        alpha_raw_flat__ = context__.vals_r("alpha_raw");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= alpha_raw_2dim__; ++sym1__) {
          for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
            stan::model::assign(alpha_raw, alpha_raw_flat__[(pos__ - 1)],
              "assigning variable alpha_raw", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            pos__ = (pos__ + 1);
          }
        }
      }
      out__.write(alpha_raw);
      Eigen::Matrix<local_scalar_t__,-1,-1> beta_raw =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(N, beta_raw_2dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> beta_raw_flat__;
        current_statement__ = 2;
        beta_raw_flat__ = context__.vals_r("beta_raw");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= beta_raw_2dim__; ++sym1__) {
          for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
            stan::model::assign(beta_raw, beta_raw_flat__[(pos__ - 1)],
              "assigning variable beta_raw", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            pos__ = (pos__ + 1);
          }
        }
      }
      out__.write(beta_raw);
      Eigen::Matrix<local_scalar_t__,-1,1> theta_lr =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(theta_lr_1dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> theta_lr_flat__;
        current_statement__ = 3;
        theta_lr_flat__ = context__.vals_r("theta_lr");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= theta_lr_1dim__; ++sym1__) {
          stan::model::assign(theta_lr, theta_lr_flat__[(pos__ - 1)],
            "assigning variable theta_lr", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_ordered(theta_lr);
      std::vector<local_scalar_t__> theta_raw =
        std::vector<local_scalar_t__>(J, DUMMY_VAR__);
      current_statement__ = 4;
      theta_raw = context__.vals_r("theta_raw");
      out__.write(theta_raw);
      Eigen::Matrix<local_scalar_t__,-1,1> mu_alpha_raw =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(mu_alpha_raw_1dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> mu_alpha_raw_flat__;
        current_statement__ = 5;
        mu_alpha_raw_flat__ = context__.vals_r("mu_alpha_raw");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= mu_alpha_raw_1dim__; ++sym1__) {
          stan::model::assign(mu_alpha_raw, mu_alpha_raw_flat__[(pos__ - 1)],
            "assigning variable mu_alpha_raw", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_simplex(mu_alpha_raw);
      Eigen::Matrix<local_scalar_t__,-1,1> mu_beta_raw =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(mu_beta_raw_1dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> mu_beta_raw_flat__;
        current_statement__ = 6;
        mu_beta_raw_flat__ = context__.vals_r("mu_beta_raw");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= mu_beta_raw_1dim__; ++sym1__) {
          stan::model::assign(mu_beta_raw, mu_beta_raw_flat__[(pos__ - 1)],
            "assigning variable mu_beta_raw", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_simplex(mu_beta_raw);
      std::vector<local_scalar_t__> sigma_alpha_par =
        std::vector<local_scalar_t__>(sigma_alpha_par_1dim__, DUMMY_VAR__);
      current_statement__ = 7;
      sigma_alpha_par = context__.vals_r("sigma_alpha_par");
      out__.write_free_lb(0, sigma_alpha_par);
      std::vector<local_scalar_t__> sigma_beta_par =
        std::vector<local_scalar_t__>(sigma_beta_par_1dim__, DUMMY_VAR__);
      current_statement__ = 8;
      sigma_beta_par = context__.vals_r("sigma_beta_par");
      out__.write_free_lub(0, 2, sigma_beta_par);
      std::vector<local_scalar_t__> nu_par =
        std::vector<local_scalar_t__>(nu_par_1dim__, DUMMY_VAR__);
      current_statement__ = 9;
      nu_par = context__.vals_r("nu_par");
      out__.write_free_lub(3, 30, nu_par);
      std::vector<local_scalar_t__> tau_par =
        std::vector<local_scalar_t__>(tau_par_1dim__, DUMMY_VAR__);
      current_statement__ = 10;
      tau_par = context__.vals_r("tau_par");
      out__.write_free_offset_multiplier(0, tau_multip, tau_par);
      Eigen::Matrix<local_scalar_t__,-1,1> eta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(eta_1dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> eta_flat__;
        current_statement__ = 11;
        eta_flat__ = context__.vals_r("eta");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= eta_1dim__; ++sym1__) {
          stan::model::assign(eta, eta_flat__[(pos__ - 1)],
            "assigning variable eta", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_lb(0, eta);
      Eigen::Matrix<local_scalar_t__,-1,1> rho =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(rho_1dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> rho_flat__;
        current_statement__ = 12;
        rho_flat__ = context__.vals_r("rho");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= rho_1dim__; ++sym1__) {
          stan::model::assign(rho, rho_flat__[(pos__ - 1)],
            "assigning variable rho", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_simplex(rho);
      Eigen::Matrix<local_scalar_t__,-1,1> lambda_raw =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(lambda_raw_1dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> lambda_raw_flat__;
        current_statement__ = 13;
        lambda_raw_flat__ = context__.vals_r("lambda_raw");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= lambda_raw_1dim__; ++sym1__) {
          stan::model::assign(lambda_raw, lambda_raw_flat__[(pos__ - 1)],
            "assigning variable lambda_raw", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      out__.write(lambda_raw);
      std::vector<local_scalar_t__> psi_par =
        std::vector<local_scalar_t__>(psi_par_1dim__, DUMMY_VAR__);
      current_statement__ = 14;
      psi_par = context__.vals_r("psi_par");
      out__.write_free_lb(0, psi_par);
      std::vector<local_scalar_t__> gamma =
        std::vector<local_scalar_t__>(gamma_1dim__, DUMMY_VAR__);
      current_statement__ = 15;
      gamma = context__.vals_r("gamma");
      out__.write_free_lub(0, 1, gamma);
      std::vector<local_scalar_t__> gam_a =
        std::vector<local_scalar_t__>(rat, DUMMY_VAR__);
      current_statement__ = 16;
      gam_a = context__.vals_r("gam_a");
      out__.write_free_lb(1, gam_a);
      std::vector<local_scalar_t__> gam_b =
        std::vector<local_scalar_t__>(rat, DUMMY_VAR__);
      current_statement__ = 17;
      gam_b = context__.vals_r("gam_b");
      out__.write_free_lb(1, gam_b);
      Eigen::Matrix<local_scalar_t__,-1,1> zeta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(zeta_1dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> zeta_flat__;
        current_statement__ = 18;
        zeta_flat__ = context__.vals_r("zeta");
        pos__ = 1;
        for (int sym1__ = 1; sym1__ <= zeta_1dim__; ++sym1__) {
          stan::model::assign(zeta, zeta_flat__[(pos__ - 1)],
            "assigning variable zeta", stan::model::index_uni(sym1__));
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_lub(0, 1, zeta);
    } 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>{"alpha_raw", "beta_raw", "theta_lr",
                "theta_raw", "mu_alpha_raw", "mu_beta_raw",
                "sigma_alpha_par", "sigma_beta_par", "nu_par", "tau_par",
                "eta", "rho", "lambda_raw", "psi_par", "gamma", "gam_a",
                "gam_b", "zeta"};
    if (emit_transformed_parameters__) {
      std::vector<std::string>
        temp{"log_probs", "theta", "alpha0", "beta0", "log_lik", "lambda",
             "mu_alpha", "mu_beta", "eta_scale", "sigma_alpha", "sigma_beta",
             "nu", "tau", "psi"};
      names__.reserve(names__.size() + temp.size());
      names__.insert(names__.end(), temp.begin(), temp.end());
    }
    if (emit_generated_quantities__) {
      std::vector<std::string>
        temp{"min_rho", "kappa", "alpha", "beta", "chi", "Y_pred"};
      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>(N),
                                                 static_cast<size_t>(
                                                   alpha_raw_2dim__)},
                std::vector<size_t>{static_cast<size_t>(N),
                  static_cast<size_t>(beta_raw_2dim__)},
                std::vector<size_t>{static_cast<size_t>(theta_lr_1dim__)},
                std::vector<size_t>{static_cast<size_t>(J)},
                std::vector<size_t>{static_cast<size_t>(mu_alpha_raw_1dim__)},
                std::vector<size_t>{static_cast<size_t>(mu_beta_raw_1dim__)},
                std::vector<size_t>{static_cast<size_t>(
                                      sigma_alpha_par_1dim__)},
                std::vector<size_t>{static_cast<size_t>(sigma_beta_par_1dim__)},
                std::vector<size_t>{static_cast<size_t>(nu_par_1dim__)},
                std::vector<size_t>{static_cast<size_t>(tau_par_1dim__)},
                std::vector<size_t>{static_cast<size_t>(eta_1dim__)},
                std::vector<size_t>{static_cast<size_t>(rho_1dim__)},
                std::vector<size_t>{static_cast<size_t>(lambda_raw_1dim__)},
                std::vector<size_t>{static_cast<size_t>(psi_par_1dim__)},
                std::vector<size_t>{static_cast<size_t>(gamma_1dim__)},
                std::vector<size_t>{static_cast<size_t>(rat)},
                std::vector<size_t>{static_cast<size_t>(rat)},
                std::vector<size_t>{static_cast<size_t>(zeta_1dim__)}};
    if (emit_transformed_parameters__) {
      std::vector<std::vector<size_t>>
        temp{std::vector<size_t>{static_cast<size_t>(log_probs_1dim__)},
             std::vector<size_t>{static_cast<size_t>(J)},
             std::vector<size_t>{static_cast<size_t>(N),
               static_cast<size_t>(alpha0_2dim__)},
             std::vector<size_t>{static_cast<size_t>(N),
               static_cast<size_t>(beta0_2dim__)},
             std::vector<size_t>{static_cast<size_t>(N_obs)},
             std::vector<size_t>{static_cast<size_t>(lambda_1dim__)},
             std::vector<size_t>{static_cast<size_t>(mu_alpha_1dim__)},
             std::vector<size_t>{static_cast<size_t>(mu_beta_1dim__)},
             std::vector<size_t>{static_cast<size_t>(het)},
             std::vector<size_t>{static_cast<size_t>(sigma_alpha_1dim__)},
             std::vector<size_t>{static_cast<size_t>(sigma_beta_1dim__)},
             std::vector<size_t>{static_cast<size_t>(het)},
             std::vector<size_t>{},
             std::vector<size_t>{static_cast<size_t>(flip)}};
      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>{},
             std::vector<size_t>{static_cast<size_t>(kappa_1dim__)},
             std::vector<size_t>{static_cast<size_t>(N)},
             std::vector<size_t>{static_cast<size_t>(N)},
             std::vector<size_t>{static_cast<size_t>(N)},
             std::vector<size_t>{static_cast<size_t>(Y_pred_1dim__)}};
      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__ <= alpha_raw_2dim__; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
        param_names__.emplace_back(std::string() + "alpha_raw" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    for (int sym1__ = 1; sym1__ <= beta_raw_2dim__; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
        param_names__.emplace_back(std::string() + "beta_raw" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    for (int sym1__ = 1; sym1__ <= theta_lr_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "theta_lr" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= J; ++sym1__) {
      param_names__.emplace_back(std::string() + "theta_raw" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= mu_alpha_raw_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "mu_alpha_raw" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= mu_beta_raw_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "mu_beta_raw" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= sigma_alpha_par_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "sigma_alpha_par" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= sigma_beta_par_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "sigma_beta_par" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= nu_par_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "nu_par" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= tau_par_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "tau_par" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= eta_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "eta" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= rho_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "rho" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= lambda_raw_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "lambda_raw" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= psi_par_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "psi_par" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= gamma_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "gamma" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= rat; ++sym1__) {
      param_names__.emplace_back(std::string() + "gam_a" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= rat; ++sym1__) {
      param_names__.emplace_back(std::string() + "gam_b" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= zeta_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "zeta" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= log_probs_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_probs" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= J; ++sym1__) {
        param_names__.emplace_back(std::string() + "theta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= alpha0_2dim__; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
          param_names__.emplace_back(std::string() + "alpha0" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= beta0_2dim__; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
          param_names__.emplace_back(std::string() + "beta0" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= N_obs; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_lik" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= lambda_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "lambda" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= mu_alpha_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "mu_alpha" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= mu_beta_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "mu_beta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= het; ++sym1__) {
        param_names__.emplace_back(std::string() + "eta_scale" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= sigma_alpha_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "sigma_alpha" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= sigma_beta_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "sigma_beta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= het; ++sym1__) {
        param_names__.emplace_back(std::string() + "nu" + '.' +
          std::to_string(sym1__));
      }
      param_names__.emplace_back(std::string() + "tau");
      for (int sym1__ = 1; sym1__ <= flip; ++sym1__) {
        param_names__.emplace_back(std::string() + "psi" + '.' +
          std::to_string(sym1__));
      }
    }
    if (emit_generated_quantities__) {
      param_names__.emplace_back(std::string() + "min_rho");
      for (int sym1__ = 1; sym1__ <= kappa_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "kappa" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
        param_names__.emplace_back(std::string() + "alpha" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
        param_names__.emplace_back(std::string() + "beta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
        param_names__.emplace_back(std::string() + "chi" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= Y_pred_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "Y_pred" + '.' +
          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__ <= alpha_raw_2dim__; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
        param_names__.emplace_back(std::string() + "alpha_raw" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    for (int sym1__ = 1; sym1__ <= beta_raw_2dim__; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
        param_names__.emplace_back(std::string() + "beta_raw" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    for (int sym1__ = 1; sym1__ <= theta_lr_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "theta_lr" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= J; ++sym1__) {
      param_names__.emplace_back(std::string() + "theta_raw" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= (mu_alpha_raw_1dim__ - 1); ++sym1__) {
      param_names__.emplace_back(std::string() + "mu_alpha_raw" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= (mu_beta_raw_1dim__ - 1); ++sym1__) {
      param_names__.emplace_back(std::string() + "mu_beta_raw" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= sigma_alpha_par_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "sigma_alpha_par" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= sigma_beta_par_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "sigma_beta_par" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= nu_par_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "nu_par" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= tau_par_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "tau_par" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= eta_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "eta" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= (rho_1dim__ - 1); ++sym1__) {
      param_names__.emplace_back(std::string() + "rho" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= lambda_raw_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "lambda_raw" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= psi_par_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "psi_par" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= gamma_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "gamma" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= rat; ++sym1__) {
      param_names__.emplace_back(std::string() + "gam_a" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= rat; ++sym1__) {
      param_names__.emplace_back(std::string() + "gam_b" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= zeta_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "zeta" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= log_probs_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_probs" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= J; ++sym1__) {
        param_names__.emplace_back(std::string() + "theta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= alpha0_2dim__; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
          param_names__.emplace_back(std::string() + "alpha0" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= beta0_2dim__; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= N; ++sym2__) {
          param_names__.emplace_back(std::string() + "beta0" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= N_obs; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_lik" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= lambda_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "lambda" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= mu_alpha_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "mu_alpha" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= mu_beta_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "mu_beta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= het; ++sym1__) {
        param_names__.emplace_back(std::string() + "eta_scale" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= sigma_alpha_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "sigma_alpha" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= sigma_beta_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "sigma_beta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= het; ++sym1__) {
        param_names__.emplace_back(std::string() + "nu" + '.' +
          std::to_string(sym1__));
      }
      param_names__.emplace_back(std::string() + "tau");
      for (int sym1__ = 1; sym1__ <= flip; ++sym1__) {
        param_names__.emplace_back(std::string() + "psi" + '.' +
          std::to_string(sym1__));
      }
    }
    if (emit_generated_quantities__) {
      param_names__.emplace_back(std::string() + "min_rho");
      for (int sym1__ = 1; sym1__ <= kappa_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "kappa" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
        param_names__.emplace_back(std::string() + "alpha" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
        param_names__.emplace_back(std::string() + "beta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= N; ++sym1__) {
        param_names__.emplace_back(std::string() + "chi" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= Y_pred_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "Y_pred" + '.' +
          std::to_string(sym1__));
      }
    }
  }
  inline std::string get_constrained_sizedtypes() const {
    return std::string("[{\"name\":\"alpha_raw\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N) + ",\"cols\":" + std::to_string(alpha_raw_2dim__) + "},\"block\":\"parameters\"},{\"name\":\"beta_raw\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N) + ",\"cols\":" + std::to_string(beta_raw_2dim__) + "},\"block\":\"parameters\"},{\"name\":\"theta_lr\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(theta_lr_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"theta_raw\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(J) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"mu_alpha_raw\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(mu_alpha_raw_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"mu_beta_raw\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(mu_beta_raw_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"sigma_alpha_par\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(sigma_alpha_par_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"sigma_beta_par\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(sigma_beta_par_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"nu_par\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(nu_par_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"tau_par\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(tau_par_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"eta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(eta_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"rho\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(rho_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"lambda_raw\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(lambda_raw_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"psi_par\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(psi_par_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(gamma_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"gam_a\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(rat) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"gam_b\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(rat) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"zeta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(zeta_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"log_probs\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_probs_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"theta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(J) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"alpha0\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N) + ",\"cols\":" + std::to_string(alpha0_2dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"beta0\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N) + ",\"cols\":" + std::to_string(beta0_2dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_obs) + "},\"block\":\"transformed_parameters\"},{\"name\":\"lambda\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(lambda_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu_alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(mu_alpha_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu_beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(mu_beta_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"eta_scale\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(het) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"sigma_alpha\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(sigma_alpha_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"sigma_beta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(sigma_beta_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"nu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(het) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"tau\",\"type\":{\"name\":\"real\"},\"block\":\"transformed_parameters\"},{\"name\":\"psi\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(flip) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"min_rho\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"kappa\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(kappa_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N) + "},\"block\":\"generated_quantities\"},{\"name\":\"chi\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N) + "},\"block\":\"generated_quantities\"},{\"name\":\"Y_pred\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Y_pred_1dim__) + "},\"block\":\"generated_quantities\"}]");
  }
  inline std::string get_unconstrained_sizedtypes() const {
    return std::string("[{\"name\":\"alpha_raw\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N) + ",\"cols\":" + std::to_string(alpha_raw_2dim__) + "},\"block\":\"parameters\"},{\"name\":\"beta_raw\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N) + ",\"cols\":" + std::to_string(beta_raw_2dim__) + "},\"block\":\"parameters\"},{\"name\":\"theta_lr\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(theta_lr_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"theta_raw\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(J) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"mu_alpha_raw\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string((mu_alpha_raw_1dim__ -1)) + "},\"block\":\"parameters\"},{\"name\":\"mu_beta_raw\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string((mu_beta_raw_1dim__ -1)) + "},\"block\":\"parameters\"},{\"name\":\"sigma_alpha_par\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(sigma_alpha_par_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"sigma_beta_par\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(sigma_beta_par_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"nu_par\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(nu_par_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"tau_par\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(tau_par_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"eta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(eta_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"rho\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string((rho_1dim__ -1)) + "},\"block\":\"parameters\"},{\"name\":\"lambda_raw\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(lambda_raw_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"psi_par\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(psi_par_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(gamma_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"gam_a\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(rat) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"gam_b\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(rat) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"zeta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(zeta_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"log_probs\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_probs_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"theta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(J) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"alpha0\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N) + ",\"cols\":" + std::to_string(alpha0_2dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"beta0\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N) + ",\"cols\":" + std::to_string(beta0_2dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_obs) + "},\"block\":\"transformed_parameters\"},{\"name\":\"lambda\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(lambda_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu_alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(mu_alpha_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu_beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(mu_beta_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"eta_scale\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(het) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"sigma_alpha\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(sigma_alpha_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"sigma_beta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(sigma_beta_1dim__) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"nu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(het) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"tau\",\"type\":{\"name\":\"real\"},\"block\":\"transformed_parameters\"},{\"name\":\"psi\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(flip) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"min_rho\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"kappa\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(kappa_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N) + "},\"block\":\"generated_quantities\"},{\"name\":\"chi\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N) + "},\"block\":\"generated_quantities\"},{\"name\":\"Y_pred\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Y_pred_1dim__) + "},\"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__ = (N * alpha_raw_2dim__) + (N *
      beta_raw_2dim__) + theta_lr_1dim__ + J + mu_alpha_raw_1dim__ +
      mu_beta_raw_1dim__ + sigma_alpha_par_1dim__ + sigma_beta_par_1dim__ +
      nu_par_1dim__ + tau_par_1dim__ + eta_1dim__ + rho_1dim__ +
      lambda_raw_1dim__ + psi_par_1dim__ + gamma_1dim__ + rat + rat +
      zeta_1dim__;
    const size_t num_transformed = emit_transformed_parameters *
      (log_probs_1dim__ + J + (N * alpha0_2dim__) + (N * beta0_2dim__) +
      N_obs + lambda_1dim__ + mu_alpha_1dim__ + mu_beta_1dim__ + het +
      sigma_alpha_1dim__ + sigma_beta_1dim__ + het + 1 + flip);
    const size_t num_gen_quantities = emit_generated_quantities * (1 +
      kappa_1dim__ + N + N + N + Y_pred_1dim__);
    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__ = (N * alpha_raw_2dim__) + (N *
      beta_raw_2dim__) + theta_lr_1dim__ + J + mu_alpha_raw_1dim__ +
      mu_beta_raw_1dim__ + sigma_alpha_par_1dim__ + sigma_beta_par_1dim__ +
      nu_par_1dim__ + tau_par_1dim__ + eta_1dim__ + rho_1dim__ +
      lambda_raw_1dim__ + psi_par_1dim__ + gamma_1dim__ + rat + rat +
      zeta_1dim__;
    const size_t num_transformed = emit_transformed_parameters *
      (log_probs_1dim__ + J + (N * alpha0_2dim__) + (N * beta0_2dim__) +
      N_obs + lambda_1dim__ + mu_alpha_1dim__ + mu_beta_1dim__ + het +
      sigma_alpha_1dim__ + sigma_beta_1dim__ + het + 1 + flip);
    const size_t num_gen_quantities = emit_generated_quantities * (1 +
      kappa_1dim__ + N + N + N + Y_pred_1dim__);
    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 = model_omni_namespace::model_omni;
#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 model_omni_namespace::profiles__;
}
#endif
#endif
