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

#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.32.2
#include <stan/model/model_header.hpp>
namespace model_mlumr_binary_spfa_namespace {
using stan::model::model_base_crtp;
using namespace stan::math;
stan::math::profile_map profiles__;
static constexpr std::array<const char*, 146> locations_array__ =
  {" (found before start of program)",
  " (in 'mlumr_binary_spfa', line 125, column 2 to column 16)",
  " (in 'mlumr_binary_spfa', line 126, column 2 to column 21)",
  " (in 'mlumr_binary_spfa', line 129, column 2 to column 23)",
  " (in 'mlumr_binary_spfa', line 135, column 2 to column 65)",
  " (in 'mlumr_binary_spfa', line 136, column 2 to column 50)",
  " (in 'mlumr_binary_spfa', line 162, column 2 to column 17)",
  " (in 'mlumr_binary_spfa', line 163, column 2 to column 22)",
  " (in 'mlumr_binary_spfa', line 164, column 2 to column 16)",
  " (in 'mlumr_binary_spfa', line 165, column 2 to column 21)",
  " (in 'mlumr_binary_spfa', line 166, column 2 to column 16)",
  " (in 'mlumr_binary_spfa', line 167, column 2 to column 21)",
  " (in 'mlumr_binary_spfa', line 168, column 2 to column 21)",
  " (in 'mlumr_binary_spfa', line 169, column 2 to column 26)",
  " (in 'mlumr_binary_spfa', line 170, column 2 to column 26)",
  " (in 'mlumr_binary_spfa', line 171, column 2 to column 31)",
  " (in 'mlumr_binary_spfa', line 172, column 2 to column 28)",
  " (in 'mlumr_binary_spfa', line 173, column 2 to column 33)",
  " (in 'mlumr_binary_spfa', line 176, column 11 to column 16)",
  " (in 'mlumr_binary_spfa', line 176, column 4 to column 67)",
  " (in 'mlumr_binary_spfa', line 177, column 11 to column 16)",
  " (in 'mlumr_binary_spfa', line 177, column 4 to column 93)",
  " (in 'mlumr_binary_spfa', line 178, column 4 to column 38)",
  " (in 'mlumr_binary_spfa', line 179, column 4 to column 48)",
  " (in 'mlumr_binary_spfa', line 175, column 2 to line 180, column 3)",
  " (in 'mlumr_binary_spfa', line 184, column 4 to column 30)",
  " (in 'mlumr_binary_spfa', line 185, column 4 to column 29)",
  " (in 'mlumr_binary_spfa', line 186, column 4 to column 21)",
  " (in 'mlumr_binary_spfa', line 188, column 13 to column 18)",
  " (in 'mlumr_binary_spfa', line 188, column 6 to column 84)",
  " (in 'mlumr_binary_spfa', line 189, column 13 to column 18)",
  " (in 'mlumr_binary_spfa', line 189, column 6 to column 89)",
  " (in 'mlumr_binary_spfa', line 190, column 6 to column 51)",
  " (in 'mlumr_binary_spfa', line 191, column 6 to column 50)",
  " (in 'mlumr_binary_spfa', line 192, column 6 to column 26)",
  " (in 'mlumr_binary_spfa', line 187, column 28 to line 193, column 5)",
  " (in 'mlumr_binary_spfa', line 187, column 4 to line 193, column 5)",
  " (in 'mlumr_binary_spfa', line 194, column 4 to column 52)",
  " (in 'mlumr_binary_spfa', line 195, column 4 to column 56)",
  " (in 'mlumr_binary_spfa', line 183, column 2 to line 196, column 3)",
  " (in 'mlumr_binary_spfa', line 201, column 2 to column 73)",
  " (in 'mlumr_binary_spfa', line 202, column 2 to column 88)",
  " (in 'mlumr_binary_spfa', line 203, column 2 to column 48)",
  " (in 'mlumr_binary_spfa', line 204, column 2 to column 63)",
  " (in 'mlumr_binary_spfa', line 207, column 2 to column 60)",
  " (in 'mlumr_binary_spfa', line 208, column 2 to column 75)",
  " (in 'mlumr_binary_spfa', line 215, column 11 to column 16)",
  " (in 'mlumr_binary_spfa', line 215, column 4 to column 61)",
  " (in 'mlumr_binary_spfa', line 217, column 6 to column 59)",
  " (in 'mlumr_binary_spfa', line 216, column 4 to line 217, column 59)",
  " (in 'mlumr_binary_spfa', line 214, column 9 to line 218, column 3)",
  " (in 'mlumr_binary_spfa', line 213, column 6 to column 67)",
  " (in 'mlumr_binary_spfa', line 212, column 4 to line 213, column 67)",
  " (in 'mlumr_binary_spfa', line 211, column 17 to line 214, column 3)",
  " (in 'mlumr_binary_spfa', line 211, column 2 to line 218, column 3)",
  " (in 'mlumr_binary_spfa', line 221, column 11 to column 16)",
  " (in 'mlumr_binary_spfa', line 221, column 4 to column 85)",
  " (in 'mlumr_binary_spfa', line 222, column 4 to column 30)",
  " (in 'mlumr_binary_spfa', line 223, column 4 to column 64)",
  " (in 'mlumr_binary_spfa', line 220, column 26 to line 224, column 3)",
  " (in 'mlumr_binary_spfa', line 220, column 2 to line 224, column 3)",
  " (in 'mlumr_binary_spfa', line 140, column 2 to line 141, column 71)",
  " (in 'mlumr_binary_spfa', line 142, column 2 to line 143, column 71)",
  " (in 'mlumr_binary_spfa', line 144, column 2 to column 73)",
  " (in 'mlumr_binary_spfa', line 149, column 4 to column 58)",
  " (in 'mlumr_binary_spfa', line 147, column 4 to column 37)",
  " (in 'mlumr_binary_spfa', line 146, column 2 to line 149, column 58)",
  " (in 'mlumr_binary_spfa', line 153, column 11 to column 16)",
  " (in 'mlumr_binary_spfa', line 153, column 4 to column 85)",
  " (in 'mlumr_binary_spfa', line 154, column 4 to column 30)",
  " (in 'mlumr_binary_spfa', line 155, column 4 to column 42)",
  " (in 'mlumr_binary_spfa', line 151, column 26 to line 156, column 3)",
  " (in 'mlumr_binary_spfa', line 151, column 2 to line 156, column 3)",
  " (in 'mlumr_binary_spfa', line 85, column 2 to column 21)",
  " (in 'mlumr_binary_spfa', line 86, column 8 to column 13)",
  " (in 'mlumr_binary_spfa', line 86, column 2 to column 42)",
  " (in 'mlumr_binary_spfa', line 87, column 2 to column 21)",
  " (in 'mlumr_binary_spfa', line 88, column 9 to column 14)",
  " (in 'mlumr_binary_spfa', line 88, column 16 to column 21)",
  " (in 'mlumr_binary_spfa', line 88, column 2 to column 29)",
  " (in 'mlumr_binary_spfa', line 90, column 2 to column 26)",
  " (in 'mlumr_binary_spfa', line 91, column 8 to column 18)",
  " (in 'mlumr_binary_spfa', line 91, column 2 to column 39)",
  " (in 'mlumr_binary_spfa', line 92, column 8 to column 18)",
  " (in 'mlumr_binary_spfa', line 92, column 2 to column 39)",
  " (in 'mlumr_binary_spfa', line 94, column 2 to column 21)",
  " (in 'mlumr_binary_spfa', line 95, column 8 to column 18)",
  " (in 'mlumr_binary_spfa', line 95, column 27 to column 32)",
  " (in 'mlumr_binary_spfa', line 95, column 34 to column 39)",
  " (in 'mlumr_binary_spfa', line 95, column 2 to column 47)",
  " (in 'mlumr_binary_spfa', line 112, column 0 to column 26)",
  " (in 'mlumr_binary_spfa', line 113, column 0 to column 33)",
  " (in 'mlumr_binary_spfa', line 114, column 0 to column 42)",
  " (in 'mlumr_binary_spfa', line 115, column 0 to column 33)",
  " (in 'mlumr_binary_spfa', line 117, column 7 to column 12)",
  " (in 'mlumr_binary_spfa', line 117, column 0 to column 30)",
  " (in 'mlumr_binary_spfa', line 118, column 16 to column 21)",
  " (in 'mlumr_binary_spfa', line 118, column 0 to column 37)",
  " (in 'mlumr_binary_spfa', line 119, column 0 to column 37)",
  " (in 'mlumr_binary_spfa', line 120, column 0 to column 28)",
  " (in 'mlumr_binary_spfa', line 121, column 2 to column 28)",
  " (in 'mlumr_binary_spfa', line 129, column 9 to column 14)",
  " (in 'mlumr_binary_spfa', line 135, column 9 to column 14)",
  " (in 'mlumr_binary_spfa', line 136, column 9 to column 14)",
  " (in 'mlumr_binary_spfa', line 172, column 9 to column 14)",
  " (in 'mlumr_binary_spfa', line 173, column 9 to column 19)",
  " (in 'mlumr_binary_spfa', line 21, column 7 to column 54)",
  " (in 'mlumr_binary_spfa', line 20, column 17 to column 57)",
  " (in 'mlumr_binary_spfa', line 20, column 2 to line 21, column 54)",
  " (in 'mlumr_binary_spfa', line 19, column 76 to line 22, column 1)",
  " (in 'mlumr_binary_spfa', line 26, column 7 to column 54)",
  " (in 'mlumr_binary_spfa', line 25, column 17 to column 57)",
  " (in 'mlumr_binary_spfa', line 25, column 2 to line 26, column 54)",
  " (in 'mlumr_binary_spfa', line 24, column 82 to line 27, column 1)",
  " (in 'mlumr_binary_spfa', line 32, column 7 to column 51)",
  " (in 'mlumr_binary_spfa', line 31, column 22 to column 73)",
  " (in 'mlumr_binary_spfa', line 31, column 7 to line 32, column 51)",
  " (in 'mlumr_binary_spfa', line 30, column 17 to column 61)",
  " (in 'mlumr_binary_spfa', line 30, column 2 to line 32, column 51)",
  " (in 'mlumr_binary_spfa', line 29, column 79 to line 33, column 1)",
  " (in 'mlumr_binary_spfa', line 48, column 7 to column 43)",
  " (in 'mlumr_binary_spfa', line 47, column 17 to column 43)",
  " (in 'mlumr_binary_spfa', line 47, column 2 to line 48, column 43)",
  " (in 'mlumr_binary_spfa', line 46, column 55 to line 49, column 1)",
  " (in 'mlumr_binary_spfa', line 54, column 2 to column 34)",
  " (in 'mlumr_binary_spfa', line 53, column 39 to line 55, column 1)",
  " (in 'mlumr_binary_spfa', line 60, column 2 to column 48)",
  " (in 'mlumr_binary_spfa', line 59, column 24 to line 61, column 1)",
  " (in 'mlumr_binary_spfa', line 68, column 7 to column 33)",
  " (in 'mlumr_binary_spfa', line 67, column 27 to column 43)",
  " (in 'mlumr_binary_spfa', line 67, column 7 to line 68, column 33)",
  " (in 'mlumr_binary_spfa', line 66, column 22 to column 44)",
  " (in 'mlumr_binary_spfa', line 66, column 2 to line 68, column 33)",
  " (in 'mlumr_binary_spfa', line 65, column 46 to line 69, column 1)",
  " (in 'mlumr_binary_spfa', line 73, column 2 to column 28)",
  " (in 'mlumr_binary_spfa', line 77, column 11 to column 12)",
  " (in 'mlumr_binary_spfa', line 77, column 4 to column 21)",
  " (in 'mlumr_binary_spfa', line 78, column 19 to column 53)",
  " (in 'mlumr_binary_spfa', line 78, column 4 to column 53)",
  " (in 'mlumr_binary_spfa', line 79, column 4 to column 18)",
  " (in 'mlumr_binary_spfa', line 76, column 7 to line 80, column 3)",
  " (in 'mlumr_binary_spfa', line 75, column 27 to column 43)",
  " (in 'mlumr_binary_spfa', line 75, column 7 to line 80, column 3)",
  " (in 'mlumr_binary_spfa', line 74, column 22 to column 44)",
  " (in 'mlumr_binary_spfa', line 74, column 2 to line 80, column 3)",
  " (in 'mlumr_binary_spfa', line 72, column 54 to line 81, column 1)"};
template <typename T0__, typename T1__, typename T2__, typename T4__,
          stan::require_all_t<stan::is_stan_scalar<T0__>,
                              stan::is_stan_scalar<T1__>,
                              stan::is_stan_scalar<T2__>,
                              stan::is_stan_scalar<T4__>>* = nullptr>
stan::promote_args_t<T0__, T1__, T2__, T4__>
log_prior_scalar(const T0__& x, const T1__& location, const T2__& scale,
                 const int& dist, const T4__& df, std::ostream* pstream__);
template <typename T0__, typename T1__, typename T2__, typename T4__,
          stan::require_all_t<stan::is_col_vector<T0__>,
                              stan::is_vt_not_complex<T0__>,
                              stan::is_col_vector<T1__>,
                              stan::is_vt_not_complex<T1__>,
                              stan::is_col_vector<T2__>,
                              stan::is_vt_not_complex<T2__>,
                              stan::is_stan_scalar<T4__>>* = nullptr>
stan::promote_args_t<stan::base_type_t<T0__>, stan::base_type_t<T1__>,
  stan::base_type_t<T2__>, T4__>
log_prior_vector(const T0__& x_arg__, const T1__& location_arg__, const T2__&
                 scale_arg__, const int& dist, const T4__& df, std::ostream*
                 pstream__);
template <typename T0__, typename T1__, typename T2__, typename T4__,
          stan::require_all_t<stan::is_stan_scalar<T0__>,
                              stan::is_stan_scalar<T1__>,
                              stan::is_stan_scalar<T2__>,
                              stan::is_stan_scalar<T4__>>* = nullptr>
stan::promote_args_t<T0__, T1__, T2__, T4__>
log_prior_sigma(const T0__& sigma, const T1__& location, const T2__& scale,
                const int& dist, const T4__& df, std::ostream* pstream__);
template <typename T0__, typename T2__,
          stan::require_all_t<stan::is_col_vector<T0__>,
                              stan::is_vt_not_complex<T0__>,
                              stan::is_stan_scalar<T2__>>* = nullptr>
stan::promote_args_t<stan::base_type_t<T0__>, T2__>
log_prior_std_vector(const T0__& z_arg__, const int& dist, const T2__& df,
                     std::ostream* pstream__);
template <typename T0__, typename T1__,
          stan::require_all_t<stan::is_stan_scalar<T0__>,
                              stan::is_stan_scalar<T1__>>* = nullptr>
stan::promote_args_t<T0__, T1__>
safe_divide(const T0__& num, const T1__& denom, std::ostream* pstream__);
template <typename T0__,
          stan::require_all_t<stan::is_stan_scalar<T0__>>* = nullptr>
stan::promote_args_t<T0__> safe_logit(const T0__& p, std::ostream* pstream__);
template <typename T0__,
          stan::require_all_t<stan::is_stan_scalar<T0__>>* = nullptr>
stan::promote_args_t<T0__>
inv_link_binary(const T0__& eta, const int& link_code, std::ostream*
                pstream__);
template <typename T0__,
          stan::require_all_t<stan::is_col_vector<T0__>,
                              stan::is_vt_not_complex<T0__>>* = nullptr>
Eigen::Matrix<stan::promote_args_t<stan::base_type_t<T0__>>,-1,1>
inv_link_binary_vec(const T0__& eta_arg__, const int& link_code,
                    std::ostream* pstream__);
template <typename T0__, typename T1__, typename T2__, typename T4__,
          stan::require_all_t<stan::is_stan_scalar<T0__>,
                              stan::is_stan_scalar<T1__>,
                              stan::is_stan_scalar<T2__>,
                              stan::is_stan_scalar<T4__>>*>
stan::promote_args_t<T0__, T1__, T2__, T4__>
log_prior_scalar(const T0__& x, const T1__& location, const T2__& scale,
                 const int& dist, const T4__& df, std::ostream* pstream__) {
  using local_scalar_t__ = stan::promote_args_t<T0__, T1__, T2__, T4__>;
  int current_statement__ = 0;
  static constexpr bool propto__ = true;
  // suppress unused var warning
  (void) propto__;
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    current_statement__ = 108;
    if (stan::math::logical_eq(dist, 0)) {
      current_statement__ = 107;
      return stan::math::normal_lpdf<false>(x, location, scale);
    } else {
      current_statement__ = 106;
      return stan::math::student_t_lpdf<false>(x, df, location, scale);
    }
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
template <typename T0__, typename T1__, typename T2__, typename T4__,
          stan::require_all_t<stan::is_col_vector<T0__>,
                              stan::is_vt_not_complex<T0__>,
                              stan::is_col_vector<T1__>,
                              stan::is_vt_not_complex<T1__>,
                              stan::is_col_vector<T2__>,
                              stan::is_vt_not_complex<T2__>,
                              stan::is_stan_scalar<T4__>>*>
stan::promote_args_t<stan::base_type_t<T0__>, stan::base_type_t<T1__>,
  stan::base_type_t<T2__>, T4__>
log_prior_vector(const T0__& x_arg__, const T1__& location_arg__, const T2__&
                 scale_arg__, const int& dist, const T4__& df, std::ostream*
                 pstream__) {
  using local_scalar_t__ = stan::promote_args_t<stan::base_type_t<T0__>,
                             stan::base_type_t<T1__>,
                             stan::base_type_t<T2__>, T4__>;
  int current_statement__ = 0;
  const auto& x = stan::math::to_ref(x_arg__);
  const auto& location = stan::math::to_ref(location_arg__);
  const auto& scale = stan::math::to_ref(scale_arg__);
  static constexpr bool propto__ = true;
  // suppress unused var warning
  (void) propto__;
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    current_statement__ = 112;
    if (stan::math::logical_eq(dist, 0)) {
      current_statement__ = 111;
      return stan::math::normal_lpdf<false>(x, location, scale);
    } else {
      current_statement__ = 110;
      return stan::math::student_t_lpdf<false>(x, df, location, scale);
    }
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
template <typename T0__, typename T1__, typename T2__, typename T4__,
          stan::require_all_t<stan::is_stan_scalar<T0__>,
                              stan::is_stan_scalar<T1__>,
                              stan::is_stan_scalar<T2__>,
                              stan::is_stan_scalar<T4__>>*>
stan::promote_args_t<T0__, T1__, T2__, T4__>
log_prior_sigma(const T0__& sigma, const T1__& location, const T2__& scale,
                const int& dist, const T4__& df, std::ostream* pstream__) {
  using local_scalar_t__ = stan::promote_args_t<T0__, T1__, T2__, T4__>;
  int current_statement__ = 0;
  static constexpr bool propto__ = true;
  // suppress unused var warning
  (void) propto__;
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    current_statement__ = 118;
    if (stan::math::logical_eq(dist, 0)) {
      current_statement__ = 117;
      return stan::math::normal_lpdf<false>(sigma, location, scale);
    } else {
      current_statement__ = 116;
      if (stan::math::logical_eq(dist, 1)) {
        current_statement__ = 115;
        return stan::math::student_t_lpdf<false>(sigma, df, location, scale);
      } else {
        current_statement__ = 114;
        return stan::math::exponential_lpdf<false>(sigma,
                 stan::math::inv(scale));
      }
    }
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
template <typename T0__, typename T2__,
          stan::require_all_t<stan::is_col_vector<T0__>,
                              stan::is_vt_not_complex<T0__>,
                              stan::is_stan_scalar<T2__>>*>
stan::promote_args_t<stan::base_type_t<T0__>, T2__>
log_prior_std_vector(const T0__& z_arg__, const int& dist, const T2__& df,
                     std::ostream* pstream__) {
  using local_scalar_t__ = stan::promote_args_t<stan::base_type_t<T0__>,
                             T2__>;
  int current_statement__ = 0;
  const auto& z = stan::math::to_ref(z_arg__);
  static constexpr bool propto__ = true;
  // suppress unused var warning
  (void) propto__;
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    current_statement__ = 122;
    if (stan::math::logical_eq(dist, 0)) {
      current_statement__ = 121;
      return stan::math::std_normal_lpdf<false>(z);
    } else {
      current_statement__ = 120;
      return stan::math::student_t_lpdf<false>(z, df, 0, 1);
    }
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
template <typename T0__, typename T1__,
          stan::require_all_t<stan::is_stan_scalar<T0__>,
                              stan::is_stan_scalar<T1__>>*>
stan::promote_args_t<T0__, T1__>
safe_divide(const T0__& num, const T1__& denom, std::ostream* pstream__) {
  using local_scalar_t__ = stan::promote_args_t<T0__, T1__>;
  int current_statement__ = 0;
  static constexpr bool propto__ = true;
  // suppress unused var warning
  (void) propto__;
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    current_statement__ = 124;
    return (num / stan::math::fmax(denom, 1e-10));
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
template <typename T0__, stan::require_all_t<stan::is_stan_scalar<T0__>>*>
stan::promote_args_t<T0__> safe_logit(const T0__& p, std::ostream* pstream__) {
  using local_scalar_t__ = stan::promote_args_t<T0__>;
  int current_statement__ = 0;
  static constexpr bool propto__ = true;
  // suppress unused var warning
  (void) propto__;
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    current_statement__ = 126;
    return stan::math::logit(
             stan::math::fmin(stan::math::fmax(p, 1e-10), (1 - 1e-10)));
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
template <typename T0__, stan::require_all_t<stan::is_stan_scalar<T0__>>*>
stan::promote_args_t<T0__>
inv_link_binary(const T0__& eta, const int& link_code, std::ostream*
                pstream__) {
  using local_scalar_t__ = stan::promote_args_t<T0__>;
  int current_statement__ = 0;
  static constexpr bool propto__ = true;
  // suppress unused var warning
  (void) propto__;
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    current_statement__ = 132;
    if (stan::math::logical_eq(link_code, 1)) {
      current_statement__ = 131;
      return stan::math::inv_logit(eta);
    } else {
      current_statement__ = 130;
      if (stan::math::logical_eq(link_code, 2)) {
        current_statement__ = 129;
        return stan::math::Phi(eta);
      } else {
        current_statement__ = 128;
        return (1 - stan::math::exp(-stan::math::exp(eta)));
      }
    }
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
template <typename T0__,
          stan::require_all_t<stan::is_col_vector<T0__>,
                              stan::is_vt_not_complex<T0__>>*>
Eigen::Matrix<stan::promote_args_t<stan::base_type_t<T0__>>,-1,1>
inv_link_binary_vec(const T0__& eta_arg__, const int& link_code,
                    std::ostream* pstream__) {
  using local_scalar_t__ = stan::promote_args_t<stan::base_type_t<T0__>>;
  int current_statement__ = 0;
  const auto& eta = stan::math::to_ref(eta_arg__);
  static constexpr bool propto__ = true;
  // suppress unused var warning
  (void) propto__;
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    int N = std::numeric_limits<int>::min();
    current_statement__ = 134;
    N = stan::math::num_elements(eta);
    current_statement__ = 144;
    if (stan::math::logical_eq(link_code, 1)) {
      current_statement__ = 143;
      return stan::math::inv_logit(eta);
    } else {
      current_statement__ = 142;
      if (stan::math::logical_eq(link_code, 2)) {
        current_statement__ = 141;
        return stan::math::Phi(eta);
      } else {
        current_statement__ = 135;
        stan::math::validate_non_negative_index("result", "N", N);
        Eigen::Matrix<local_scalar_t__,-1,1> result =
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N, DUMMY_VAR__);
        current_statement__ = 138;
        for (int i = 1; i <= N; ++i) {
          current_statement__ = 137;
          stan::model::assign(result, (1 -
            stan::math::exp(
              -stan::math::exp(
                 stan::model::rvalue(eta, "eta", stan::model::index_uni(i))))),
            "assigning variable result", stan::model::index_uni(i));
        }
        current_statement__ = 139;
        return result;
      }
    }
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
#include <stan_meta_header.hpp>
class model_mlumr_binary_spfa final : public model_base_crtp<model_mlumr_binary_spfa> {
private:
  int n_ipd;
  std::vector<int> y_ipd;
  int n_cov;
  Eigen::Matrix<double,-1,-1> X_ipd_data__;
  int n_agd_rows;
  std::vector<int> n_agd;
  std::vector<int> r_agd;
  int n_int;
  std::vector<Eigen::Matrix<double,-1,-1>> X_int;
  double prior_intercept_mean;
  double prior_intercept_sd;
  int prior_intercept_dist;
  double prior_intercept_df;
  Eigen::Matrix<double,-1,1> prior_beta_mean_data__;
  Eigen::Matrix<double,-1,1> prior_beta_sd_data__;
  int prior_beta_dist;
  double prior_beta_df;
  int link;
  Eigen::Map<Eigen::Matrix<double,-1,-1>> X_ipd{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> prior_beta_mean{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> prior_beta_sd{nullptr, 0};
public:
  ~model_mlumr_binary_spfa() {}
  model_mlumr_binary_spfa(stan::io::var_context& context__, unsigned int
                          random_seed__ = 0, std::ostream*
                          pstream__ = nullptr) : model_base_crtp(0) {
    int current_statement__ = 0;
    using local_scalar_t__ = double;
    boost::ecuyer1988 base_rng__ =
      stan::services::util::create_rng(random_seed__, 0);
    // suppress unused var warning
    (void) base_rng__;
    static constexpr const char* function__ =
      "model_mlumr_binary_spfa_namespace::model_mlumr_binary_spfa";
    // 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__ = 73;
      context__.validate_dims("data initialization", "n_ipd", "int",
        std::vector<size_t>{});
      n_ipd = std::numeric_limits<int>::min();
      current_statement__ = 73;
      n_ipd = context__.vals_i("n_ipd")[(1 - 1)];
      current_statement__ = 73;
      stan::math::check_greater_or_equal(function__, "n_ipd", n_ipd, 0);
      current_statement__ = 74;
      stan::math::validate_non_negative_index("y_ipd", "n_ipd", n_ipd);
      current_statement__ = 75;
      context__.validate_dims("data initialization", "y_ipd", "int",
        std::vector<size_t>{static_cast<size_t>(n_ipd)});
      y_ipd = std::vector<int>(n_ipd, std::numeric_limits<int>::min());
      current_statement__ = 75;
      y_ipd = context__.vals_i("y_ipd");
      current_statement__ = 75;
      stan::math::check_greater_or_equal(function__, "y_ipd", y_ipd, 0);
      current_statement__ = 75;
      stan::math::check_less_or_equal(function__, "y_ipd", y_ipd, 1);
      current_statement__ = 76;
      context__.validate_dims("data initialization", "n_cov", "int",
        std::vector<size_t>{});
      n_cov = std::numeric_limits<int>::min();
      current_statement__ = 76;
      n_cov = context__.vals_i("n_cov")[(1 - 1)];
      current_statement__ = 76;
      stan::math::check_greater_or_equal(function__, "n_cov", n_cov, 1);
      current_statement__ = 77;
      stan::math::validate_non_negative_index("X_ipd", "n_ipd", n_ipd);
      current_statement__ = 78;
      stan::math::validate_non_negative_index("X_ipd", "n_cov", n_cov);
      current_statement__ = 79;
      context__.validate_dims("data initialization", "X_ipd", "double",
        std::vector<size_t>{static_cast<size_t>(n_ipd),
          static_cast<size_t>(n_cov)});
      X_ipd_data__ = Eigen::Matrix<double,-1,-1>::Constant(n_ipd, n_cov,
                       std::numeric_limits<double>::quiet_NaN());
      new (&X_ipd)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(X_ipd_data__.data(), n_ipd,
        n_cov);
      {
        std::vector<local_scalar_t__> X_ipd_flat__;
        current_statement__ = 79;
        X_ipd_flat__ = context__.vals_r("X_ipd");
        current_statement__ = 79;
        pos__ = 1;
        current_statement__ = 79;
        for (int sym1__ = 1; sym1__ <= n_cov; ++sym1__) {
          current_statement__ = 79;
          for (int sym2__ = 1; sym2__ <= n_ipd; ++sym2__) {
            current_statement__ = 79;
            stan::model::assign(X_ipd, X_ipd_flat__[(pos__ - 1)],
              "assigning variable X_ipd", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 79;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 80;
      context__.validate_dims("data initialization", "n_agd_rows", "int",
        std::vector<size_t>{});
      n_agd_rows = std::numeric_limits<int>::min();
      current_statement__ = 80;
      n_agd_rows = context__.vals_i("n_agd_rows")[(1 - 1)];
      current_statement__ = 80;
      stan::math::check_greater_or_equal(function__, "n_agd_rows",
        n_agd_rows, 1);
      current_statement__ = 81;
      stan::math::validate_non_negative_index("n_agd", "n_agd_rows",
        n_agd_rows);
      current_statement__ = 82;
      context__.validate_dims("data initialization", "n_agd", "int",
        std::vector<size_t>{static_cast<size_t>(n_agd_rows)});
      n_agd = std::vector<int>(n_agd_rows, std::numeric_limits<int>::min());
      current_statement__ = 82;
      n_agd = context__.vals_i("n_agd");
      current_statement__ = 82;
      stan::math::check_greater_or_equal(function__, "n_agd", n_agd, 1);
      current_statement__ = 83;
      stan::math::validate_non_negative_index("r_agd", "n_agd_rows",
        n_agd_rows);
      current_statement__ = 84;
      context__.validate_dims("data initialization", "r_agd", "int",
        std::vector<size_t>{static_cast<size_t>(n_agd_rows)});
      r_agd = std::vector<int>(n_agd_rows, std::numeric_limits<int>::min());
      current_statement__ = 84;
      r_agd = context__.vals_i("r_agd");
      current_statement__ = 84;
      stan::math::check_greater_or_equal(function__, "r_agd", r_agd, 0);
      current_statement__ = 85;
      context__.validate_dims("data initialization", "n_int", "int",
        std::vector<size_t>{});
      n_int = std::numeric_limits<int>::min();
      current_statement__ = 85;
      n_int = context__.vals_i("n_int")[(1 - 1)];
      current_statement__ = 85;
      stan::math::check_greater_or_equal(function__, "n_int", n_int, 1);
      current_statement__ = 86;
      stan::math::validate_non_negative_index("X_int", "n_agd_rows",
        n_agd_rows);
      current_statement__ = 87;
      stan::math::validate_non_negative_index("X_int", "n_int", n_int);
      current_statement__ = 88;
      stan::math::validate_non_negative_index("X_int", "n_cov", n_cov);
      current_statement__ = 89;
      context__.validate_dims("data initialization", "X_int", "double",
        std::vector<size_t>{static_cast<size_t>(n_agd_rows),
          static_cast<size_t>(n_int), static_cast<size_t>(n_cov)});
      X_int = std::vector<Eigen::Matrix<double,-1,-1>>(n_agd_rows,
                Eigen::Matrix<double,-1,-1>::Constant(n_int, n_cov,
                  std::numeric_limits<double>::quiet_NaN()));
      {
        std::vector<local_scalar_t__> X_int_flat__;
        current_statement__ = 89;
        X_int_flat__ = context__.vals_r("X_int");
        current_statement__ = 89;
        pos__ = 1;
        current_statement__ = 89;
        for (int sym1__ = 1; sym1__ <= n_cov; ++sym1__) {
          current_statement__ = 89;
          for (int sym2__ = 1; sym2__ <= n_int; ++sym2__) {
            current_statement__ = 89;
            for (int sym3__ = 1; sym3__ <= n_agd_rows; ++sym3__) {
              current_statement__ = 89;
              stan::model::assign(X_int, X_int_flat__[(pos__ - 1)],
                "assigning variable X_int", stan::model::index_uni(sym3__),
                stan::model::index_uni(sym2__),
                stan::model::index_uni(sym1__));
              current_statement__ = 89;
              pos__ = (pos__ + 1);
            }
          }
        }
      }
      current_statement__ = 90;
      context__.validate_dims("data initialization", "prior_intercept_mean",
        "double", std::vector<size_t>{});
      prior_intercept_mean = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 90;
      prior_intercept_mean = context__.vals_r("prior_intercept_mean")[(1 -
        1)];
      current_statement__ = 91;
      context__.validate_dims("data initialization", "prior_intercept_sd",
        "double", std::vector<size_t>{});
      prior_intercept_sd = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 91;
      prior_intercept_sd = context__.vals_r("prior_intercept_sd")[(1 - 1)];
      current_statement__ = 91;
      stan::math::check_greater_or_equal(function__, "prior_intercept_sd",
        prior_intercept_sd, 0);
      current_statement__ = 92;
      context__.validate_dims("data initialization", "prior_intercept_dist",
        "int", std::vector<size_t>{});
      prior_intercept_dist = std::numeric_limits<int>::min();
      current_statement__ = 92;
      prior_intercept_dist = context__.vals_i("prior_intercept_dist")[(1 -
        1)];
      current_statement__ = 92;
      stan::math::check_greater_or_equal(function__, "prior_intercept_dist",
        prior_intercept_dist, 0);
      current_statement__ = 92;
      stan::math::check_less_or_equal(function__, "prior_intercept_dist",
        prior_intercept_dist, 1);
      current_statement__ = 93;
      context__.validate_dims("data initialization", "prior_intercept_df",
        "double", std::vector<size_t>{});
      prior_intercept_df = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 93;
      prior_intercept_df = context__.vals_r("prior_intercept_df")[(1 - 1)];
      current_statement__ = 93;
      stan::math::check_greater_or_equal(function__, "prior_intercept_df",
        prior_intercept_df, 0);
      current_statement__ = 94;
      stan::math::validate_non_negative_index("prior_beta_mean", "n_cov",
        n_cov);
      current_statement__ = 95;
      context__.validate_dims("data initialization", "prior_beta_mean",
        "double", std::vector<size_t>{static_cast<size_t>(n_cov)});
      prior_beta_mean_data__ = Eigen::Matrix<double,-1,1>::Constant(n_cov,
                                 std::numeric_limits<double>::quiet_NaN());
      new (&prior_beta_mean)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(prior_beta_mean_data__.data(),
        n_cov);
      {
        std::vector<local_scalar_t__> prior_beta_mean_flat__;
        current_statement__ = 95;
        prior_beta_mean_flat__ = context__.vals_r("prior_beta_mean");
        current_statement__ = 95;
        pos__ = 1;
        current_statement__ = 95;
        for (int sym1__ = 1; sym1__ <= n_cov; ++sym1__) {
          current_statement__ = 95;
          stan::model::assign(prior_beta_mean, prior_beta_mean_flat__[(pos__
            - 1)], "assigning variable prior_beta_mean",
            stan::model::index_uni(sym1__));
          current_statement__ = 95;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 96;
      stan::math::validate_non_negative_index("prior_beta_sd", "n_cov", n_cov);
      current_statement__ = 97;
      context__.validate_dims("data initialization", "prior_beta_sd",
        "double", std::vector<size_t>{static_cast<size_t>(n_cov)});
      prior_beta_sd_data__ = Eigen::Matrix<double,-1,1>::Constant(n_cov,
                               std::numeric_limits<double>::quiet_NaN());
      new (&prior_beta_sd)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(prior_beta_sd_data__.data(),
        n_cov);
      {
        std::vector<local_scalar_t__> prior_beta_sd_flat__;
        current_statement__ = 97;
        prior_beta_sd_flat__ = context__.vals_r("prior_beta_sd");
        current_statement__ = 97;
        pos__ = 1;
        current_statement__ = 97;
        for (int sym1__ = 1; sym1__ <= n_cov; ++sym1__) {
          current_statement__ = 97;
          stan::model::assign(prior_beta_sd, prior_beta_sd_flat__[(pos__ -
            1)], "assigning variable prior_beta_sd",
            stan::model::index_uni(sym1__));
          current_statement__ = 97;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 97;
      stan::math::check_greater_or_equal(function__, "prior_beta_sd",
        prior_beta_sd, 0);
      current_statement__ = 98;
      context__.validate_dims("data initialization", "prior_beta_dist",
        "int", std::vector<size_t>{});
      prior_beta_dist = std::numeric_limits<int>::min();
      current_statement__ = 98;
      prior_beta_dist = context__.vals_i("prior_beta_dist")[(1 - 1)];
      current_statement__ = 98;
      stan::math::check_greater_or_equal(function__, "prior_beta_dist",
        prior_beta_dist, 0);
      current_statement__ = 98;
      stan::math::check_less_or_equal(function__, "prior_beta_dist",
        prior_beta_dist, 1);
      current_statement__ = 99;
      context__.validate_dims("data initialization", "prior_beta_df",
        "double", std::vector<size_t>{});
      prior_beta_df = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 99;
      prior_beta_df = context__.vals_r("prior_beta_df")[(1 - 1)];
      current_statement__ = 99;
      stan::math::check_greater_or_equal(function__, "prior_beta_df",
        prior_beta_df, 0);
      current_statement__ = 100;
      context__.validate_dims("data initialization", "link", "int",
        std::vector<size_t>{});
      link = std::numeric_limits<int>::min();
      current_statement__ = 100;
      link = context__.vals_i("link")[(1 - 1)];
      current_statement__ = 100;
      stan::math::check_greater_or_equal(function__, "link", link, 1);
      current_statement__ = 100;
      stan::math::check_less_or_equal(function__, "link", link, 3);
      current_statement__ = 101;
      stan::math::validate_non_negative_index("z_beta", "n_cov", n_cov);
      current_statement__ = 102;
      stan::math::validate_non_negative_index("beta", "n_cov", n_cov);
      current_statement__ = 103;
      stan::math::validate_non_negative_index("eta_ipd", "n_ipd", n_ipd);
      current_statement__ = 104;
      stan::math::validate_non_negative_index("log_lik_ipd", "n_ipd", n_ipd);
      current_statement__ = 105;
      stan::math::validate_non_negative_index("log_lik_agd", "n_agd_rows",
        n_agd_rows);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    num_params_r__ = 1 + 1 + n_cov;
  }
  inline std::string model_name() const final {
    return "model_mlumr_binary_spfa";
  }
  inline std::vector<std::string> model_compile_info() const noexcept {
    return std::vector<std::string>{"stanc_version = stanc3 v2.32.2",
             "stancflags = --allow-undefined"};
  }
  template <bool propto__, bool jacobian__, typename VecR, typename VecI,
            stan::require_vector_like_t<VecR>* = nullptr,
            stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
  inline stan::scalar_type_t<VecR>
  log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream*
                pstream__ = nullptr) const {
    using T__ = stan::scalar_type_t<VecR>;
    using local_scalar_t__ = T__;
    T__ lp__(0.0);
    stan::math::accumulator<T__> lp_accum__;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    int current_statement__ = 0;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    static constexpr const char* function__ =
      "model_mlumr_binary_spfa_namespace::log_prob";
    // suppress unused var warning
    (void) function__;
    try {
      local_scalar_t__ mu_index = DUMMY_VAR__;
      current_statement__ = 1;
      mu_index = in__.template read<local_scalar_t__>();
      local_scalar_t__ mu_comparator = DUMMY_VAR__;
      current_statement__ = 2;
      mu_comparator = in__.template read<local_scalar_t__>();
      Eigen::Matrix<local_scalar_t__,-1,1> z_beta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_cov, DUMMY_VAR__);
      current_statement__ = 3;
      z_beta = in__.template read<
                 Eigen::Matrix<local_scalar_t__,-1,1>>(n_cov);
      Eigen::Matrix<local_scalar_t__,-1,1> beta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_cov, DUMMY_VAR__);
      current_statement__ = 4;
      stan::model::assign(beta,
        stan::math::add(prior_beta_mean,
          stan::math::elt_multiply(prior_beta_sd, z_beta)),
        "assigning variable beta");
      Eigen::Matrix<local_scalar_t__,-1,1> eta_ipd =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_ipd, DUMMY_VAR__);
      current_statement__ = 5;
      stan::model::assign(eta_ipd,
        stan::math::add(mu_index, stan::math::multiply(X_ipd, beta)),
        "assigning variable eta_ipd");
      {
        current_statement__ = 61;
        lp_accum__.add(log_prior_scalar(mu_index, prior_intercept_mean,
                         prior_intercept_sd, prior_intercept_dist,
                         prior_intercept_df, pstream__));
        current_statement__ = 62;
        lp_accum__.add(log_prior_scalar(mu_comparator, prior_intercept_mean,
                         prior_intercept_sd, prior_intercept_dist,
                         prior_intercept_df, pstream__));
        current_statement__ = 63;
        lp_accum__.add(log_prior_std_vector(z_beta, prior_beta_dist,
                         prior_beta_df, pstream__));
        current_statement__ = 66;
        if (stan::math::logical_eq(link, 1)) {
          current_statement__ = 65;
          lp_accum__.add(stan::math::bernoulli_logit_lpmf<propto__>(y_ipd,
                           eta_ipd));
        } else {
          current_statement__ = 64;
          lp_accum__.add(stan::math::bernoulli_lpmf<propto__>(y_ipd,
                           inv_link_binary_vec(eta_ipd, link, pstream__)));
        }
        current_statement__ = 72;
        for (int k = 1; k <= n_agd_rows; ++k) {
          current_statement__ = 67;
          stan::math::validate_non_negative_index("p_int", "n_int", n_int);
          Eigen::Matrix<local_scalar_t__,-1,1> p_int =
            Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_int,
              DUMMY_VAR__);
          current_statement__ = 68;
          stan::model::assign(p_int,
            inv_link_binary_vec(
              stan::math::add(mu_comparator,
                stan::math::multiply(
                  stan::model::rvalue(X_int, "X_int",
                    stan::model::index_uni(k)), beta)), link, pstream__),
            "assigning variable p_int");
          local_scalar_t__ p_mean = DUMMY_VAR__;
          current_statement__ = 69;
          p_mean = stan::math::mean(p_int);
          current_statement__ = 70;
          lp_accum__.add(stan::math::binomial_lpmf<propto__>(
                           stan::model::rvalue(r_agd, "r_agd",
                             stan::model::index_uni(k)),
                           stan::model::rvalue(n_agd, "n_agd",
                             stan::model::index_uni(k)), p_mean));
        }
      }
    } 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;
    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;
    static constexpr const char* function__ =
      "model_mlumr_binary_spfa_namespace::write_array";
    // suppress unused var warning
    (void) function__;
    try {
      double mu_index = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 1;
      mu_index = in__.template read<local_scalar_t__>();
      double mu_comparator = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 2;
      mu_comparator = in__.template read<local_scalar_t__>();
      Eigen::Matrix<double,-1,1> z_beta =
        Eigen::Matrix<double,-1,1>::Constant(n_cov,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 3;
      z_beta = in__.template read<
                 Eigen::Matrix<local_scalar_t__,-1,1>>(n_cov);
      Eigen::Matrix<double,-1,1> beta =
        Eigen::Matrix<double,-1,1>::Constant(n_cov,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> eta_ipd =
        Eigen::Matrix<double,-1,1>::Constant(n_ipd,
          std::numeric_limits<double>::quiet_NaN());
      out__.write(mu_index);
      out__.write(mu_comparator);
      out__.write(z_beta);
      if (stan::math::logical_negation(
            (stan::math::primitive_value(emit_transformed_parameters__) ||
            stan::math::primitive_value(emit_generated_quantities__)))) {
        return ;
      }
      current_statement__ = 4;
      stan::model::assign(beta,
        stan::math::add(prior_beta_mean,
          stan::math::elt_multiply(prior_beta_sd, z_beta)),
        "assigning variable beta");
      current_statement__ = 5;
      stan::model::assign(eta_ipd,
        stan::math::add(mu_index, stan::math::multiply(X_ipd, beta)),
        "assigning variable eta_ipd");
      if (emit_transformed_parameters__) {
        out__.write(beta);
        out__.write(eta_ipd);
      }
      if (stan::math::logical_negation(emit_generated_quantities__)) {
        return ;
      }
      double lor_index = std::numeric_limits<double>::quiet_NaN();
      double lor_comparator = std::numeric_limits<double>::quiet_NaN();
      double rd_index = std::numeric_limits<double>::quiet_NaN();
      double rd_comparator = std::numeric_limits<double>::quiet_NaN();
      double rr_index = std::numeric_limits<double>::quiet_NaN();
      double rr_comparator = std::numeric_limits<double>::quiet_NaN();
      double p_index_index = std::numeric_limits<double>::quiet_NaN();
      double p_comparator_index = std::numeric_limits<double>::quiet_NaN();
      double p_index_comparator = std::numeric_limits<double>::quiet_NaN();
      double p_comparator_comparator =
        std::numeric_limits<double>::quiet_NaN();
      Eigen::Matrix<double,-1,1> log_lik_ipd =
        Eigen::Matrix<double,-1,1>::Constant(n_ipd,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> log_lik_agd =
        Eigen::Matrix<double,-1,1>::Constant(n_agd_rows,
          std::numeric_limits<double>::quiet_NaN());
      {
        current_statement__ = 18;
        stan::math::validate_non_negative_index("p_index_vec", "n_ipd", n_ipd);
        Eigen::Matrix<double,-1,1> p_index_vec =
          Eigen::Matrix<double,-1,1>::Constant(n_ipd,
            std::numeric_limits<double>::quiet_NaN());
        current_statement__ = 19;
        stan::model::assign(p_index_vec,
          inv_link_binary_vec(eta_ipd, link, pstream__),
          "assigning variable p_index_vec");
        current_statement__ = 20;
        stan::math::validate_non_negative_index("p_comparator_vec", "n_ipd",
          n_ipd);
        Eigen::Matrix<double,-1,1> p_comparator_vec =
          Eigen::Matrix<double,-1,1>::Constant(n_ipd,
            std::numeric_limits<double>::quiet_NaN());
        current_statement__ = 21;
        stan::model::assign(p_comparator_vec,
          inv_link_binary_vec(
            stan::math::add(mu_comparator, stan::math::multiply(X_ipd, beta)),
            link, pstream__), "assigning variable p_comparator_vec");
        current_statement__ = 22;
        p_index_index = stan::math::mean(p_index_vec);
        current_statement__ = 23;
        p_comparator_index = stan::math::mean(p_comparator_vec);
      }
      {
        double p_index_comp_sum = std::numeric_limits<double>::quiet_NaN();
        current_statement__ = 25;
        p_index_comp_sum = 0;
        double p_comp_comp_sum = std::numeric_limits<double>::quiet_NaN();
        current_statement__ = 26;
        p_comp_comp_sum = 0;
        double total_n = std::numeric_limits<double>::quiet_NaN();
        current_statement__ = 27;
        total_n = 0;
        current_statement__ = 36;
        for (int k = 1; k <= n_agd_rows; ++k) {
          current_statement__ = 28;
          stan::math::validate_non_negative_index("p_idx_k", "n_int", n_int);
          Eigen::Matrix<double,-1,1> p_idx_k =
            Eigen::Matrix<double,-1,1>::Constant(n_int,
              std::numeric_limits<double>::quiet_NaN());
          current_statement__ = 29;
          stan::model::assign(p_idx_k,
            inv_link_binary_vec(
              stan::math::add(mu_index,
                stan::math::multiply(
                  stan::model::rvalue(X_int, "X_int",
                    stan::model::index_uni(k)), beta)), link, pstream__),
            "assigning variable p_idx_k");
          current_statement__ = 30;
          stan::math::validate_non_negative_index("p_cmp_k", "n_int", n_int);
          Eigen::Matrix<double,-1,1> p_cmp_k =
            Eigen::Matrix<double,-1,1>::Constant(n_int,
              std::numeric_limits<double>::quiet_NaN());
          current_statement__ = 31;
          stan::model::assign(p_cmp_k,
            inv_link_binary_vec(
              stan::math::add(mu_comparator,
                stan::math::multiply(
                  stan::model::rvalue(X_int, "X_int",
                    stan::model::index_uni(k)), beta)), link, pstream__),
            "assigning variable p_cmp_k");
          current_statement__ = 32;
          p_index_comp_sum = (p_index_comp_sum + (stan::math::mean(p_idx_k) *
            stan::model::rvalue(n_agd, "n_agd", stan::model::index_uni(k))));
          current_statement__ = 33;
          p_comp_comp_sum = (p_comp_comp_sum + (stan::math::mean(p_cmp_k) *
            stan::model::rvalue(n_agd, "n_agd", stan::model::index_uni(k))));
          current_statement__ = 34;
          total_n = (total_n +
            stan::model::rvalue(n_agd, "n_agd", stan::model::index_uni(k)));
        }
        current_statement__ = 37;
        p_index_comparator = (p_index_comp_sum / total_n);
        current_statement__ = 38;
        p_comparator_comparator = (p_comp_comp_sum / total_n);
      }
      current_statement__ = 40;
      lor_index = (safe_logit(p_index_index, pstream__) -
        safe_logit(p_comparator_index, pstream__));
      current_statement__ = 41;
      lor_comparator = (safe_logit(p_index_comparator, pstream__) -
        safe_logit(p_comparator_comparator, pstream__));
      current_statement__ = 42;
      rd_index = (p_index_index - p_comparator_index);
      current_statement__ = 43;
      rd_comparator = (p_index_comparator - p_comparator_comparator);
      current_statement__ = 44;
      rr_index = safe_divide(p_index_index, p_comparator_index, pstream__);
      current_statement__ = 45;
      rr_comparator = safe_divide(p_index_comparator,
                        p_comparator_comparator, pstream__);
      current_statement__ = 54;
      if (stan::math::logical_eq(link, 1)) {
        current_statement__ = 52;
        for (int i = 1; i <= n_ipd; ++i) {
          current_statement__ = 51;
          stan::model::assign(log_lik_ipd,
            stan::math::bernoulli_logit_lpmf<false>(
              stan::model::rvalue(y_ipd, "y_ipd", stan::model::index_uni(i)),
              stan::model::rvalue(eta_ipd, "eta_ipd",
                stan::model::index_uni(i))),
            "assigning variable log_lik_ipd", stan::model::index_uni(i));
        }
      } else {
        current_statement__ = 46;
        stan::math::validate_non_negative_index("p_ipd", "n_ipd", n_ipd);
        Eigen::Matrix<double,-1,1> p_ipd =
          Eigen::Matrix<double,-1,1>::Constant(n_ipd,
            std::numeric_limits<double>::quiet_NaN());
        current_statement__ = 47;
        stan::model::assign(p_ipd,
          inv_link_binary_vec(eta_ipd, link, pstream__),
          "assigning variable p_ipd");
        current_statement__ = 49;
        for (int i = 1; i <= n_ipd; ++i) {
          current_statement__ = 48;
          stan::model::assign(log_lik_ipd,
            stan::math::bernoulli_lpmf<false>(
              stan::model::rvalue(y_ipd, "y_ipd", stan::model::index_uni(i)),
              stan::model::rvalue(p_ipd, "p_ipd", stan::model::index_uni(i))),
            "assigning variable log_lik_ipd", stan::model::index_uni(i));
        }
      }
      current_statement__ = 60;
      for (int k = 1; k <= n_agd_rows; ++k) {
        current_statement__ = 55;
        stan::math::validate_non_negative_index("p_int", "n_int", n_int);
        Eigen::Matrix<double,-1,1> p_int =
          Eigen::Matrix<double,-1,1>::Constant(n_int,
            std::numeric_limits<double>::quiet_NaN());
        current_statement__ = 56;
        stan::model::assign(p_int,
          inv_link_binary_vec(
            stan::math::add(mu_comparator,
              stan::math::multiply(
                stan::model::rvalue(X_int, "X_int", stan::model::index_uni(k)),
                beta)), link, pstream__), "assigning variable p_int");
        double p_mean = std::numeric_limits<double>::quiet_NaN();
        current_statement__ = 57;
        p_mean = stan::math::mean(p_int);
        current_statement__ = 58;
        stan::model::assign(log_lik_agd,
          stan::math::binomial_lpmf<false>(
            stan::model::rvalue(r_agd, "r_agd", stan::model::index_uni(k)),
            stan::model::rvalue(n_agd, "n_agd", stan::model::index_uni(k)),
            p_mean), "assigning variable log_lik_agd",
          stan::model::index_uni(k));
      }
      out__.write(lor_index);
      out__.write(lor_comparator);
      out__.write(rd_index);
      out__.write(rd_comparator);
      out__.write(rr_index);
      out__.write(rr_comparator);
      out__.write(p_index_index);
      out__.write(p_comparator_index);
      out__.write(p_index_comparator);
      out__.write(p_comparator_comparator);
      out__.write(log_lik_ipd);
      out__.write(log_lik_agd);
    } 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;
    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;
      local_scalar_t__ mu_index = DUMMY_VAR__;
      current_statement__ = 1;
      mu_index = in__.read<local_scalar_t__>();
      out__.write(mu_index);
      local_scalar_t__ mu_comparator = DUMMY_VAR__;
      current_statement__ = 2;
      mu_comparator = in__.read<local_scalar_t__>();
      out__.write(mu_comparator);
      Eigen::Matrix<local_scalar_t__,-1,1> z_beta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_cov, DUMMY_VAR__);
      current_statement__ = 3;
      stan::model::assign(z_beta,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(n_cov),
        "assigning variable z_beta");
      out__.write(z_beta);
    } 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;
    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", "mu_index",
        "double", std::vector<size_t>{});
      current_statement__ = 2;
      context__.validate_dims("parameter initialization", "mu_comparator",
        "double", std::vector<size_t>{});
      current_statement__ = 3;
      context__.validate_dims("parameter initialization", "z_beta", "double",
        std::vector<size_t>{static_cast<size_t>(n_cov)});
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      local_scalar_t__ mu_index = DUMMY_VAR__;
      current_statement__ = 1;
      mu_index = context__.vals_r("mu_index")[(1 - 1)];
      out__.write(mu_index);
      local_scalar_t__ mu_comparator = DUMMY_VAR__;
      current_statement__ = 2;
      mu_comparator = context__.vals_r("mu_comparator")[(1 - 1)];
      out__.write(mu_comparator);
      Eigen::Matrix<local_scalar_t__,-1,1> z_beta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_cov, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> z_beta_flat__;
        current_statement__ = 3;
        z_beta_flat__ = context__.vals_r("z_beta");
        current_statement__ = 3;
        pos__ = 1;
        current_statement__ = 3;
        for (int sym1__ = 1; sym1__ <= n_cov; ++sym1__) {
          current_statement__ = 3;
          stan::model::assign(z_beta, z_beta_flat__[(pos__ - 1)],
            "assigning variable z_beta", stan::model::index_uni(sym1__));
          current_statement__ = 3;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(z_beta);
    } 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>{"mu_index", "mu_comparator", "z_beta"};
    if (emit_transformed_parameters__) {
      std::vector<std::string> temp{"beta", "eta_ipd"};
      names__.reserve(names__.size() + temp.size());
      names__.insert(names__.end(), temp.begin(), temp.end());
    }
    if (emit_generated_quantities__) {
      std::vector<std::string>
        temp{"lor_index", "lor_comparator", "rd_index", "rd_comparator",
             "rr_index", "rr_comparator", "p_index_index",
             "p_comparator_index", "p_index_comparator",
             "p_comparator_comparator", "log_lik_ipd", "log_lik_agd"};
      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>{},
                std::vector<size_t>{},
                std::vector<size_t>{static_cast<size_t>(n_cov)}};
    if (emit_transformed_parameters__) {
      std::vector<std::vector<size_t>>
        temp{std::vector<size_t>{static_cast<size_t>(n_cov)},
             std::vector<size_t>{static_cast<size_t>(n_ipd)}};
      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>{},
             std::vector<size_t>{}, std::vector<size_t>{},
             std::vector<size_t>{}, std::vector<size_t>{},
             std::vector<size_t>{}, std::vector<size_t>{},
             std::vector<size_t>{}, std::vector<size_t>{},
             std::vector<size_t>{static_cast<size_t>(n_ipd)},
             std::vector<size_t>{static_cast<size_t>(n_agd_rows)}};
      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 {
    param_names__.emplace_back(std::string() + "mu_index");
    param_names__.emplace_back(std::string() + "mu_comparator");
    for (int sym1__ = 1; sym1__ <= n_cov; ++sym1__) {
      param_names__.emplace_back(std::string() + "z_beta" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= n_cov; ++sym1__) {
        param_names__.emplace_back(std::string() + "beta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= n_ipd; ++sym1__) {
        param_names__.emplace_back(std::string() + "eta_ipd" + '.' +
          std::to_string(sym1__));
      }
    }
    if (emit_generated_quantities__) {
      param_names__.emplace_back(std::string() + "lor_index");
      param_names__.emplace_back(std::string() + "lor_comparator");
      param_names__.emplace_back(std::string() + "rd_index");
      param_names__.emplace_back(std::string() + "rd_comparator");
      param_names__.emplace_back(std::string() + "rr_index");
      param_names__.emplace_back(std::string() + "rr_comparator");
      param_names__.emplace_back(std::string() + "p_index_index");
      param_names__.emplace_back(std::string() + "p_comparator_index");
      param_names__.emplace_back(std::string() + "p_index_comparator");
      param_names__.emplace_back(std::string() + "p_comparator_comparator");
      for (int sym1__ = 1; sym1__ <= n_ipd; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_lik_ipd" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= n_agd_rows; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_lik_agd" + '.' +
          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 {
    param_names__.emplace_back(std::string() + "mu_index");
    param_names__.emplace_back(std::string() + "mu_comparator");
    for (int sym1__ = 1; sym1__ <= n_cov; ++sym1__) {
      param_names__.emplace_back(std::string() + "z_beta" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= n_cov; ++sym1__) {
        param_names__.emplace_back(std::string() + "beta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= n_ipd; ++sym1__) {
        param_names__.emplace_back(std::string() + "eta_ipd" + '.' +
          std::to_string(sym1__));
      }
    }
    if (emit_generated_quantities__) {
      param_names__.emplace_back(std::string() + "lor_index");
      param_names__.emplace_back(std::string() + "lor_comparator");
      param_names__.emplace_back(std::string() + "rd_index");
      param_names__.emplace_back(std::string() + "rd_comparator");
      param_names__.emplace_back(std::string() + "rr_index");
      param_names__.emplace_back(std::string() + "rr_comparator");
      param_names__.emplace_back(std::string() + "p_index_index");
      param_names__.emplace_back(std::string() + "p_comparator_index");
      param_names__.emplace_back(std::string() + "p_index_comparator");
      param_names__.emplace_back(std::string() + "p_comparator_comparator");
      for (int sym1__ = 1; sym1__ <= n_ipd; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_lik_ipd" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= n_agd_rows; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_lik_agd" + '.' +
          std::to_string(sym1__));
      }
    }
  }
  inline std::string get_constrained_sizedtypes() const {
    return std::string("[{\"name\":\"mu_index\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"mu_comparator\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"z_beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_cov) + "},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_cov) + "},\"block\":\"transformed_parameters\"},{\"name\":\"eta_ipd\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_ipd) + "},\"block\":\"transformed_parameters\"},{\"name\":\"lor_index\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"lor_comparator\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"rd_index\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"rd_comparator\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"rr_index\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"rr_comparator\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"p_index_index\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"p_comparator_index\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"p_index_comparator\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"p_comparator_comparator\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"log_lik_ipd\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_ipd) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik_agd\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_agd_rows) + "},\"block\":\"generated_quantities\"}]");
  }
  inline std::string get_unconstrained_sizedtypes() const {
    return std::string("[{\"name\":\"mu_index\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"mu_comparator\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"z_beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_cov) + "},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_cov) + "},\"block\":\"transformed_parameters\"},{\"name\":\"eta_ipd\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_ipd) + "},\"block\":\"transformed_parameters\"},{\"name\":\"lor_index\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"lor_comparator\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"rd_index\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"rd_comparator\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"rr_index\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"rr_comparator\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"p_index_index\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"p_comparator_index\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"p_index_comparator\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"p_comparator_comparator\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"log_lik_ipd\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_ipd) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik_agd\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_agd_rows) + "},\"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__ = ((1 + 1) + n_cov);
    const size_t num_transformed = emit_transformed_parameters * ((n_cov +
      n_ipd));
    const size_t num_gen_quantities = emit_generated_quantities *
      ((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + n_ipd) +
      n_agd_rows));
    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__ = ((1 + 1) + n_cov);
    const size_t num_transformed = emit_transformed_parameters * ((n_cov +
      n_ipd));
    const size_t num_gen_quantities = emit_generated_quantities *
      ((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + n_ipd) +
      n_agd_rows));
    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_mlumr_binary_spfa_namespace::model_mlumr_binary_spfa;
#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_mlumr_binary_spfa_namespace::profiles__;
}
#endif
#endif
