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

/*
    multinma 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.

    multinma 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 multinma.  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.32.2
#include <stan/model/model_header.hpp>
namespace model_ordered_multinomial_namespace {
using stan::model::model_base_crtp;
using namespace stan::math;
stan::math::profile_map profiles__;
static constexpr std::array<const char*, 705> locations_array__ =
  {" (found before start of program)",
  " (in 'string', line 293, column 0 to column 22)",
  " (in 'string', line 296, column 0 to column 24)",
  " (in 'string', line 297, column 0 to column 34)",
  " (in 'string', line 300, column 0 to column 53)",
  " (in 'string', line 301, column 0 to column 63)",
  " (in 'string', line 304, column 0 to column 49)",
  " (in 'string', line 307, column 2 to column 34)",
  " (in 'string', line 310, column 2 to column 22)",
  " (in 'string', line 311, column 2 to column 39)",
  " (in 'string', line 312, column 2 to column 93)",
  " (in 'string', line 313, column 2 to column 47)",
  " (in 'string', line 314, column 2 to column 51)",
  " (in 'string', line 319, column 0 to column 23)",
  " (in 'string', line 324, column 0 to line 329, column 14)",
  " (in 'string', line 332, column 0 to column 54)",
  " (in 'string', line 335, column 0 to column 58)",
  " (in 'string', line 337, column 0 to column 17)",
  " (in 'string', line 339, column 0 to column 56)",
  " (in 'string', line 341, column 0 to column 24)",
  " (in 'string', line 343, column 0 to column 47)",
  " (in 'string', line 348, column 0 to column 70)",
  " (in 'string', line 349, column 0 to column 45)",
  " (in 'string', line 766, column 2 to column 40)",
  " (in 'string', line 767, column 2 to column 48)",
  " (in 'string', line 768, column 2 to column 109)",
  " (in 'string', line 773, column 0 to column 54)",
  " (in 'string', line 774, column 0 to column 53)",
  " (in 'string', line 775, column 0 to column 44)",
  " (in 'string', line 778, column 2 to column 66)",
  " (in 'string', line 782, column 0 to column 22)",
  " (in 'string', line 355, column 2 to column 24)",
  " (in 'string', line 354, column 11 to line 356, column 1)",
  " (in 'string', line 354, column 0 to line 356, column 1)",
  " (in 'string', line 361, column 2 to column 44)",
  " (in 'string', line 360, column 39 to line 362, column 1)",
  " (in 'string', line 360, column 0 to line 362, column 1)",
  " (in 'string', line 367, column 2 to column 33)",
  " (in 'string', line 366, column 15 to line 368, column 1)",
  " (in 'string', line 366, column 0 to line 368, column 1)",
  " (in 'string', line 372, column 2 to column 123)",
  " (in 'string', line 373, column 2 to column 113)",
  " (in 'string', line 371, column 19 to line 374, column 1)",
  " (in 'string', line 371, column 0 to line 374, column 1)",
  " (in 'string', line 396, column 4 to line 398, column 23)",
  " (in 'string', line 395, column 9 to line 399, column 3)",
  " (in 'string', line 384, column 13 to column 19)",
  " (in 'string', line 384, column 6 to line 386, column 25)",
  " (in 'string', line 392, column 8 to column 37)",
  " (in 'string', line 390, column 8 to column 69)",
  " (in 'string', line 389, column 8 to line 392, column 37)",
  " (in 'string', line 388, column 26 to line 393, column 7)",
  " (in 'string', line 388, column 6 to line 393, column 7)",
  " (in 'string', line 383, column 4 to line 394, column 5)",
  " (in 'string', line 382, column 10 to line 395, column 3)",
  " (in 'string', line 382, column 2 to line 399, column 3)",
  " (in 'string', line 406, column 4 to column 97)",
  " (in 'string', line 402, column 22 to line 407, column 3)",
  " (in 'string', line 402, column 2 to line 407, column 3)",
  " (in 'string', line 413, column 8 to column 69)",
  " (in 'string', line 412, column 72 to line 414, column 7)",
  " (in 'string', line 412, column 6 to line 414, column 7)",
  " (in 'string', line 411, column 24 to line 415, column 5)",
  " (in 'string', line 411, column 4 to line 415, column 5)",
  " (in 'string', line 410, column 21 to line 416, column 3)",
  " (in 'string', line 410, column 2 to line 416, column 3)",
  " (in 'string', line 381, column 12 to line 417, column 1)",
  " (in 'string', line 381, column 0 to line 417, column 1)",
  " (in 'string', line 472, column 6 to line 474, column 34)",
  " (in 'string', line 471, column 11 to line 475, column 5)",
  " (in 'string', line 461, column 13 to column 35)",
  " (in 'string', line 461, column 6 to line 463, column 34)",
  " (in 'string', line 469, column 8 to column 59)",
  " (in 'string', line 467, column 8 to column 108)",
  " (in 'string', line 466, column 8 to line 469, column 59)",
  " (in 'string', line 465, column 35 to line 470, column 7)",
  " (in 'string', line 465, column 6 to line 470, column 7)",
  " (in 'string', line 460, column 12 to line 471, column 5)",
  " (in 'string', line 460, column 4 to line 475, column 5)",
  " (in 'string', line 480, column 10 to column 84)",
  " (in 'string', line 479, column 74 to line 481, column 9)",
  " (in 'string', line 479, column 8 to line 481, column 9)",
  " (in 'string', line 483, column 10 to column 86)",
  " (in 'string', line 482, column 78 to line 484, column 9)",
  " (in 'string', line 482, column 8 to line 484, column 9)",
  " (in 'string', line 478, column 35 to line 485, column 7)",
  " (in 'string', line 478, column 6 to line 485, column 7)",
  " (in 'string', line 477, column 23 to line 486, column 5)",
  " (in 'string', line 477, column 4 to line 486, column 5)",
  " (in 'string', line 459, column 9 to line 487, column 3)",
  " (in 'string', line 422, column 11 to column 37)",
  " (in 'string', line 422, column 4 to line 424, column 32)",
  " (in 'string', line 430, column 10 to column 128)",
  " (in 'string', line 429, column 74 to line 431, column 9)",
  " (in 'string', line 429, column 8 to line 431, column 9)",
  " (in 'string', line 433, column 10 to column 130)",
  " (in 'string', line 432, column 78 to line 434, column 9)",
  " (in 'string', line 432, column 8 to line 434, column 9)",
  " (in 'string', line 428, column 29 to line 435, column 7)",
  " (in 'string', line 428, column 6 to line 435, column 7)",
  " (in 'string', line 427, column 23 to line 436, column 5)",
  " (in 'string', line 427, column 4 to line 436, column 5)",
  " (in 'string', line 452, column 8 to column 125)",
  " (in 'string', line 451, column 40 to line 453, column 7)",
  " (in 'string', line 451, column 11 to line 453, column 7)",
  " (in 'string', line 450, column 28 to column 72)",
  " (in 'string', line 450, column 6 to line 453, column 7)",
  " (in 'string', line 456, column 8 to column 87)",
  " (in 'string', line 455, column 35 to line 457, column 7)",
  " (in 'string', line 455, column 6 to line 457, column 7)",
  " (in 'string', line 449, column 11 to line 458, column 5)",
  " (in 'string', line 444, column 8 to line 445, column 76)",
  " (in 'string', line 441, column 8 to line 442, column 125)",
  " (in 'string', line 440, column 8 to line 445, column 76)",
  " (in 'string', line 447, column 8 to column 87)",
  " (in 'string', line 439, column 35 to line 448, column 7)",
  " (in 'string', line 439, column 6 to line 448, column 7)",
  " (in 'string', line 438, column 12 to line 449, column 5)",
  " (in 'string', line 438, column 4 to line 458, column 5)",
  " (in 'string', line 421, column 20 to line 459, column 3)",
  " (in 'string', line 421, column 2 to line 487, column 3)",
  " (in 'string', line 420, column 21 to line 488, column 1)",
  " (in 'string', line 420, column 0 to line 488, column 1)",
  " (in 'string', line 489, column 2 to column 12)",
  " (in 'string', line 490, column 16 to column 30)",
  " (in 'string', line 490, column 2 to column 30)",
  " (in 'string', line 492, column 2 to column 25)",
  " (in 'string', line 493, column 2 to column 41)",
  " (in 'string', line 497, column 11 to column 26)",
  " (in 'string', line 497, column 4 to column 35)",
  " (in 'string', line 504, column 8 to column 68)",
  " (in 'string', line 503, column 11 to line 504, column 68)",
  " (in 'string', line 502, column 8 to column 60)",
  " (in 'string', line 501, column 11 to line 504, column 68)",
  " (in 'string', line 500, column 8 to column 66)",
  " (in 'string', line 499, column 6 to line 504, column 68)",
  " (in 'string', line 498, column 35 to line 505, column 5)",
  " (in 'string', line 498, column 4 to line 505, column 5)",
  " (in 'string', line 507, column 4 to column 36)",
  " (in 'string', line 511, column 6 to column 62)",
  " (in 'string', line 509, column 35 to line 512, column 5)",
  " (in 'string', line 509, column 4 to line 512, column 5)",
  " (in 'string', line 514, column 4 to column 68)",
  " (in 'string', line 496, column 22 to line 515, column 3)",
  " (in 'string', line 496, column 2 to line 515, column 3)",
  " (in 'string', line 518, column 11 to column 32)",
  " (in 'string', line 518, column 4 to line 520, column 33)",
  " (in 'string', line 526, column 6 to column 116)",
  " (in 'string', line 522, column 24 to line 527, column 5)",
  " (in 'string', line 522, column 4 to line 527, column 5)",
  " (in 'string', line 532, column 10 to column 118)",
  " (in 'string', line 531, column 64 to line 533, column 9)",
  " (in 'string', line 531, column 8 to line 533, column 9)",
  " (in 'string', line 530, column 30 to line 534, column 7)",
  " (in 'string', line 530, column 6 to line 534, column 7)",
  " (in 'string', line 529, column 23 to line 535, column 5)",
  " (in 'string', line 529, column 4 to line 535, column 5)",
  " (in 'string', line 641, column 14 to column 79)",
  " (in 'string', line 640, column 68 to line 642, column 13)",
  " (in 'string', line 640, column 12 to line 642, column 13)",
  " (in 'string', line 639, column 34 to line 643, column 11)",
  " (in 'string', line 639, column 10 to line 643, column 11)",
  " (in 'string', line 638, column 27 to line 644, column 9)",
  " (in 'string', line 638, column 8 to line 644, column 9)",
  " (in 'string', line 660, column 14 to column 97)",
  " (in 'string', line 659, column 47 to line 661, column 13)",
  " (in 'string', line 659, column 12 to line 661, column 13)",
  " (in 'string', line 658, column 34 to line 662, column 11)",
  " (in 'string', line 658, column 10 to line 662, column 11)",
  " (in 'string', line 657, column 30 to line 663, column 9)",
  " (in 'string', line 657, column 15 to line 663, column 9)",
  " (in 'string', line 654, column 14 to column 89)",
  " (in 'string', line 653, column 47 to line 655, column 13)",
  " (in 'string', line 653, column 12 to line 655, column 13)",
  " (in 'string', line 652, column 34 to line 656, column 11)",
  " (in 'string', line 652, column 10 to line 656, column 11)",
  " (in 'string', line 651, column 30 to line 657, column 9)",
  " (in 'string', line 651, column 15 to line 663, column 9)",
  " (in 'string', line 648, column 14 to column 95)",
  " (in 'string', line 647, column 47 to line 649, column 13)",
  " (in 'string', line 647, column 12 to line 649, column 13)",
  " (in 'string', line 646, column 34 to line 650, column 11)",
  " (in 'string', line 646, column 10 to line 650, column 11)",
  " (in 'string', line 645, column 23 to line 651, column 9)",
  " (in 'string', line 645, column 8 to line 663, column 9)",
  " (in 'string', line 637, column 13 to line 664, column 7)",
  " (in 'string', line 598, column 8 to column 28)",
  " (in 'string', line 602, column 14 to column 79)",
  " (in 'string', line 601, column 68 to line 603, column 13)",
  " (in 'string', line 601, column 12 to line 603, column 13)",
  " (in 'string', line 600, column 34 to line 604, column 11)",
  " (in 'string', line 600, column 10 to line 604, column 11)",
  " (in 'string', line 599, column 27 to line 605, column 9)",
  " (in 'string', line 599, column 8 to line 605, column 9)",
  " (in 'string', line 631, column 14 to column 51)",
  " (in 'string', line 629, column 14 to column 85)",
  " (in 'string', line 628, column 12 to line 631, column 51)",
  " (in 'string', line 633, column 14 to column 92)",
  " (in 'string', line 632, column 47 to line 634, column 13)",
  " (in 'string', line 632, column 12 to line 634, column 13)",
  " (in 'string', line 627, column 34 to line 635, column 11)",
  " (in 'string', line 627, column 10 to line 635, column 11)",
  " (in 'string', line 626, column 30 to line 636, column 9)",
  " (in 'string', line 626, column 15 to line 636, column 9)",
  " (in 'string', line 621, column 14 to column 51)",
  " (in 'string', line 619, column 14 to column 85)",
  " (in 'string', line 618, column 12 to line 621, column 51)",
  " (in 'string', line 623, column 14 to column 84)",
  " (in 'string', line 622, column 47 to line 624, column 13)",
  " (in 'string', line 622, column 12 to line 624, column 13)",
  " (in 'string', line 617, column 34 to line 625, column 11)",
  " (in 'string', line 617, column 10 to line 625, column 11)",
  " (in 'string', line 616, column 30 to line 626, column 9)",
  " (in 'string', line 616, column 15 to line 636, column 9)",
  " (in 'string', line 611, column 14 to column 51)",
  " (in 'string', line 609, column 14 to column 85)",
  " (in 'string', line 608, column 12 to line 611, column 51)",
  " (in 'string', line 613, column 14 to column 90)",
  " (in 'string', line 612, column 47 to line 614, column 13)",
  " (in 'string', line 612, column 12 to line 614, column 13)",
  " (in 'string', line 607, column 34 to line 615, column 11)",
  " (in 'string', line 607, column 10 to line 615, column 11)",
  " (in 'string', line 606, column 23 to line 616, column 9)",
  " (in 'string', line 606, column 8 to line 636, column 9)",
  " (in 'string', line 597, column 14 to line 637, column 7)",
  " (in 'string', line 597, column 6 to line 664, column 7)",
  " (in 'string', line 596, column 11 to line 665, column 5)",
  " (in 'string', line 586, column 14 to column 167)",
  " (in 'string', line 585, column 47 to line 587, column 13)",
  " (in 'string', line 585, column 12 to line 587, column 13)",
  " (in 'string', line 584, column 34 to line 588, column 11)",
  " (in 'string', line 584, column 10 to line 588, column 11)",
  " (in 'string', line 583, column 30 to line 589, column 9)",
  " (in 'string', line 583, column 15 to line 589, column 9)",
  " (in 'string', line 580, column 14 to column 159)",
  " (in 'string', line 579, column 47 to line 581, column 13)",
  " (in 'string', line 579, column 12 to line 581, column 13)",
  " (in 'string', line 578, column 34 to line 582, column 11)",
  " (in 'string', line 578, column 10 to line 582, column 11)",
  " (in 'string', line 577, column 30 to line 583, column 9)",
  " (in 'string', line 577, column 15 to line 589, column 9)",
  " (in 'string', line 574, column 14 to column 165)",
  " (in 'string', line 573, column 47 to line 575, column 13)",
  " (in 'string', line 573, column 12 to line 575, column 13)",
  " (in 'string', line 572, column 34 to line 576, column 11)",
  " (in 'string', line 572, column 10 to line 576, column 11)",
  " (in 'string', line 571, column 23 to line 577, column 9)",
  " (in 'string', line 571, column 8 to line 589, column 9)",
  " (in 'string', line 570, column 13 to line 590, column 7)",
  " (in 'string', line 538, column 15 to column 19)",
  " (in 'string', line 538, column 8 to column 36)",
  " (in 'string', line 564, column 14 to column 94)",
  " (in 'string', line 562, column 14 to column 128)",
  " (in 'string', line 561, column 12 to line 564, column 94)",
  " (in 'string', line 566, column 14 to column 119)",
  " (in 'string', line 565, column 47 to line 567, column 13)",
  " (in 'string', line 565, column 12 to line 567, column 13)",
  " (in 'string', line 560, column 34 to line 568, column 11)",
  " (in 'string', line 560, column 10 to line 568, column 11)",
  " (in 'string', line 559, column 30 to line 569, column 9)",
  " (in 'string', line 559, column 15 to line 569, column 9)",
  " (in 'string', line 554, column 14 to column 94)",
  " (in 'string', line 552, column 14 to column 128)",
  " (in 'string', line 551, column 12 to line 554, column 94)",
  " (in 'string', line 556, column 14 to column 111)",
  " (in 'string', line 555, column 47 to line 557, column 13)",
  " (in 'string', line 555, column 12 to line 557, column 13)",
  " (in 'string', line 550, column 34 to line 558, column 11)",
  " (in 'string', line 550, column 10 to line 558, column 11)",
  " (in 'string', line 549, column 30 to line 559, column 9)",
  " (in 'string', line 549, column 15 to line 569, column 9)",
  " (in 'string', line 544, column 14 to column 94)",
  " (in 'string', line 542, column 14 to column 128)",
  " (in 'string', line 541, column 12 to line 544, column 94)",
  " (in 'string', line 546, column 14 to column 117)",
  " (in 'string', line 545, column 47 to line 547, column 13)",
  " (in 'string', line 545, column 12 to line 547, column 13)",
  " (in 'string', line 540, column 34 to line 548, column 11)",
  " (in 'string', line 540, column 10 to line 548, column 11)",
  " (in 'string', line 539, column 23 to line 549, column 9)",
  " (in 'string', line 539, column 8 to line 569, column 9)",
  " (in 'string', line 537, column 14 to line 570, column 7)",
  " (in 'string', line 537, column 6 to line 590, column 7)",
  " (in 'string', line 593, column 10 to column 85)",
  " (in 'string', line 592, column 43 to line 594, column 9)",
  " (in 'string', line 592, column 8 to line 594, column 9)",
  " (in 'string', line 591, column 30 to line 595, column 7)",
  " (in 'string', line 591, column 6 to line 595, column 7)",
  " (in 'string', line 536, column 22 to line 596, column 5)",
  " (in 'string', line 536, column 4 to line 665, column 5)",
  " (in 'string', line 668, column 6 to column 56)",
  " (in 'string', line 671, column 8 to column 96)",
  " (in 'string', line 670, column 6 to line 671, column 96)",
  " (in 'string', line 673, column 6 to column 100)",
  " (in 'string', line 666, column 28 to line 674, column 5)",
  " (in 'string', line 666, column 4 to line 674, column 5)",
  " (in 'string', line 517, column 18 to line 675, column 3)",
  " (in 'string', line 517, column 2 to line 675, column 3)",
  " (in 'string', line 785, column 2 to column 12)",
  " (in 'string', line 788, column 6 to column 93)",
  " (in 'string', line 789, column 6 to column 13)",
  " (in 'string', line 787, column 21 to line 790, column 5)",
  " (in 'string', line 787, column 4 to line 790, column 5)",
  " (in 'string', line 786, column 41 to line 791, column 3)",
  " (in 'string', line 786, column 2 to line 791, column 3)",
  " (in 'string', line 794, column 6 to line 795, column 101)",
  " (in 'string', line 798, column 8 to column 49)",
  " (in 'string', line 797, column 6 to line 798, column 49)",
  " (in 'string', line 800, column 6 to column 13)",
  " (in 'string', line 793, column 47 to line 801, column 5)",
  " (in 'string', line 793, column 4 to line 801, column 5)",
  " (in 'string', line 792, column 31 to line 802, column 3)",
  " (in 'string', line 792, column 2 to line 802, column 3)",
  " (in 'string', line 784, column 8 to line 803, column 1)",
  " (in 'string', line 784, column 0 to line 803, column 1)",
  " (in 'string', line 808, column 4 to column 125)",
  " (in 'string', line 807, column 26 to line 809, column 3)",
  " (in 'string', line 807, column 2 to line 809, column 3)",
  " (in 'string', line 806, column 29 to line 810, column 1)",
  " (in 'string', line 806, column 0 to line 810, column 1)",
  " (in 'string', line 812, column 0 to column 43)",
  " (in 'string', line 816, column 2 to column 12)",
  " (in 'string', line 817, column 2 to column 9)",
  " (in 'string', line 819, column 4 to column 28)",
  " (in 'string', line 820, column 4 to line 821, column 102)",
  " (in 'string', line 822, column 4 to line 823, column 123)",
  " (in 'string', line 824, column 4 to column 12)",
  " (in 'string', line 818, column 31 to line 825, column 3)",
  " (in 'string', line 818, column 2 to line 825, column 3)",
  " (in 'string', line 815, column 0 to line 826, column 1)",
  " (in 'string', line 830, column 4 to column 59)",
  " (in 'string', line 831, column 4 to column 32)",
  " (in 'string', line 832, column 4 to column 33)",
  " (in 'string', line 829, column 22 to line 833, column 3)",
  " (in 'string', line 829, column 2 to line 833, column 3)",
  " (in 'string', line 836, column 10 to column 20)",
  " (in 'string', line 836, column 29 to column 33)",
  " (in 'string', line 836, column 4 to column 38)",
  " (in 'string', line 838, column 6 to column 82)",
  " (in 'string', line 839, column 6 to column 62)",
  " (in 'string', line 842, column 8 to column 177)",
  " (in 'string', line 840, column 35 to line 843, column 7)",
  " (in 'string', line 840, column 6 to line 843, column 7)",
  " (in 'string', line 844, column 6 to column 61)",
  " (in 'string', line 837, column 28 to line 845, column 5)",
  " (in 'string', line 837, column 4 to line 845, column 5)",
  " (in 'string', line 835, column 2 to line 846, column 3)",
  " (in 'string', line 850, column 13 to column 21)",
  " (in 'string', line 850, column 6 to column 41)",
  " (in 'string', line 851, column 41 to column 138)",
  " (in 'string', line 851, column 6 to column 138)",
  " (in 'string', line 853, column 6 to column 82)",
  " (in 'string', line 856, column 8 to column 123)",
  " (in 'string', line 855, column 6 to line 856, column 123)",
  " (in 'string', line 858, column 6 to column 126)",
  " (in 'string', line 849, column 28 to line 859, column 5)",
  " (in 'string', line 849, column 4 to line 859, column 5)",
  " (in 'string', line 848, column 26 to line 860, column 3)",
  " (in 'string', line 848, column 2 to line 860, column 3)",
  " (in 'string', line 683, column 0 to column 111)",
  " (in 'string', line 689, column 4 to column 127)",
  " (in 'string', line 692, column 4 to column 117)",
  " (in 'string', line 687, column 9 to line 693, column 1)",
  " (in 'string', line 686, column 4 to column 90)",
  " (in 'string', line 685, column 26 to line 687, column 3)",
  " (in 'string', line 685, column 2 to line 693, column 1)",
  " (in 'string', line 696, column 0 to column 89)",
  " (in 'string', line 699, column 0 to column 90)",
  " (in 'string', line 708, column 11 to column 21)",
  " (in 'string', line 708, column 4 to column 29)",
  " (in 'string', line 715, column 6 to column 27)",
  " (in 'string', line 716, column 6 to column 28)",
  " (in 'string', line 714, column 34 to line 717, column 5)",
  " (in 'string', line 714, column 9 to line 717, column 5)",
  " (in 'string', line 711, column 6 to column 26)",
  " (in 'string', line 712, column 6 to column 25)",
  " (in 'string', line 710, column 29 to line 713, column 5)",
  " (in 'string', line 710, column 4 to line 717, column 5)",
  " (in 'string', line 718, column 4 to column 94)",
  " (in 'string', line 706, column 10 to line 719, column 3)",
  " (in 'string', line 706, column 9 to line 719, column 4)",
  " (in 'string', line 704, column 4 to column 92)",
  " (in 'string', line 703, column 27 to line 706, column 3)",
  " (in 'string', line 703, column 2 to line 719, column 4)",
  " (in 'string', line 702, column 8 to line 720, column 1)",
  " (in 'string', line 702, column 0 to line 720, column 1)",
  " (in 'string', line 723, column 0 to column 23)",
  " (in 'string', line 727, column 2 to column 74)",
  " (in 'string', line 726, column 21 to line 728, column 1)",
  " (in 'string', line 726, column 0 to line 728, column 1)",
  " (in 'string', line 738, column 6 to column 42)",
  " (in 'string', line 736, column 11 to line 739, column 5)",
  " (in 'string', line 735, column 6 to column 96)",
  " (in 'string', line 733, column 26 to line 736, column 5)",
  " (in 'string', line 733, column 4 to line 739, column 5)",
  " (in 'string', line 732, column 22 to line 740, column 3)",
  " (in 'string', line 732, column 2 to line 740, column 3)",
  " (in 'string', line 731, column 19 to line 741, column 1)",
  " (in 'string', line 731, column 0 to line 741, column 1)",
  " (in 'string', line 744, column 0 to column 23)",
  " (in 'string', line 747, column 4 to column 41)",
  " (in 'string', line 746, column 2 to line 747, column 41)",
  " (in 'string', line 751, column 4 to column 53)",
  " (in 'string', line 750, column 2 to line 751, column 53)",
  " (in 'string', line 758, column 11 to column 19)",
  " (in 'string', line 758, column 4 to column 29)",
  " (in 'string', line 760, column 6 to column 37)",
  " (in 'string', line 759, column 4 to line 760, column 37)",
  " (in 'string', line 761, column 4 to column 96)",
  " (in 'string', line 757, column 26 to line 762, column 3)",
  " (in 'string', line 757, column 2 to line 762, column 3)",
  " (in 'string', line 80, column 0 to column 20)",
  " (in 'string', line 81, column 0 to column 24)",
  " (in 'string', line 82, column 0 to column 29)",
  " (in 'string', line 84, column 0 to column 20)",
  " (in 'string', line 85, column 0 to column 24)",
  " (in 'string', line 86, column 0 to column 29)",
  " (in 'string', line 89, column 0 to column 22)",
  " (in 'string', line 90, column 6 to column 12)",
  " (in 'string', line 90, column 0 to column 35)",
  " (in 'string', line 91, column 6 to column 14)",
  " (in 'string', line 91, column 0 to column 37)",
  " (in 'string', line 92, column 0 to column 26)",
  " (in 'string', line 93, column 6 to column 18)",
  " (in 'string', line 93, column 0 to column 45)",
  " (in 'string', line 94, column 6 to column 21)",
  " (in 'string', line 94, column 0 to column 53)",
  " (in 'string', line 95, column 6 to column 21)",
  " (in 'string', line 95, column 0 to column 55)",
  " (in 'string', line 102, column 0 to column 16)",
  " (in 'string', line 103, column 0 to column 16)",
  " (in 'string', line 106, column 0 to column 21)",
  " (in 'string', line 107, column 0 to column 36)",
  " (in 'string', line 108, column 6 to column 13)",
  " (in 'string', line 108, column 0 to column 37)",
  " (in 'string', line 109, column 0 to column 22)",
  " (in 'string', line 110, column 0 to column 22)",
  " (in 'string', line 112, column 0 to column 18)",
  " (in 'string', line 115, column 7 to column 22)",
  " (in 'string', line 115, column 0 to column 39)",
  " (in 'string', line 116, column 11 to column 48)",
  " (in 'string', line 116, column 0 to column 69)",
  " (in 'string', line 119, column 0 to column 25)",
  " (in 'string', line 120, column 7 to column 57)",
  " (in 'string', line 120, column 59 to column 61)",
  " (in 'string', line 120, column 0 to column 65)",
  " (in 'string', line 121, column 7 to column 18)",
  " (in 'string', line 121, column 20 to column 31)",
  " (in 'string', line 121, column 0 to column 39)",
  " (in 'string', line 124, column 0 to column 33)",
  " (in 'string', line 125, column 7 to column 74)",
  " (in 'string', line 125, column 0 to column 84)",
  " (in 'string', line 128, column 0 to column 25)",
  " (in 'string', line 129, column 6 to column 56)",
  " (in 'string', line 129, column 0 to column 80)",
  " (in 'string', line 130, column 12 to column 34)",
  " (in 'string', line 130, column 0 to column 43)",
  " (in 'string', line 133, column 0 to column 32)",
  " (in 'string', line 136, column 0 to column 24)",
  " (in 'string', line 137, column 6 to column 16)",
  " (in 'string', line 137, column 0 to column 40)",
  " (in 'string', line 138, column 0 to column 13)",
  " (in 'string', line 141, column 0 to column 42)",
  " (in 'string', line 142, column 0 to column 30)",
  " (in 'string', line 143, column 0 to column 36)",
  " (in 'string', line 144, column 0 to column 33)",
  " (in 'string', line 146, column 0 to column 36)",
  " (in 'string', line 147, column 0 to column 24)",
  " (in 'string', line 148, column 0 to column 30)",
  " (in 'string', line 149, column 0 to column 27)",
  " (in 'string', line 151, column 0 to column 36)",
  " (in 'string', line 152, column 0 to column 36)",
  " (in 'string', line 153, column 0 to column 24)",
  " (in 'string', line 154, column 0 to column 30)",
  " (in 'string', line 155, column 0 to column 27)",
  " (in 'string', line 157, column 0 to column 36)",
  " (in 'string', line 158, column 0 to column 24)",
  " (in 'string', line 159, column 0 to column 30)",
  " (in 'string', line 160, column 0 to column 27)",
  " (in 'string', line 163, column 0 to column 36)",
  " (in 'string', line 164, column 6 to column 30)",
  " (in 'string', line 164, column 0 to column 54)",
  " (in 'string', line 165, column 6 to column 30)",
  " (in 'string', line 165, column 0 to column 57)",
  " (in 'string', line 167, column 0 to column 43)",
  " (in 'string', line 168, column 0 to column 31)",
  " (in 'string', line 169, column 0 to column 37)",
  " (in 'string', line 170, column 0 to column 34)",
  " (in 'string', line 172, column 0 to column 41)",
  " (in 'string', line 173, column 0 to column 29)",
  " (in 'string', line 174, column 0 to column 35)",
  " (in 'string', line 175, column 0 to column 32)",
  " (in 'string', line 177, column 2 to column 20)",
  " (in 'string', line 178, column 8 to column 14)",
  " (in 'string', line 178, column 2 to column 47)",
  " (in 'string', line 179, column 8 to column 14)",
  " (in 'string', line 179, column 16 to column 20)",
  " (in 'string', line 179, column 2 to column 55)",
  " (in 'string', line 180, column 8 to column 14)",
  " (in 'string', line 180, column 2 to column 50)",
  " (in 'string', line 181, column 8 to column 18)",
  " (in 'string', line 181, column 20 to column 24)",
  " (in 'string', line 181, column 2 to column 49)",
  " (in 'string', line 182, column 9 to column 19)",
  " (in 'string', line 182, column 2 to column 31)",
  " (in 'string', line 183, column 8 to column 18)",
  " (in 'string', line 183, column 20 to column 24)",
  " (in 'string', line 183, column 2 to column 63)",
  " (in 'string', line 184, column 8 to column 18)",
  " (in 'string', line 184, column 2 to column 58)",
  " (in 'string', line 186, column 2 to column 38)",
  " (in 'string', line 187, column 2 to column 26)",
  " (in 'string', line 188, column 2 to column 32)",
  " (in 'string', line 189, column 2 to column 29)",
  " (in 'string', line 192, column 8 to column 14)",
  " (in 'string', line 192, column 23 to column 27)",
  " (in 'string', line 192, column 2 to column 81)",
  " (in 'string', line 193, column 8 to column 18)",
  " (in 'string', line 193, column 27 to column 31)",
  " (in 'string', line 193, column 2 to column 97)",
  " (in 'string', line 200, column 0 to column 54)",
  " (in 'string', line 204, column 0 to column 46)",
  " (in 'string', line 206, column 7 to column 14)",
  " (in 'string', line 206, column 0 to column 47)",
  " (in 'string', line 208, column 0 to column 21)",
  " (in 'string', line 209, column 21 to column 28)",
  " (in 'string', line 209, column 0 to column 84)",
  " (in 'string', line 211, column 0 to column 17)",
  " (in 'string', line 212, column 0 to column 21)",
  " (in 'string', line 213, column 0 to column 34)",
  " (in 'string', line 214, column 0 to column 58)",
  " (in 'string', line 215, column 7 to column 30)",
  " (in 'string', line 215, column 0 to column 81)",
  " (in 'string', line 216, column 6 to column 29)",
  " (in 'string', line 216, column 0 to column 85)",
  " (in 'string', line 217, column 6 to column 33)",
  " (in 'string', line 217, column 0 to column 90)",
  " (in 'string', line 223, column 0 to column 32)",
  " (in 'string', line 229, column 6 to column 47)",
  " (in 'string', line 229, column 0 to column 135)",
  " (in 'string', line 232, column 10 to column 12)",
  " (in 'string', line 232, column 0 to column 21)",
  " (in 'string', line 233, column 7 to column 13)",
  " (in 'string', line 233, column 15 to column 17)",
  " (in 'string', line 233, column 0 to column 57)",
  " (in 'string', line 234, column 7 to column 28)",
  " (in 'string', line 234, column 30 to column 32)",
  " (in 'string', line 234, column 0 to column 117)",
  " (in 'string', line 235, column 7 to column 33)",
  " (in 'string', line 235, column 35 to column 37)",
  " (in 'string', line 235, column 0 to column 176)",
  " (in 'string', line 238, column 0 to column 17)",
  " (in 'string', line 239, column 7 to column 40)",
  " (in 'string', line 239, column 0 to column 105)",
  " (in 'string', line 240, column 7 to column 59)",
  " (in 'string', line 240, column 0 to column 169)",
  " (in 'string', line 241, column 7 to column 69)",
  " (in 'string', line 241, column 0 to column 233)",
  " (in 'string', line 244, column 0 to column 72)",
  " (in 'string', line 247, column 7 to column 44)",
  " (in 'string', line 247, column 46 to column 83)",
  " (in 'string', line 247, column 0 to column 129)",
  " (in 'string', line 251, column 6 to column 21)",
  " (in 'string', line 251, column 0 to column 43)",
  " (in 'string', line 253, column 2 to column 12)",
  " (in 'string', line 254, column 2 to column 12)",
  " (in 'string', line 261, column 6 to column 13)",
  " (in 'string', line 260, column 11 to line 262, column 5)",
  " (in 'string', line 257, column 6 to column 29)",
  " (in 'string', line 258, column 6 to column 13)",
  " (in 'string', line 259, column 6 to column 12)",
  " (in 'string', line 256, column 41 to line 260, column 5)",
  " (in 'string', line 256, column 4 to line 262, column 5)",
  " (in 'string', line 255, column 37 to line 263, column 3)",
  " (in 'string', line 255, column 2 to line 263, column 3)",
  " (in 'string', line 265, column 2 to column 25)",
  " (in 'string', line 252, column 21 to line 266, column 1)",
  " (in 'string', line 252, column 0 to line 266, column 1)",
  " (in 'string', line 269, column 0 to column 63)",
  " (in 'string', line 270, column 6 to column 18)",
  " (in 'string', line 270, column 0 to column 63)",
  " (in 'string', line 273, column 0 to column 57)",
  " (in 'string', line 274, column 6 to column 30)",
  " (in 'string', line 274, column 0 to column 58)",
  " (in 'string', line 277, column 2 to column 16)",
  " (in 'string', line 284, column 6 to column 26)",
  " (in 'string', line 283, column 11 to line 285, column 5)",
  " (in 'string', line 281, column 6 to column 30)",
  " (in 'string', line 282, column 6 to column 17)",
  " (in 'string', line 280, column 28 to line 283, column 5)",
  " (in 'string', line 280, column 4 to line 285, column 5)",
  " (in 'string', line 279, column 24 to line 286, column 3)",
  " (in 'string', line 279, column 2 to line 286, column 3)",
  " (in 'string', line 276, column 19 to line 287, column 1)",
  " (in 'string', line 276, column 0 to line 287, column 1)",
  " (in 'string', line 293, column 7 to column 9)",
  " (in 'string', line 296, column 7 to column 14)",
  " (in 'string', line 297, column 18 to column 28)",
  " (in 'string', line 300, column 7 to column 40)",
  " (in 'string', line 301, column 16 to column 52)",
  " (in 'string', line 304, column 7 to column 39)",
  " (in 'string', line 307, column 19 to column 27)",
  " (in 'string', line 310, column 9 to column 17)",
  " (in 'string', line 311, column 8 to column 14)",
  " (in 'string', line 311, column 23 to column 27)",
  " (in 'string', line 312, column 9 to column 45)",
  " (in 'string', line 312, column 47 to column 74)",
  " (in 'string', line 313, column 8 to column 18)",
  " (in 'string', line 313, column 27 to column 31)",
  " (in 'string', line 314, column 8 to column 18)",
  " (in 'string', line 314, column 27 to column 31)",
  " (in 'string', line 319, column 7 to column 13)",
  " (in 'string', line 324, column 7 to column 14)",
  " (in 'string', line 332, column 7 to column 44)",
  " (in 'string', line 335, column 7 to column 9)",
  " (in 'string', line 337, column 7 to column 12)",
  " (in 'string', line 339, column 7 to column 13)",
  " (in 'string', line 341, column 7 to column 16)",
  " (in 'string', line 343, column 7 to column 40)",
  " (in 'string', line 348, column 7 to column 48)",
  " (in 'string', line 349, column 7 to column 22)",
  " (in 'string', line 766, column 8 to column 14)",
  " (in 'string', line 766, column 23 to column 27)",
  " (in 'string', line 767, column 8 to column 18)",
  " (in 'string', line 767, column 27 to column 31)",
  " (in 'string', line 768, column 9 to column 32)",
  " (in 'string', line 768, column 34 to column 38)",
  " (in 'string', line 773, column 7 to column 44)",
  " (in 'string', line 774, column 7 to column 44)",
  " (in 'string', line 775, column 7 to column 22)",
  " (in 'string', line 778, column 9 to column 37)",
  " (in 'string', line 782, column 7 to column 14)",
  " (in 'string', line 21, column 4 to column 42)",
  " (in 'string', line 20, column 9 to line 22, column 3)",
  " (in 'string', line 18, column 4 to column 44)",
  " (in 'string', line 19, column 4 to column 22)",
  " (in 'string', line 17, column 24 to line 20, column 3)",
  " (in 'string', line 17, column 9 to line 22, column 3)",
  " (in 'string', line 16, column 4 to column 35)",
  " (in 'string', line 15, column 24 to line 17, column 3)",
  " (in 'string', line 15, column 9 to line 22, column 3)",
  " (in 'string', line 14, column 4 to column 29)",
  " (in 'string', line 13, column 24 to line 15, column 3)",
  " (in 'string', line 13, column 9 to line 22, column 3)",
  " (in 'string', line 12, column 4 to column 39)",
  " (in 'string', line 11, column 24 to line 13, column 3)",
  " (in 'string', line 11, column 9 to line 22, column 3)",
  " (in 'string', line 10, column 4 to column 32)",
  " (in 'string', line 9, column 24 to line 11, column 3)",
  " (in 'string', line 9, column 9 to line 22, column 3)",
  " (in 'string', line 8, column 4 to column 32)",
  " (in 'string', line 7, column 24 to line 9, column 3)",
  " (in 'string', line 7, column 9 to line 22, column 3)",
  " (in 'string', line 5, column 17 to line 7, column 3)",
  " (in 'string', line 5, column 2 to line 22, column 3)",
  " (in 'string', line 23, column 2 to column 9)",
  " (in 'string', line 4, column 77 to line 24, column 1)",
  " (in 'string', line 43, column 4 to column 42)",
  " (in 'string', line 42, column 9 to line 44, column 3)",
  " (in 'string', line 40, column 4 to column 44)",
  " (in 'string', line 41, column 4 to column 22)",
  " (in 'string', line 39, column 24 to line 42, column 3)",
  " (in 'string', line 39, column 9 to line 44, column 3)",
  " (in 'string', line 38, column 4 to column 35)",
  " (in 'string', line 37, column 24 to line 39, column 3)",
  " (in 'string', line 37, column 9 to line 44, column 3)",
  " (in 'string', line 36, column 4 to column 29)",
  " (in 'string', line 35, column 24 to line 37, column 3)",
  " (in 'string', line 35, column 9 to line 44, column 3)",
  " (in 'string', line 34, column 4 to column 39)",
  " (in 'string', line 33, column 24 to line 35, column 3)",
  " (in 'string', line 33, column 9 to line 44, column 3)",
  " (in 'string', line 32, column 4 to column 32)",
  " (in 'string', line 31, column 24 to line 33, column 3)",
  " (in 'string', line 31, column 9 to line 44, column 3)",
  " (in 'string', line 30, column 4 to column 32)",
  " (in 'string', line 29, column 24 to line 31, column 3)",
  " (in 'string', line 29, column 9 to line 44, column 3)",
  " (in 'string', line 27, column 17 to line 29, column 3)",
  " (in 'string', line 27, column 2 to line 44, column 3)",
  " (in 'string', line 45, column 2 to column 9)",
  " (in 'string', line 26, column 76 to line 46, column 1)",
  " (in 'string', line 51, column 2 to column 18)",
  " (in 'string', line 52, column 2 to column 18)",
  " (in 'string', line 53, column 2 to column 12)",
  " (in 'string', line 56, column 23 to column 30)",
  " (in 'string', line 56, column 6 to column 30)",
  " (in 'string', line 55, column 19 to line 57, column 5)",
  " (in 'string', line 55, column 4 to line 57, column 5)",
  " (in 'string', line 54, column 17 to line 58, column 3)",
  " (in 'string', line 54, column 2 to line 58, column 3)",
  " (in 'string', line 59, column 2 to column 11)",
  " (in 'string', line 50, column 28 to line 60, column 1)",
  " (in 'string', line 64, column 2 to column 26)",
  " (in 'string', line 65, column 8 to column 9)",
  " (in 'string', line 65, column 2 to column 17)",
  " (in 'string', line 66, column 2 to column 12)",
  " (in 'string', line 69, column 6 to column 15)",
  " (in 'string', line 70, column 6 to column 13)",
  " (in 'string', line 68, column 18 to line 71, column 5)",
  " (in 'string', line 68, column 4 to line 71, column 5)",
  " (in 'string', line 67, column 17 to line 72, column 3)",
  " (in 'string', line 67, column 2 to line 72, column 3)",
  " (in 'string', line 73, column 2 to column 20)",
  " (in 'string', line 63, column 38 to line 74, column 1)"};
template <bool propto__, typename T0__, typename T2__, typename T3__,
          typename T4__, typename T_lp__, typename T_lp_accum__,
          stan::require_all_t<stan::is_col_vector<T0__>,
                              stan::is_vt_not_complex<T0__>,
                              stan::is_stan_scalar<T2__>,
                              stan::is_stan_scalar<T3__>,
                              stan::is_stan_scalar<T4__>>* = nullptr>
void
prior_select_lp(const T0__& y_arg__, const int& dist, const T2__& location,
                const T3__& scale, const T4__& df, T_lp__& lp__,
                T_lp_accum__& lp_accum__, std::ostream* pstream__);
template <bool propto__, typename T0__, typename T2__, typename T3__,
          typename T4__, typename T_lp__, typename T_lp_accum__,
          stan::require_all_t<stan::is_stan_scalar<T0__>,
                              stan::is_stan_scalar<T2__>,
                              stan::is_stan_scalar<T3__>,
                              stan::is_stan_scalar<T4__>>* = nullptr>
void
prior_select2_lp(const T0__& y, const int& dist, const T2__& location,
                 const T3__& scale, const T4__& df, T_lp__& lp__,
                 T_lp_accum__& lp_accum__, std::ostream* pstream__);
template <typename T0__,
          stan::require_all_t<stan::is_eigen_matrix_dynamic<T0__>,
                              stan::is_vt_not_complex<T0__>>* = nullptr>
int count_nonzero(const T0__& m_arg__, std::ostream* pstream__);
std::vector<int>
which_gt0a(const std::vector<int>& x, std::ostream* pstream__);
template <bool propto__, typename T0__, typename T2__, typename T3__,
          typename T4__, typename T_lp__, typename T_lp_accum__,
          stan::require_all_t<stan::is_col_vector<T0__>,
                              stan::is_vt_not_complex<T0__>,
                              stan::is_stan_scalar<T2__>,
                              stan::is_stan_scalar<T3__>,
                              stan::is_stan_scalar<T4__>>*>
void
prior_select_lp(const T0__& y_arg__, const int& dist, const T2__& location,
                const T3__& scale, const T4__& df, T_lp__& lp__,
                T_lp_accum__& lp_accum__, std::ostream* pstream__) {
  using local_scalar_t__ = stan::promote_args_t<stan::base_type_t<T0__>,
                             T2__, T3__, T4__>;
  int current_statement__ = 0;
  const auto& y = stan::math::to_ref(y_arg__);
  local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  // suppress unused var warning
  (void) DUMMY_VAR__;
  try {
    current_statement__ = 654;
    if (stan::math::logical_eq(dist, 0)) {} else {
                                            current_statement__ = 652;
                                            if (stan::math::logical_eq(dist,
                                                  1)) {
                                              current_statement__ = 650;
                                              lp_accum__.add(stan::math::normal_lpdf<
                                                               propto__>(y,
                                                               location,
                                                               scale));
                                            } else {
                                              current_statement__ = 649;
                                              if (stan::math::logical_eq(
                                                    dist, 2)) {
                                                current_statement__ = 647;
                                                lp_accum__.add(stan::math::cauchy_lpdf<
                                                                 propto__>(y,
                                                                 location,
                                                                 scale));
                                              } else {
                                                current_statement__ = 646;
                                                if (stan::math::logical_eq(
                                                      dist, 3)) {
                                                  current_statement__ = 644;
                                                  lp_accum__.add(stan::math::student_t_lpdf<
                                                                   propto__>(
                                                                   y, df,
                                                                   location,
                                                                   scale));
                                                } else {
                                                  current_statement__ = 643;
                                                  if (stan::math::logical_eq(
                                                        dist, 4)) {
                                                    current_statement__ = 641;
                                                    lp_accum__.add(stan::math::exponential_lpdf<
                                                                    propto__>(
                                                                    y, (1 /
                                                                    scale)));
                                                  } else {
                                                    current_statement__ = 640;
                                                    if (stan::math::logical_eq(
                                                          dist, 5)) {
                                                      current_statement__ = 638;
                                                      lp_accum__.add(
                                                        stan::math::lognormal_lpdf<
                                                          propto__>(y,
                                                          location, scale));
                                                    } else {
                                                      current_statement__ = 637;
                                                      if (stan::math::logical_eq(
                                                            dist, 6)) {
                                                        current_statement__ = 634;
                                                        lp_accum__.add(
                                                          stan::math::student_t_lpdf<
                                                            propto__>(
                                                            stan::math::log(y),
                                                            df, location,
                                                            scale));
                                                        current_statement__ = 635;
                                                        lp_accum__.add(
                                                          stan::math::minus(
                                                            stan::math::log(y)));
                                                      } else {
                                                        current_statement__ = 632;
                                                        std::stringstream
                                                          errmsg_stream__;
                                                        stan::math::stan_print(
                                                          &errmsg_stream__,
                                                          "Not a supported prior dist.");
                                                        throw std::domain_error(
                                                                errmsg_stream__.str());
                                                      }
                                                    }
                                                  }
                                                }
                                              }
                                            }
    }
    current_statement__ = 655;
    return ;
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
template <bool propto__, typename T0__, typename T2__, typename T3__,
          typename T4__, typename T_lp__, typename T_lp_accum__,
          stan::require_all_t<stan::is_stan_scalar<T0__>,
                              stan::is_stan_scalar<T2__>,
                              stan::is_stan_scalar<T3__>,
                              stan::is_stan_scalar<T4__>>*>
void
prior_select2_lp(const T0__& y, const int& dist, const T2__& location,
                 const T3__& scale, const T4__& df, T_lp__& lp__,
                 T_lp_accum__& lp_accum__, std::ostream* pstream__) {
  using local_scalar_t__ = stan::promote_args_t<T0__, T2__, T3__, T4__>;
  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__ = 679;
    if (stan::math::logical_eq(dist, 0)) {} else {
                                            current_statement__ = 677;
                                            if (stan::math::logical_eq(dist,
                                                  1)) {
                                              current_statement__ = 675;
                                              lp_accum__.add(stan::math::normal_lpdf<
                                                               propto__>(y,
                                                               location,
                                                               scale));
                                            } else {
                                              current_statement__ = 674;
                                              if (stan::math::logical_eq(
                                                    dist, 2)) {
                                                current_statement__ = 672;
                                                lp_accum__.add(stan::math::cauchy_lpdf<
                                                                 propto__>(y,
                                                                 location,
                                                                 scale));
                                              } else {
                                                current_statement__ = 671;
                                                if (stan::math::logical_eq(
                                                      dist, 3)) {
                                                  current_statement__ = 669;
                                                  lp_accum__.add(stan::math::student_t_lpdf<
                                                                   propto__>(
                                                                   y, df,
                                                                   location,
                                                                   scale));
                                                } else {
                                                  current_statement__ = 668;
                                                  if (stan::math::logical_eq(
                                                        dist, 4)) {
                                                    current_statement__ = 666;
                                                    lp_accum__.add(stan::math::exponential_lpdf<
                                                                    propto__>(
                                                                    y, (1 /
                                                                    scale)));
                                                  } else {
                                                    current_statement__ = 665;
                                                    if (stan::math::logical_eq(
                                                          dist, 5)) {
                                                      current_statement__ = 663;
                                                      lp_accum__.add(
                                                        stan::math::lognormal_lpdf<
                                                          propto__>(y,
                                                          location, scale));
                                                    } else {
                                                      current_statement__ = 662;
                                                      if (stan::math::logical_eq(
                                                            dist, 6)) {
                                                        current_statement__ = 659;
                                                        lp_accum__.add(
                                                          stan::math::student_t_lpdf<
                                                            propto__>(
                                                            stan::math::log(y),
                                                            df, location,
                                                            scale));
                                                        current_statement__ = 660;
                                                        lp_accum__.add(-
                                                          stan::math::log(y));
                                                      } else {
                                                        current_statement__ = 657;
                                                        std::stringstream
                                                          errmsg_stream__;
                                                        stan::math::stan_print(
                                                          &errmsg_stream__,
                                                          "Not a supported prior dist.");
                                                        throw std::domain_error(
                                                                errmsg_stream__.str());
                                                      }
                                                    }
                                                  }
                                                }
                                              }
                                            }
    }
    current_statement__ = 680;
    return ;
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
template <typename T0__,
          stan::require_all_t<stan::is_eigen_matrix_dynamic<T0__>,
                              stan::is_vt_not_complex<T0__>>*>
int count_nonzero(const T0__& m_arg__, std::ostream* pstream__) {
  using local_scalar_t__ = stan::promote_args_t<stan::base_type_t<T0__>>;
  int current_statement__ = 0;
  const auto& m = stan::math::to_ref(m_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 I = std::numeric_limits<int>::min();
    current_statement__ = 682;
    I = stan::math::rows(m);
    int J = std::numeric_limits<int>::min();
    current_statement__ = 683;
    J = stan::math::cols(m);
    int c = std::numeric_limits<int>::min();
    current_statement__ = 684;
    c = 0;
    current_statement__ = 690;
    for (int j = 1; j <= I; ++j) {
      current_statement__ = 688;
      for (int i = 1; i <= J; ++i) {
        current_statement__ = 686;
        if (stan::math::logical_neq(
              stan::model::rvalue(m, "m", stan::model::index_uni(i),
                stan::model::index_uni(j)), 0)) {
          current_statement__ = 685;
          c = (c + 1);
        }
      }
    }
    current_statement__ = 691;
    return c;
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
std::vector<int>
which_gt0a(const std::vector<int>& x, std::ostream* pstream__) {
  using local_scalar_t__ = double;
  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 {
    int n = std::numeric_limits<int>::min();
    current_statement__ = 693;
    n = stan::math::num_elements(x);
    current_statement__ = 694;
    stan::math::validate_non_negative_index("w", "n", n);
    std::vector<int> w = std::vector<int>(n, std::numeric_limits<int>::min());
    int c = std::numeric_limits<int>::min();
    current_statement__ = 696;
    c = 1;
    current_statement__ = 702;
    for (int i = 1; i <= n; ++i) {
      current_statement__ = 700;
      if (stan::math::logical_gt(
            stan::model::rvalue(x, "x", stan::model::index_uni(i)), 0)) {
        current_statement__ = 697;
        stan::model::assign(w, i, "assigning variable w",
          stan::model::index_uni(c));
        current_statement__ = 698;
        c = (c + 1);
      }
    }
    current_statement__ = 703;
    return stan::model::rvalue(w, "w", stan::model::index_min_max(1, (c - 1)));
  } catch (const std::exception& e) {
    stan::lang::rethrow_located(e, locations_array__[current_statement__]);
  }
}
#include <stan_meta_header.hpp>
class model_ordered_multinomial final : public model_base_crtp<model_ordered_multinomial> {
private:
  int ns_ipd;
  int ns_agd_arm;
  int ns_agd_contrast;
  int ni_ipd;
  int ni_agd_arm;
  int ni_agd_contrast;
  int narm_ipd;
  std::vector<int> ipd_arm;
  std::vector<int> ipd_trt;
  int narm_agd_arm;
  std::vector<int> agd_arm_trt;
  std::vector<int> agd_contrast_trt;
  std::vector<int> agd_contrast_trt_b;
  int nt;
  int nX;
  int nchains;
  int CHAIN_ID;
  std::vector<int> nint_vec;
  int nint_max;
  int int_thin;
  int link;
  Eigen::Matrix<double,-1,1> agd_contrast_y_data__;
  Eigen::Matrix<double,-1,-1> agd_contrast_Sigma_data__;
  int QR;
  Eigen::Matrix<double,-1,-1> X_data__;
  Eigen::Matrix<double,-1,-1> R_inv_data__;
  int has_offset;
  Eigen::Matrix<double,-1,1> offsets_data__;
  int RE;
  std::vector<int> which_RE;
  Eigen::Matrix<double,-1,-1> RE_cor_data__;
  int nodesplit;
  int brmr_n_col;
  std::vector<int> brmr_col;
  double xbar_mu;
  int prior_intercept_dist;
  double prior_intercept_location;
  double prior_intercept_scale;
  double prior_intercept_df;
  int prior_trt_dist;
  double prior_trt_location;
  double prior_trt_scale;
  double prior_trt_df;
  int prior_het_dist;
  int prior_het_type;
  double prior_het_location;
  double prior_het_scale;
  double prior_het_df;
  int prior_reg_dist;
  double prior_reg_location;
  double prior_reg_scale;
  double prior_reg_df;
  int class_effects;
  std::vector<int> which_CE;
  std::vector<int> which_CE_sd;
  int prior_class_mean_dist;
  double prior_class_mean_location;
  double prior_class_mean_scale;
  double prior_class_mean_df;
  int prior_class_sd_dist;
  double prior_class_sd_location;
  double prior_class_sd_scale;
  double prior_class_sd_df;
  int ncat;
  std::vector<int> ipd_r;
  std::vector<std::vector<int>> ipd_cat;
  std::vector<int> ipd_ncat;
  std::vector<std::vector<int>> agd_arm_r;
  Eigen::Matrix<double,-1,1> agd_arm_n_data__;
  std::vector<std::vector<int>> agd_arm_cat;
  std::vector<int> agd_arm_ncat;
  int prior_aux_dist;
  double prior_aux_location;
  double prior_aux_scale;
  double prior_aux_df;
  std::vector<Eigen::Matrix<double,-1,1>> theta_ipd0;
  std::vector<Eigen::Matrix<double,-1,1>> theta_agd_arm_bar0;
  int nint;
  int n_delta;
  Eigen::Matrix<double,-1,1> RE_mu_data__;
  Eigen::Matrix<double,-1,-1> REdummy_data__;
  Eigen::Matrix<double,-1,-1> RE_L_data__;
  Eigen::Matrix<double,-1,1> wdummy_data__;
  std::vector<int> vudummy;
  int RE_L_nz;
  int RE_sparse;
  Eigen::Matrix<double,-1,1> RE_L_w_data__;
  std::vector<int> RE_L_v;
  std::vector<int> RE_L_u;
  int totns;
  std::vector<int> trt;
  Eigen::Matrix<double,-1,-1> Xdummy_data__;
  Eigen::Matrix<double,-1,-1> X_ipd_data__;
  Eigen::Matrix<double,-1,-1> X_agd_arm_data__;
  Eigen::Matrix<double,-1,-1> X_agd_contrast_data__;
  Eigen::Matrix<double,-1,1> odummy_data__;
  Eigen::Matrix<double,-1,1> offset_ipd_data__;
  Eigen::Matrix<double,-1,1> offset_agd_arm_data__;
  Eigen::Matrix<double,-1,1> offset_agd_contrast_data__;
  int n_int_thin;
  Eigen::Matrix<double,-1,-1> inv_Sigma_data__;
  std::vector<int> nc_agd_contrast;
  int n_class_trts;
  std::vector<int> which_class_trt;
  int n_class;
  std::vector<int> which_fclass;
  int tau_1dim__;
  int class_mean_1dim__;
  int class_sd_1dim__;
  int z_class_1dim__;
  int f_cc_1dim__;
  int cc_1dim__;
  int theta_agd_arm_ii_1dim__;
  int theta_agd_arm_ii_2dim__;
  int f_class_1dim__;
  int d_1dim__;
  int beta_1dim__;
  int eta_agd_contrast_ii_1dim__;
  int theta_bar_cum_agd_arm_1dim__;
  int log_lik_1dim__;
  int resdev_1dim__;
  int theta_bar_cum_agd_contrast_1dim__;
  Eigen::Map<Eigen::Matrix<double,-1,1>> agd_contrast_y{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> agd_contrast_Sigma{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> X{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> R_inv{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> offsets{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> RE_cor{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> agd_arm_n{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> RE_mu{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> REdummy{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> RE_L{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> wdummy{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> RE_L_w{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> Xdummy{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> X_ipd{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> X_agd_arm{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> X_agd_contrast{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> odummy{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> offset_ipd{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> offset_agd_arm{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> offset_agd_contrast{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,-1>> inv_Sigma{nullptr, 0, 0};
public:
  ~model_ordered_multinomial() {}
  model_ordered_multinomial(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_ordered_multinomial_namespace::model_ordered_multinomial";
    // 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__ = 411;
      context__.validate_dims("data initialization", "ns_ipd", "int",
        std::vector<size_t>{});
      ns_ipd = std::numeric_limits<int>::min();
      current_statement__ = 411;
      ns_ipd = context__.vals_i("ns_ipd")[(1 - 1)];
      current_statement__ = 411;
      stan::math::check_greater_or_equal(function__, "ns_ipd", ns_ipd, 0);
      current_statement__ = 412;
      context__.validate_dims("data initialization", "ns_agd_arm", "int",
        std::vector<size_t>{});
      ns_agd_arm = std::numeric_limits<int>::min();
      current_statement__ = 412;
      ns_agd_arm = context__.vals_i("ns_agd_arm")[(1 - 1)];
      current_statement__ = 412;
      stan::math::check_greater_or_equal(function__, "ns_agd_arm",
        ns_agd_arm, 0);
      current_statement__ = 413;
      context__.validate_dims("data initialization", "ns_agd_contrast",
        "int", std::vector<size_t>{});
      ns_agd_contrast = std::numeric_limits<int>::min();
      current_statement__ = 413;
      ns_agd_contrast = context__.vals_i("ns_agd_contrast")[(1 - 1)];
      current_statement__ = 413;
      stan::math::check_greater_or_equal(function__, "ns_agd_contrast",
        ns_agd_contrast, 0);
      current_statement__ = 414;
      context__.validate_dims("data initialization", "ni_ipd", "int",
        std::vector<size_t>{});
      ni_ipd = std::numeric_limits<int>::min();
      current_statement__ = 414;
      ni_ipd = context__.vals_i("ni_ipd")[(1 - 1)];
      current_statement__ = 414;
      stan::math::check_greater_or_equal(function__, "ni_ipd", ni_ipd, 0);
      current_statement__ = 415;
      context__.validate_dims("data initialization", "ni_agd_arm", "int",
        std::vector<size_t>{});
      ni_agd_arm = std::numeric_limits<int>::min();
      current_statement__ = 415;
      ni_agd_arm = context__.vals_i("ni_agd_arm")[(1 - 1)];
      current_statement__ = 415;
      stan::math::check_greater_or_equal(function__, "ni_agd_arm",
        ni_agd_arm, 0);
      current_statement__ = 416;
      context__.validate_dims("data initialization", "ni_agd_contrast",
        "int", std::vector<size_t>{});
      ni_agd_contrast = std::numeric_limits<int>::min();
      current_statement__ = 416;
      ni_agd_contrast = context__.vals_i("ni_agd_contrast")[(1 - 1)];
      current_statement__ = 416;
      stan::math::check_greater_or_equal(function__, "ni_agd_contrast",
        ni_agd_contrast, 0);
      current_statement__ = 417;
      context__.validate_dims("data initialization", "narm_ipd", "int",
        std::vector<size_t>{});
      narm_ipd = std::numeric_limits<int>::min();
      current_statement__ = 417;
      narm_ipd = context__.vals_i("narm_ipd")[(1 - 1)];
      current_statement__ = 417;
      stan::math::check_greater_or_equal(function__, "narm_ipd", narm_ipd, 0);
      current_statement__ = 418;
      stan::math::validate_non_negative_index("ipd_arm", "ni_ipd", ni_ipd);
      current_statement__ = 419;
      context__.validate_dims("data initialization", "ipd_arm", "int",
        std::vector<size_t>{static_cast<size_t>(ni_ipd)});
      ipd_arm = std::vector<int>(ni_ipd, std::numeric_limits<int>::min());
      current_statement__ = 419;
      ipd_arm = context__.vals_i("ipd_arm");
      current_statement__ = 419;
      stan::math::check_greater_or_equal(function__, "ipd_arm", ipd_arm, 1);
      current_statement__ = 420;
      stan::math::validate_non_negative_index("ipd_trt", "narm_ipd", narm_ipd);
      current_statement__ = 421;
      context__.validate_dims("data initialization", "ipd_trt", "int",
        std::vector<size_t>{static_cast<size_t>(narm_ipd)});
      ipd_trt = std::vector<int>(narm_ipd, std::numeric_limits<int>::min());
      current_statement__ = 421;
      ipd_trt = context__.vals_i("ipd_trt");
      current_statement__ = 421;
      stan::math::check_greater_or_equal(function__, "ipd_trt", ipd_trt, 1);
      current_statement__ = 422;
      context__.validate_dims("data initialization", "narm_agd_arm", "int",
        std::vector<size_t>{});
      narm_agd_arm = std::numeric_limits<int>::min();
      current_statement__ = 422;
      narm_agd_arm = context__.vals_i("narm_agd_arm")[(1 - 1)];
      current_statement__ = 422;
      stan::math::check_greater_or_equal(function__, "narm_agd_arm",
        narm_agd_arm, 0);
      current_statement__ = 423;
      stan::math::validate_non_negative_index("agd_arm_trt", "narm_agd_arm",
        narm_agd_arm);
      current_statement__ = 424;
      context__.validate_dims("data initialization", "agd_arm_trt", "int",
        std::vector<size_t>{static_cast<size_t>(narm_agd_arm)});
      agd_arm_trt = std::vector<int>(narm_agd_arm,
                      std::numeric_limits<int>::min());
      current_statement__ = 424;
      agd_arm_trt = context__.vals_i("agd_arm_trt");
      current_statement__ = 424;
      stan::math::check_greater_or_equal(function__, "agd_arm_trt",
        agd_arm_trt, 1);
      current_statement__ = 425;
      stan::math::validate_non_negative_index("agd_contrast_trt",
        "ni_agd_contrast", ni_agd_contrast);
      current_statement__ = 426;
      context__.validate_dims("data initialization", "agd_contrast_trt",
        "int", std::vector<size_t>{static_cast<size_t>(ni_agd_contrast)});
      agd_contrast_trt = std::vector<int>(ni_agd_contrast,
                           std::numeric_limits<int>::min());
      current_statement__ = 426;
      agd_contrast_trt = context__.vals_i("agd_contrast_trt");
      current_statement__ = 426;
      stan::math::check_greater_or_equal(function__, "agd_contrast_trt",
        agd_contrast_trt, 1);
      current_statement__ = 427;
      stan::math::validate_non_negative_index("agd_contrast_trt_b",
        "ni_agd_contrast", ni_agd_contrast);
      current_statement__ = 428;
      context__.validate_dims("data initialization", "agd_contrast_trt_b",
        "int", std::vector<size_t>{static_cast<size_t>(ni_agd_contrast)});
      agd_contrast_trt_b = std::vector<int>(ni_agd_contrast,
                             std::numeric_limits<int>::min());
      current_statement__ = 428;
      agd_contrast_trt_b = context__.vals_i("agd_contrast_trt_b");
      current_statement__ = 428;
      stan::math::check_greater_or_equal(function__, "agd_contrast_trt_b",
        agd_contrast_trt_b, 1);
      current_statement__ = 429;
      context__.validate_dims("data initialization", "nt", "int",
        std::vector<size_t>{});
      nt = std::numeric_limits<int>::min();
      current_statement__ = 429;
      nt = context__.vals_i("nt")[(1 - 1)];
      current_statement__ = 429;
      stan::math::check_greater_or_equal(function__, "nt", nt, 1);
      current_statement__ = 430;
      context__.validate_dims("data initialization", "nX", "int",
        std::vector<size_t>{});
      nX = std::numeric_limits<int>::min();
      current_statement__ = 430;
      nX = context__.vals_i("nX")[(1 - 1)];
      current_statement__ = 430;
      stan::math::check_greater_or_equal(function__, "nX", nX, 0);
      current_statement__ = 431;
      context__.validate_dims("data initialization", "nchains", "int",
        std::vector<size_t>{});
      nchains = std::numeric_limits<int>::min();
      current_statement__ = 431;
      nchains = context__.vals_i("nchains")[(1 - 1)];
      current_statement__ = 431;
      stan::math::check_greater_or_equal(function__, "nchains", nchains, 1);
      current_statement__ = 432;
      context__.validate_dims("data initialization", "CHAIN_ID", "int",
        std::vector<size_t>{});
      CHAIN_ID = std::numeric_limits<int>::min();
      current_statement__ = 432;
      CHAIN_ID = context__.vals_i("CHAIN_ID")[(1 - 1)];
      current_statement__ = 432;
      stan::math::check_greater_or_equal(function__, "CHAIN_ID", CHAIN_ID, 1);
      current_statement__ = 432;
      stan::math::check_less_or_equal(function__, "CHAIN_ID", CHAIN_ID,
        nchains);
      current_statement__ = 433;
      stan::math::validate_non_negative_index("nint_vec", "nchains", nchains);
      current_statement__ = 434;
      context__.validate_dims("data initialization", "nint_vec", "int",
        std::vector<size_t>{static_cast<size_t>(nchains)});
      nint_vec = std::vector<int>(nchains, std::numeric_limits<int>::min());
      current_statement__ = 434;
      nint_vec = context__.vals_i("nint_vec");
      current_statement__ = 434;
      stan::math::check_greater_or_equal(function__, "nint_vec", nint_vec, 1);
      current_statement__ = 435;
      context__.validate_dims("data initialization", "nint_max", "int",
        std::vector<size_t>{});
      nint_max = std::numeric_limits<int>::min();
      current_statement__ = 435;
      nint_max = context__.vals_i("nint_max")[(1 - 1)];
      current_statement__ = 435;
      stan::math::check_greater_or_equal(function__, "nint_max", nint_max, 1);
      current_statement__ = 436;
      context__.validate_dims("data initialization", "int_thin", "int",
        std::vector<size_t>{});
      int_thin = std::numeric_limits<int>::min();
      current_statement__ = 436;
      int_thin = context__.vals_i("int_thin")[(1 - 1)];
      current_statement__ = 436;
      stan::math::check_greater_or_equal(function__, "int_thin", int_thin, 0);
      current_statement__ = 437;
      context__.validate_dims("data initialization", "link", "int",
        std::vector<size_t>{});
      link = std::numeric_limits<int>::min();
      current_statement__ = 437;
      link = context__.vals_i("link")[(1 - 1)];
      current_statement__ = 437;
      stan::math::check_greater_or_equal(function__, "link", link, 1);
      current_statement__ = 438;
      stan::math::validate_non_negative_index("agd_contrast_y",
        "ni_agd_contrast", ni_agd_contrast);
      current_statement__ = 439;
      context__.validate_dims("data initialization", "agd_contrast_y",
        "double", std::vector<size_t>{static_cast<size_t>(ni_agd_contrast)});
      agd_contrast_y_data__ = Eigen::Matrix<double,-1,1>::Constant(ni_agd_contrast,
                                std::numeric_limits<double>::quiet_NaN());
      new (&agd_contrast_y)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(agd_contrast_y_data__.data(),
        ni_agd_contrast);
      {
        std::vector<local_scalar_t__> agd_contrast_y_flat__;
        current_statement__ = 439;
        agd_contrast_y_flat__ = context__.vals_r("agd_contrast_y");
        current_statement__ = 439;
        pos__ = 1;
        current_statement__ = 439;
        for (int sym1__ = 1; sym1__ <= ni_agd_contrast; ++sym1__) {
          current_statement__ = 439;
          stan::model::assign(agd_contrast_y, agd_contrast_y_flat__[(pos__ -
            1)], "assigning variable agd_contrast_y",
            stan::model::index_uni(sym1__));
          current_statement__ = 439;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 440;
      stan::math::validate_non_negative_index("agd_contrast_Sigma",
        "ni_agd_contrast ? ni_agd_contrast : 1",
        (ni_agd_contrast ? ni_agd_contrast : 1));
      current_statement__ = 440;
      stan::math::validate_non_negative_index("agd_contrast_Sigma",
        "ni_agd_contrast ? ni_agd_contrast : 1",
        (ni_agd_contrast ? ni_agd_contrast : 1));
      current_statement__ = 441;
      context__.validate_dims("data initialization", "agd_contrast_Sigma",
        "double",
        std::vector<size_t>{static_cast<size_t>(
                              (ni_agd_contrast ? ni_agd_contrast : 1)),
          static_cast<size_t>((ni_agd_contrast ? ni_agd_contrast : 1))});
      agd_contrast_Sigma_data__ = Eigen::Matrix<double,-1,-1>::Constant((ni_agd_contrast ? ni_agd_contrast : 1),
                                    (ni_agd_contrast ? ni_agd_contrast : 1),
                                    std::numeric_limits<double>::quiet_NaN());
      new (&agd_contrast_Sigma)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(agd_contrast_Sigma_data__.data(),
        (ni_agd_contrast ? ni_agd_contrast : 1),
        (ni_agd_contrast ? ni_agd_contrast : 1));
      {
        std::vector<local_scalar_t__> agd_contrast_Sigma_flat__;
        current_statement__ = 441;
        agd_contrast_Sigma_flat__ = context__.vals_r("agd_contrast_Sigma");
        current_statement__ = 441;
        pos__ = 1;
        current_statement__ = 441;
        for (int sym1__ = 1; sym1__ <=
             (ni_agd_contrast ? ni_agd_contrast : 1); ++sym1__) {
          current_statement__ = 441;
          for (int sym2__ = 1; sym2__ <=
               (ni_agd_contrast ? ni_agd_contrast : 1); ++sym2__) {
            current_statement__ = 441;
            stan::model::assign(agd_contrast_Sigma,
              agd_contrast_Sigma_flat__[(pos__ - 1)],
              "assigning variable agd_contrast_Sigma",
              stan::model::index_uni(sym2__), stan::model::index_uni(sym1__));
            current_statement__ = 441;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 441;
      stan::math::check_cov_matrix(function__, "agd_contrast_Sigma",
        agd_contrast_Sigma);
      current_statement__ = 442;
      context__.validate_dims("data initialization", "QR", "int",
        std::vector<size_t>{});
      QR = std::numeric_limits<int>::min();
      current_statement__ = 442;
      QR = context__.vals_i("QR")[(1 - 1)];
      current_statement__ = 442;
      stan::math::check_greater_or_equal(function__, "QR", QR, 0);
      current_statement__ = 442;
      stan::math::check_less_or_equal(function__, "QR", QR, 1);
      current_statement__ = 443;
      stan::math::validate_non_negative_index("X",
        "ni_ipd + nint_max * (ni_agd_arm + ni_agd_contrast)", (ni_ipd +
        (nint_max * (ni_agd_arm + ni_agd_contrast))));
      current_statement__ = 444;
      stan::math::validate_non_negative_index("X", "nX", nX);
      current_statement__ = 445;
      context__.validate_dims("data initialization", "X", "double",
        std::vector<size_t>{static_cast<size_t>((ni_ipd + (nint_max *
                              (ni_agd_arm + ni_agd_contrast)))),
          static_cast<size_t>(nX)});
      X_data__ = Eigen::Matrix<double,-1,-1>::Constant((ni_ipd + (nint_max *
                   (ni_agd_arm + ni_agd_contrast))), nX,
                   std::numeric_limits<double>::quiet_NaN());
      new (&X) Eigen::Map<Eigen::Matrix<double,-1,-1>>(X_data__.data(),
        (ni_ipd + (nint_max * (ni_agd_arm + ni_agd_contrast))), nX);
      {
        std::vector<local_scalar_t__> X_flat__;
        current_statement__ = 445;
        X_flat__ = context__.vals_r("X");
        current_statement__ = 445;
        pos__ = 1;
        current_statement__ = 445;
        for (int sym1__ = 1; sym1__ <= nX; ++sym1__) {
          current_statement__ = 445;
          for (int sym2__ = 1; sym2__ <= (ni_ipd + (nint_max * (ni_agd_arm +
               ni_agd_contrast))); ++sym2__) {
            current_statement__ = 445;
            stan::model::assign(X, X_flat__[(pos__ - 1)],
              "assigning variable X", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 445;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 446;
      stan::math::validate_non_negative_index("R_inv", "QR ? nX : 0",
        (QR ? nX : 0));
      current_statement__ = 447;
      stan::math::validate_non_negative_index("R_inv", "QR ? nX : 0",
        (QR ? nX : 0));
      current_statement__ = 448;
      context__.validate_dims("data initialization", "R_inv", "double",
        std::vector<size_t>{static_cast<size_t>((QR ? nX : 0)),
          static_cast<size_t>((QR ? nX : 0))});
      R_inv_data__ = Eigen::Matrix<double,-1,-1>::Constant((QR ? nX : 0),
                       (QR ? nX : 0),
                       std::numeric_limits<double>::quiet_NaN());
      new (&R_inv)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(R_inv_data__.data(),
        (QR ? nX : 0), (QR ? nX : 0));
      {
        std::vector<local_scalar_t__> R_inv_flat__;
        current_statement__ = 448;
        R_inv_flat__ = context__.vals_r("R_inv");
        current_statement__ = 448;
        pos__ = 1;
        current_statement__ = 448;
        for (int sym1__ = 1; sym1__ <= (QR ? nX : 0); ++sym1__) {
          current_statement__ = 448;
          for (int sym2__ = 1; sym2__ <= (QR ? nX : 0); ++sym2__) {
            current_statement__ = 448;
            stan::model::assign(R_inv, R_inv_flat__[(pos__ - 1)],
              "assigning variable R_inv", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 448;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 449;
      context__.validate_dims("data initialization", "has_offset", "int",
        std::vector<size_t>{});
      has_offset = std::numeric_limits<int>::min();
      current_statement__ = 449;
      has_offset = context__.vals_i("has_offset")[(1 - 1)];
      current_statement__ = 449;
      stan::math::check_greater_or_equal(function__, "has_offset",
        has_offset, 0);
      current_statement__ = 449;
      stan::math::check_less_or_equal(function__, "has_offset", has_offset, 1);
      current_statement__ = 450;
      stan::math::validate_non_negative_index("offsets",
        "has_offset ? ni_ipd + nint_max * (ni_agd_arm + ni_agd_contrast) : 0",
        (has_offset ? (ni_ipd + (nint_max * (ni_agd_arm +
        ni_agd_contrast))) : 0));
      current_statement__ = 451;
      context__.validate_dims("data initialization", "offsets", "double",
        std::vector<size_t>{static_cast<size_t>((has_offset ? (ni_ipd +
                              (nint_max * (ni_agd_arm +
                              ni_agd_contrast))) : 0))});
      offsets_data__ = Eigen::Matrix<double,-1,1>::Constant((has_offset ? (ni_ipd
                         + (nint_max * (ni_agd_arm + ni_agd_contrast))) : 0),
                         std::numeric_limits<double>::quiet_NaN());
      new (&offsets)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(offsets_data__.data(),
        (has_offset ? (ni_ipd + (nint_max * (ni_agd_arm +
        ni_agd_contrast))) : 0));
      {
        std::vector<local_scalar_t__> offsets_flat__;
        current_statement__ = 451;
        offsets_flat__ = context__.vals_r("offsets");
        current_statement__ = 451;
        pos__ = 1;
        current_statement__ = 451;
        for (int sym1__ = 1; sym1__ <= (has_offset ? (ni_ipd + (nint_max *
             (ni_agd_arm + ni_agd_contrast))) : 0); ++sym1__) {
          current_statement__ = 451;
          stan::model::assign(offsets, offsets_flat__[(pos__ - 1)],
            "assigning variable offsets", stan::model::index_uni(sym1__));
          current_statement__ = 451;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 452;
      context__.validate_dims("data initialization", "RE", "int",
        std::vector<size_t>{});
      RE = std::numeric_limits<int>::min();
      current_statement__ = 452;
      RE = context__.vals_i("RE")[(1 - 1)];
      current_statement__ = 452;
      stan::math::check_greater_or_equal(function__, "RE", RE, 0);
      current_statement__ = 452;
      stan::math::check_less_or_equal(function__, "RE", RE, 1);
      current_statement__ = 453;
      stan::math::validate_non_negative_index("which_RE",
        "RE ? narm_ipd + narm_agd_arm + ni_agd_contrast : 0",
        (RE ? ((narm_ipd + narm_agd_arm) + ni_agd_contrast) : 0));
      current_statement__ = 454;
      context__.validate_dims("data initialization", "which_RE", "int",
        std::vector<size_t>{static_cast<size_t>((RE ? ((narm_ipd +
                              narm_agd_arm) + ni_agd_contrast) : 0))});
      which_RE = std::vector<int>((RE ? ((narm_ipd + narm_agd_arm) +
                   ni_agd_contrast) : 0), std::numeric_limits<int>::min());
      current_statement__ = 454;
      which_RE = context__.vals_i("which_RE");
      current_statement__ = 454;
      stan::math::check_greater_or_equal(function__, "which_RE", which_RE, 0);
      current_statement__ = 455;
      stan::math::validate_non_negative_index("RE_cor",
        "RE ? max(which_RE) : 1", (RE ? stan::math::max(which_RE) : 1));
      current_statement__ = 455;
      stan::math::validate_non_negative_index("RE_cor",
        "RE ? max(which_RE) : 1", (RE ? stan::math::max(which_RE) : 1));
      current_statement__ = 456;
      context__.validate_dims("data initialization", "RE_cor", "double",
        std::vector<size_t>{static_cast<size_t>(
                              (RE ? stan::math::max(which_RE) : 1)),
          static_cast<size_t>((RE ? stan::math::max(which_RE) : 1))});
      RE_cor_data__ = Eigen::Matrix<double,-1,-1>::Constant((RE ? stan::math::max(
                                                                    which_RE) : 1),
                        (RE ? stan::math::max(which_RE) : 1),
                        std::numeric_limits<double>::quiet_NaN());
      new (&RE_cor)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(RE_cor_data__.data(),
        (RE ? stan::math::max(which_RE) : 1),
        (RE ? stan::math::max(which_RE) : 1));
      {
        std::vector<local_scalar_t__> RE_cor_flat__;
        current_statement__ = 456;
        RE_cor_flat__ = context__.vals_r("RE_cor");
        current_statement__ = 456;
        pos__ = 1;
        current_statement__ = 456;
        for (int sym1__ = 1; sym1__ <=
             (RE ? stan::math::max(which_RE) : 1); ++sym1__) {
          current_statement__ = 456;
          for (int sym2__ = 1; sym2__ <=
               (RE ? stan::math::max(which_RE) : 1); ++sym2__) {
            current_statement__ = 456;
            stan::model::assign(RE_cor, RE_cor_flat__[(pos__ - 1)],
              "assigning variable RE_cor", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 456;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 456;
      stan::math::check_corr_matrix(function__, "RE_cor", RE_cor);
      current_statement__ = 457;
      context__.validate_dims("data initialization", "nodesplit", "int",
        std::vector<size_t>{});
      nodesplit = std::numeric_limits<int>::min();
      current_statement__ = 457;
      nodesplit = context__.vals_i("nodesplit")[(1 - 1)];
      current_statement__ = 457;
      stan::math::check_greater_or_equal(function__, "nodesplit", nodesplit,
        0);
      current_statement__ = 457;
      stan::math::check_less_or_equal(function__, "nodesplit", nodesplit, 1);
      current_statement__ = 458;
      context__.validate_dims("data initialization", "brmr_n_col", "int",
        std::vector<size_t>{});
      brmr_n_col = std::numeric_limits<int>::min();
      current_statement__ = 458;
      brmr_n_col = context__.vals_i("brmr_n_col")[(1 - 1)];
      current_statement__ = 458;
      stan::math::check_greater_or_equal(function__, "brmr_n_col",
        brmr_n_col, 0);
      current_statement__ = 459;
      stan::math::validate_non_negative_index("brmr_col", "brmr_n_col",
        brmr_n_col);
      current_statement__ = 460;
      context__.validate_dims("data initialization", "brmr_col", "int",
        std::vector<size_t>{static_cast<size_t>(brmr_n_col)});
      brmr_col = std::vector<int>(brmr_n_col,
                   std::numeric_limits<int>::min());
      current_statement__ = 460;
      brmr_col = context__.vals_i("brmr_col");
      current_statement__ = 460;
      stan::math::check_greater_or_equal(function__, "brmr_col", brmr_col, 1);
      current_statement__ = 461;
      context__.validate_dims("data initialization", "xbar_mu", "double",
        std::vector<size_t>{});
      xbar_mu = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 461;
      xbar_mu = context__.vals_r("xbar_mu")[(1 - 1)];
      current_statement__ = 462;
      context__.validate_dims("data initialization", "prior_intercept_dist",
        "int", std::vector<size_t>{});
      prior_intercept_dist = std::numeric_limits<int>::min();
      current_statement__ = 462;
      prior_intercept_dist = context__.vals_i("prior_intercept_dist")[(1 -
        1)];
      current_statement__ = 462;
      stan::math::check_greater_or_equal(function__, "prior_intercept_dist",
        prior_intercept_dist, 0);
      current_statement__ = 462;
      stan::math::check_less_or_equal(function__, "prior_intercept_dist",
        prior_intercept_dist, 3);
      current_statement__ = 463;
      context__.validate_dims("data initialization",
        "prior_intercept_location", "double", std::vector<size_t>{});
      prior_intercept_location = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 463;
      prior_intercept_location = context__.vals_r("prior_intercept_location")[(1
        - 1)];
      current_statement__ = 464;
      context__.validate_dims("data initialization", "prior_intercept_scale",
        "double", std::vector<size_t>{});
      prior_intercept_scale = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 464;
      prior_intercept_scale = context__.vals_r("prior_intercept_scale")[(1 -
        1)];
      current_statement__ = 464;
      stan::math::check_greater_or_equal(function__, "prior_intercept_scale",
        prior_intercept_scale, 0);
      current_statement__ = 465;
      context__.validate_dims("data initialization", "prior_intercept_df",
        "double", std::vector<size_t>{});
      prior_intercept_df = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 465;
      prior_intercept_df = context__.vals_r("prior_intercept_df")[(1 - 1)];
      current_statement__ = 465;
      stan::math::check_greater_or_equal(function__, "prior_intercept_df",
        prior_intercept_df, 0);
      current_statement__ = 466;
      context__.validate_dims("data initialization", "prior_trt_dist", "int",
        std::vector<size_t>{});
      prior_trt_dist = std::numeric_limits<int>::min();
      current_statement__ = 466;
      prior_trt_dist = context__.vals_i("prior_trt_dist")[(1 - 1)];
      current_statement__ = 466;
      stan::math::check_greater_or_equal(function__, "prior_trt_dist",
        prior_trt_dist, 0);
      current_statement__ = 466;
      stan::math::check_less_or_equal(function__, "prior_trt_dist",
        prior_trt_dist, 3);
      current_statement__ = 467;
      context__.validate_dims("data initialization", "prior_trt_location",
        "double", std::vector<size_t>{});
      prior_trt_location = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 467;
      prior_trt_location = context__.vals_r("prior_trt_location")[(1 - 1)];
      current_statement__ = 468;
      context__.validate_dims("data initialization", "prior_trt_scale",
        "double", std::vector<size_t>{});
      prior_trt_scale = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 468;
      prior_trt_scale = context__.vals_r("prior_trt_scale")[(1 - 1)];
      current_statement__ = 468;
      stan::math::check_greater_or_equal(function__, "prior_trt_scale",
        prior_trt_scale, 0);
      current_statement__ = 469;
      context__.validate_dims("data initialization", "prior_trt_df",
        "double", std::vector<size_t>{});
      prior_trt_df = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 469;
      prior_trt_df = context__.vals_r("prior_trt_df")[(1 - 1)];
      current_statement__ = 469;
      stan::math::check_greater_or_equal(function__, "prior_trt_df",
        prior_trt_df, 0);
      current_statement__ = 470;
      context__.validate_dims("data initialization", "prior_het_dist", "int",
        std::vector<size_t>{});
      prior_het_dist = std::numeric_limits<int>::min();
      current_statement__ = 470;
      prior_het_dist = context__.vals_i("prior_het_dist")[(1 - 1)];
      current_statement__ = 470;
      stan::math::check_greater_or_equal(function__, "prior_het_dist",
        prior_het_dist, 0);
      current_statement__ = 470;
      stan::math::check_less_or_equal(function__, "prior_het_dist",
        prior_het_dist, 6);
      current_statement__ = 471;
      context__.validate_dims("data initialization", "prior_het_type", "int",
        std::vector<size_t>{});
      prior_het_type = std::numeric_limits<int>::min();
      current_statement__ = 471;
      prior_het_type = context__.vals_i("prior_het_type")[(1 - 1)];
      current_statement__ = 471;
      stan::math::check_greater_or_equal(function__, "prior_het_type",
        prior_het_type, 1);
      current_statement__ = 471;
      stan::math::check_less_or_equal(function__, "prior_het_type",
        prior_het_type, 3);
      current_statement__ = 472;
      context__.validate_dims("data initialization", "prior_het_location",
        "double", std::vector<size_t>{});
      prior_het_location = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 472;
      prior_het_location = context__.vals_r("prior_het_location")[(1 - 1)];
      current_statement__ = 473;
      context__.validate_dims("data initialization", "prior_het_scale",
        "double", std::vector<size_t>{});
      prior_het_scale = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 473;
      prior_het_scale = context__.vals_r("prior_het_scale")[(1 - 1)];
      current_statement__ = 473;
      stan::math::check_greater_or_equal(function__, "prior_het_scale",
        prior_het_scale, 0);
      current_statement__ = 474;
      context__.validate_dims("data initialization", "prior_het_df",
        "double", std::vector<size_t>{});
      prior_het_df = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 474;
      prior_het_df = context__.vals_r("prior_het_df")[(1 - 1)];
      current_statement__ = 474;
      stan::math::check_greater_or_equal(function__, "prior_het_df",
        prior_het_df, 0);
      current_statement__ = 475;
      context__.validate_dims("data initialization", "prior_reg_dist", "int",
        std::vector<size_t>{});
      prior_reg_dist = std::numeric_limits<int>::min();
      current_statement__ = 475;
      prior_reg_dist = context__.vals_i("prior_reg_dist")[(1 - 1)];
      current_statement__ = 475;
      stan::math::check_greater_or_equal(function__, "prior_reg_dist",
        prior_reg_dist, 0);
      current_statement__ = 475;
      stan::math::check_less_or_equal(function__, "prior_reg_dist",
        prior_reg_dist, 3);
      current_statement__ = 476;
      context__.validate_dims("data initialization", "prior_reg_location",
        "double", std::vector<size_t>{});
      prior_reg_location = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 476;
      prior_reg_location = context__.vals_r("prior_reg_location")[(1 - 1)];
      current_statement__ = 477;
      context__.validate_dims("data initialization", "prior_reg_scale",
        "double", std::vector<size_t>{});
      prior_reg_scale = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 477;
      prior_reg_scale = context__.vals_r("prior_reg_scale")[(1 - 1)];
      current_statement__ = 477;
      stan::math::check_greater_or_equal(function__, "prior_reg_scale",
        prior_reg_scale, 0);
      current_statement__ = 478;
      context__.validate_dims("data initialization", "prior_reg_df",
        "double", std::vector<size_t>{});
      prior_reg_df = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 478;
      prior_reg_df = context__.vals_r("prior_reg_df")[(1 - 1)];
      current_statement__ = 478;
      stan::math::check_greater_or_equal(function__, "prior_reg_df",
        prior_reg_df, 0);
      current_statement__ = 479;
      context__.validate_dims("data initialization", "class_effects", "int",
        std::vector<size_t>{});
      class_effects = std::numeric_limits<int>::min();
      current_statement__ = 479;
      class_effects = context__.vals_i("class_effects")[(1 - 1)];
      current_statement__ = 479;
      stan::math::check_greater_or_equal(function__, "class_effects",
        class_effects, 0);
      current_statement__ = 479;
      stan::math::check_less_or_equal(function__, "class_effects",
        class_effects, 1);
      current_statement__ = 480;
      stan::math::validate_non_negative_index("which_CE",
        "class_effects ? nt - 1 : 0", (class_effects ? (nt - 1) : 0));
      current_statement__ = 481;
      context__.validate_dims("data initialization", "which_CE", "int",
        std::vector<size_t>{static_cast<size_t>((class_effects ? (nt -
                              1) : 0))});
      which_CE = std::vector<int>((class_effects ? (nt - 1) : 0),
                   std::numeric_limits<int>::min());
      current_statement__ = 481;
      which_CE = context__.vals_i("which_CE");
      current_statement__ = 481;
      stan::math::check_greater_or_equal(function__, "which_CE", which_CE, 0);
      current_statement__ = 482;
      stan::math::validate_non_negative_index("which_CE_sd",
        "class_effects ? nt - 1 : 0", (class_effects ? (nt - 1) : 0));
      current_statement__ = 483;
      context__.validate_dims("data initialization", "which_CE_sd", "int",
        std::vector<size_t>{static_cast<size_t>((class_effects ? (nt -
                              1) : 0))});
      which_CE_sd = std::vector<int>((class_effects ? (nt - 1) : 0),
                      std::numeric_limits<int>::min());
      current_statement__ = 483;
      which_CE_sd = context__.vals_i("which_CE_sd");
      current_statement__ = 483;
      stan::math::check_greater_or_equal(function__, "which_CE_sd",
        which_CE_sd, 0);
      current_statement__ = 484;
      context__.validate_dims("data initialization", "prior_class_mean_dist",
        "int", std::vector<size_t>{});
      prior_class_mean_dist = std::numeric_limits<int>::min();
      current_statement__ = 484;
      prior_class_mean_dist = context__.vals_i("prior_class_mean_dist")[(1 -
        1)];
      current_statement__ = 484;
      stan::math::check_greater_or_equal(function__, "prior_class_mean_dist",
        prior_class_mean_dist, 0);
      current_statement__ = 484;
      stan::math::check_less_or_equal(function__, "prior_class_mean_dist",
        prior_class_mean_dist, 3);
      current_statement__ = 485;
      context__.validate_dims("data initialization",
        "prior_class_mean_location", "double", std::vector<size_t>{});
      prior_class_mean_location = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 485;
      prior_class_mean_location = context__.vals_r("prior_class_mean_location")[(1
        - 1)];
      current_statement__ = 486;
      context__.validate_dims("data initialization",
        "prior_class_mean_scale", "double", std::vector<size_t>{});
      prior_class_mean_scale = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 486;
      prior_class_mean_scale = context__.vals_r("prior_class_mean_scale")[(1
        - 1)];
      current_statement__ = 486;
      stan::math::check_greater_or_equal(function__,
        "prior_class_mean_scale", prior_class_mean_scale, 0);
      current_statement__ = 487;
      context__.validate_dims("data initialization", "prior_class_mean_df",
        "double", std::vector<size_t>{});
      prior_class_mean_df = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 487;
      prior_class_mean_df = context__.vals_r("prior_class_mean_df")[(1 - 1)];
      current_statement__ = 487;
      stan::math::check_greater_or_equal(function__, "prior_class_mean_df",
        prior_class_mean_df, 0);
      current_statement__ = 488;
      context__.validate_dims("data initialization", "prior_class_sd_dist",
        "int", std::vector<size_t>{});
      prior_class_sd_dist = std::numeric_limits<int>::min();
      current_statement__ = 488;
      prior_class_sd_dist = context__.vals_i("prior_class_sd_dist")[(1 - 1)];
      current_statement__ = 488;
      stan::math::check_greater_or_equal(function__, "prior_class_sd_dist",
        prior_class_sd_dist, 0);
      current_statement__ = 488;
      stan::math::check_less_or_equal(function__, "prior_class_sd_dist",
        prior_class_sd_dist, 6);
      current_statement__ = 489;
      context__.validate_dims("data initialization",
        "prior_class_sd_location", "double", std::vector<size_t>{});
      prior_class_sd_location = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 489;
      prior_class_sd_location = context__.vals_r("prior_class_sd_location")[(1
        - 1)];
      current_statement__ = 490;
      context__.validate_dims("data initialization", "prior_class_sd_scale",
        "double", std::vector<size_t>{});
      prior_class_sd_scale = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 490;
      prior_class_sd_scale = context__.vals_r("prior_class_sd_scale")[(1 -
        1)];
      current_statement__ = 490;
      stan::math::check_greater_or_equal(function__, "prior_class_sd_scale",
        prior_class_sd_scale, 0);
      current_statement__ = 491;
      context__.validate_dims("data initialization", "prior_class_sd_df",
        "double", std::vector<size_t>{});
      prior_class_sd_df = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 491;
      prior_class_sd_df = context__.vals_r("prior_class_sd_df")[(1 - 1)];
      current_statement__ = 491;
      stan::math::check_greater_or_equal(function__, "prior_class_sd_df",
        prior_class_sd_df, 0);
      current_statement__ = 492;
      context__.validate_dims("data initialization", "ncat", "int",
        std::vector<size_t>{});
      ncat = std::numeric_limits<int>::min();
      current_statement__ = 492;
      ncat = context__.vals_i("ncat")[(1 - 1)];
      current_statement__ = 492;
      stan::math::check_greater_or_equal(function__, "ncat", ncat, 2);
      current_statement__ = 493;
      stan::math::validate_non_negative_index("ipd_r", "ni_ipd", ni_ipd);
      current_statement__ = 494;
      context__.validate_dims("data initialization", "ipd_r", "int",
        std::vector<size_t>{static_cast<size_t>(ni_ipd)});
      ipd_r = std::vector<int>(ni_ipd, std::numeric_limits<int>::min());
      current_statement__ = 494;
      ipd_r = context__.vals_i("ipd_r");
      current_statement__ = 494;
      stan::math::check_greater_or_equal(function__, "ipd_r", ipd_r, 1);
      current_statement__ = 494;
      stan::math::check_less_or_equal(function__, "ipd_r", ipd_r, ncat);
      current_statement__ = 495;
      stan::math::validate_non_negative_index("ipd_cat", "ni_ipd", ni_ipd);
      current_statement__ = 496;
      stan::math::validate_non_negative_index("ipd_cat", "ncat", ncat);
      current_statement__ = 497;
      context__.validate_dims("data initialization", "ipd_cat", "int",
        std::vector<size_t>{static_cast<size_t>(ni_ipd),
          static_cast<size_t>(ncat)});
      ipd_cat = std::vector<std::vector<int>>(ni_ipd,
                  std::vector<int>(ncat, std::numeric_limits<int>::min()));
      {
        std::vector<int> ipd_cat_flat__;
        current_statement__ = 497;
        ipd_cat_flat__ = context__.vals_i("ipd_cat");
        current_statement__ = 497;
        pos__ = 1;
        current_statement__ = 497;
        for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
          current_statement__ = 497;
          for (int sym2__ = 1; sym2__ <= ni_ipd; ++sym2__) {
            current_statement__ = 497;
            stan::model::assign(ipd_cat, ipd_cat_flat__[(pos__ - 1)],
              "assigning variable ipd_cat", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 497;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 497;
      stan::math::check_greater_or_equal(function__, "ipd_cat", ipd_cat, 0);
      current_statement__ = 497;
      stan::math::check_less_or_equal(function__, "ipd_cat", ipd_cat, ncat);
      current_statement__ = 498;
      stan::math::validate_non_negative_index("ipd_ncat", "ni_ipd", ni_ipd);
      current_statement__ = 499;
      context__.validate_dims("data initialization", "ipd_ncat", "int",
        std::vector<size_t>{static_cast<size_t>(ni_ipd)});
      ipd_ncat = std::vector<int>(ni_ipd, std::numeric_limits<int>::min());
      current_statement__ = 499;
      ipd_ncat = context__.vals_i("ipd_ncat");
      current_statement__ = 499;
      stan::math::check_greater_or_equal(function__, "ipd_ncat", ipd_ncat, 2);
      current_statement__ = 499;
      stan::math::check_less_or_equal(function__, "ipd_ncat", ipd_ncat, ncat);
      current_statement__ = 500;
      stan::math::validate_non_negative_index("agd_arm_r", "ni_agd_arm",
        ni_agd_arm);
      current_statement__ = 501;
      stan::math::validate_non_negative_index("agd_arm_r", "ncat", ncat);
      current_statement__ = 502;
      context__.validate_dims("data initialization", "agd_arm_r", "int",
        std::vector<size_t>{static_cast<size_t>(ni_agd_arm),
          static_cast<size_t>(ncat)});
      agd_arm_r = std::vector<std::vector<int>>(ni_agd_arm,
                    std::vector<int>(ncat, std::numeric_limits<int>::min()));
      {
        std::vector<int> agd_arm_r_flat__;
        current_statement__ = 502;
        agd_arm_r_flat__ = context__.vals_i("agd_arm_r");
        current_statement__ = 502;
        pos__ = 1;
        current_statement__ = 502;
        for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
          current_statement__ = 502;
          for (int sym2__ = 1; sym2__ <= ni_agd_arm; ++sym2__) {
            current_statement__ = 502;
            stan::model::assign(agd_arm_r, agd_arm_r_flat__[(pos__ - 1)],
              "assigning variable agd_arm_r", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 502;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 502;
      stan::math::check_greater_or_equal(function__, "agd_arm_r", agd_arm_r,
        0);
      current_statement__ = 503;
      stan::math::validate_non_negative_index("agd_arm_n", "ni_agd_arm",
        ni_agd_arm);
      current_statement__ = 504;
      context__.validate_dims("data initialization", "agd_arm_n", "double",
        std::vector<size_t>{static_cast<size_t>(ni_agd_arm)});
      agd_arm_n_data__ = Eigen::Matrix<double,-1,1>::Constant(ni_agd_arm,
                           std::numeric_limits<double>::quiet_NaN());
      new (&agd_arm_n)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(agd_arm_n_data__.data(),
        ni_agd_arm);
      {
        std::vector<local_scalar_t__> agd_arm_n_flat__;
        current_statement__ = 504;
        agd_arm_n_flat__ = context__.vals_r("agd_arm_n");
        current_statement__ = 504;
        pos__ = 1;
        current_statement__ = 504;
        for (int sym1__ = 1; sym1__ <= ni_agd_arm; ++sym1__) {
          current_statement__ = 504;
          stan::model::assign(agd_arm_n, agd_arm_n_flat__[(pos__ - 1)],
            "assigning variable agd_arm_n", stan::model::index_uni(sym1__));
          current_statement__ = 504;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 505;
      stan::math::validate_non_negative_index("agd_arm_cat", "ni_agd_arm",
        ni_agd_arm);
      current_statement__ = 506;
      stan::math::validate_non_negative_index("agd_arm_cat", "ncat", ncat);
      current_statement__ = 507;
      context__.validate_dims("data initialization", "agd_arm_cat", "int",
        std::vector<size_t>{static_cast<size_t>(ni_agd_arm),
          static_cast<size_t>(ncat)});
      agd_arm_cat = std::vector<std::vector<int>>(ni_agd_arm,
                      std::vector<int>(ncat, std::numeric_limits<int>::min()));
      {
        std::vector<int> agd_arm_cat_flat__;
        current_statement__ = 507;
        agd_arm_cat_flat__ = context__.vals_i("agd_arm_cat");
        current_statement__ = 507;
        pos__ = 1;
        current_statement__ = 507;
        for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
          current_statement__ = 507;
          for (int sym2__ = 1; sym2__ <= ni_agd_arm; ++sym2__) {
            current_statement__ = 507;
            stan::model::assign(agd_arm_cat, agd_arm_cat_flat__[(pos__ - 1)],
              "assigning variable agd_arm_cat",
              stan::model::index_uni(sym2__), stan::model::index_uni(sym1__));
            current_statement__ = 507;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 507;
      stan::math::check_greater_or_equal(function__, "agd_arm_cat",
        agd_arm_cat, 0);
      current_statement__ = 507;
      stan::math::check_less_or_equal(function__, "agd_arm_cat", agd_arm_cat,
        ncat);
      current_statement__ = 508;
      stan::math::validate_non_negative_index("agd_arm_ncat", "ni_agd_arm",
        ni_agd_arm);
      current_statement__ = 509;
      context__.validate_dims("data initialization", "agd_arm_ncat", "int",
        std::vector<size_t>{static_cast<size_t>(ni_agd_arm)});
      agd_arm_ncat = std::vector<int>(ni_agd_arm,
                       std::numeric_limits<int>::min());
      current_statement__ = 509;
      agd_arm_ncat = context__.vals_i("agd_arm_ncat");
      current_statement__ = 509;
      stan::math::check_greater_or_equal(function__, "agd_arm_ncat",
        agd_arm_ncat, 2);
      current_statement__ = 509;
      stan::math::check_less_or_equal(function__, "agd_arm_ncat",
        agd_arm_ncat, ncat);
      current_statement__ = 510;
      context__.validate_dims("data initialization", "prior_aux_dist", "int",
        std::vector<size_t>{});
      prior_aux_dist = std::numeric_limits<int>::min();
      current_statement__ = 510;
      prior_aux_dist = context__.vals_i("prior_aux_dist")[(1 - 1)];
      current_statement__ = 510;
      stan::math::check_greater_or_equal(function__, "prior_aux_dist",
        prior_aux_dist, 0);
      current_statement__ = 510;
      stan::math::check_less_or_equal(function__, "prior_aux_dist",
        prior_aux_dist, 6);
      current_statement__ = 511;
      context__.validate_dims("data initialization", "prior_aux_location",
        "double", std::vector<size_t>{});
      prior_aux_location = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 511;
      prior_aux_location = context__.vals_r("prior_aux_location")[(1 - 1)];
      current_statement__ = 512;
      context__.validate_dims("data initialization", "prior_aux_scale",
        "double", std::vector<size_t>{});
      prior_aux_scale = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 512;
      prior_aux_scale = context__.vals_r("prior_aux_scale")[(1 - 1)];
      current_statement__ = 512;
      stan::math::check_greater_or_equal(function__, "prior_aux_scale",
        prior_aux_scale, 0);
      current_statement__ = 513;
      context__.validate_dims("data initialization", "prior_aux_df",
        "double", std::vector<size_t>{});
      prior_aux_df = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 513;
      prior_aux_df = context__.vals_r("prior_aux_df")[(1 - 1)];
      current_statement__ = 513;
      stan::math::check_greater_or_equal(function__, "prior_aux_df",
        prior_aux_df, 0);
      current_statement__ = 514;
      stan::math::validate_non_negative_index("theta_ipd0", "ni_ipd", ni_ipd);
      current_statement__ = 515;
      stan::math::validate_non_negative_index("theta_ipd0", "ncat", ncat);
      current_statement__ = 516;
      theta_ipd0 = std::vector<Eigen::Matrix<double,-1,1>>(ni_ipd,
                     Eigen::Matrix<double,-1,1>::Constant(ncat,
                       std::numeric_limits<double>::quiet_NaN()));
      current_statement__ = 516;
      stan::model::assign(theta_ipd0,
        stan::math::rep_array(stan::math::rep_vector(0, ncat), ni_ipd),
        "assigning variable theta_ipd0");
      current_statement__ = 517;
      stan::math::validate_non_negative_index("theta_agd_arm_bar0",
        "ni_agd_arm", ni_agd_arm);
      current_statement__ = 518;
      stan::math::validate_non_negative_index("theta_agd_arm_bar0", "ncat",
        ncat);
      current_statement__ = 519;
      theta_agd_arm_bar0 = std::vector<Eigen::Matrix<double,-1,1>>(ni_agd_arm,
                             Eigen::Matrix<double,-1,1>::Constant(ncat,
                               std::numeric_limits<double>::quiet_NaN()));
      current_statement__ = 519;
      stan::model::assign(theta_agd_arm_bar0,
        stan::math::rep_array(stan::math::rep_vector(0, ncat), ni_agd_arm),
        "assigning variable theta_agd_arm_bar0");
      current_statement__ = 520;
      nint = std::numeric_limits<int>::min();
      current_statement__ = 520;
      nint = stan::model::rvalue(nint_vec, "nint_vec",
               stan::model::index_uni(CHAIN_ID));
      current_statement__ = 521;
      n_delta = std::numeric_limits<int>::min();
      current_statement__ = 521;
      n_delta = (RE ? stan::math::max(which_RE) : 0);
      current_statement__ = 522;
      stan::math::validate_non_negative_index("RE_mu", "n_delta", n_delta);
      current_statement__ = 523;
      RE_mu_data__ = Eigen::Matrix<double,-1,1>::Constant(n_delta,
                       std::numeric_limits<double>::quiet_NaN());
      new (&RE_mu)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(RE_mu_data__.data(), n_delta);
      current_statement__ = 523;
      stan::model::assign(RE_mu, stan::math::rep_vector(0, n_delta),
        "assigning variable RE_mu");
      current_statement__ = 524;
      REdummy_data__ = Eigen::Matrix<double,-1,-1>::Constant(0, 0,
                         std::numeric_limits<double>::quiet_NaN());
      new (&REdummy)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(REdummy_data__.data(), 0, 0);
      current_statement__ = 525;
      stan::math::validate_non_negative_index("RE_L", "n_delta", n_delta);
      current_statement__ = 525;
      stan::math::validate_non_negative_index("RE_L", "n_delta", n_delta);
      current_statement__ = 526;
      RE_L_data__ = Eigen::Matrix<double,-1,-1>::Constant(n_delta, n_delta,
                      std::numeric_limits<double>::quiet_NaN());
      new (&RE_L) Eigen::Map<Eigen::Matrix<double,-1,-1>>(RE_L_data__.data(),
        n_delta, n_delta);
      current_statement__ = 526;
      stan::model::assign(RE_L,
        (n_delta ? stan::math::eval(stan::math::cholesky_decompose(RE_cor)) : 
        stan::math::eval(REdummy)), "assigning variable RE_L");
      current_statement__ = 527;
      wdummy_data__ = Eigen::Matrix<double,-1,1>::Constant(0,
                        std::numeric_limits<double>::quiet_NaN());
      new (&wdummy)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(wdummy_data__.data(), 0);
      current_statement__ = 528;
      vudummy = std::vector<int>(0, std::numeric_limits<int>::min());
      current_statement__ = 529;
      RE_L_nz = std::numeric_limits<int>::min();
      current_statement__ = 529;
      RE_L_nz = count_nonzero(RE_L, pstream__);
      current_statement__ = 530;
      RE_sparse = std::numeric_limits<int>::min();
      current_statement__ = 530;
      RE_sparse = stan::math::logical_lte(((RE_L_nz * 1.0) /
                    stan::math::num_elements(RE_L)), 0.1);
      current_statement__ = 531;
      stan::math::validate_non_negative_index("RE_L_w",
        "RE_sparse ? RE_L_nz : 0", (RE_sparse ? RE_L_nz : 0));
      current_statement__ = 532;
      RE_L_w_data__ = Eigen::Matrix<double,-1,1>::Constant((RE_sparse ? RE_L_nz : 0),
                        std::numeric_limits<double>::quiet_NaN());
      new (&RE_L_w)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(RE_L_w_data__.data(),
        (RE_sparse ? RE_L_nz : 0));
      current_statement__ = 532;
      stan::model::assign(RE_L_w,
        (RE_sparse ? stan::math::eval(stan::math::csr_extract_w(RE_L)) : 
        stan::math::eval(wdummy)), "assigning variable RE_L_w");
      current_statement__ = 533;
      stan::math::validate_non_negative_index("RE_L_v",
        "RE_sparse ? RE_L_nz : 0", (RE_sparse ? RE_L_nz : 0));
      current_statement__ = 534;
      RE_L_v = std::vector<int>((RE_sparse ? RE_L_nz : 0),
                 std::numeric_limits<int>::min());
      current_statement__ = 534;
      stan::model::assign(RE_L_v,
        (RE_sparse ? stan::math::csr_extract_v(RE_L) : vudummy),
        "assigning variable RE_L_v");
      current_statement__ = 535;
      stan::math::validate_non_negative_index("RE_L_u",
        "RE_sparse ? n_delta + 1 : 0", (RE_sparse ? (n_delta + 1) : 0));
      current_statement__ = 536;
      RE_L_u = std::vector<int>((RE_sparse ? (n_delta + 1) : 0),
                 std::numeric_limits<int>::min());
      current_statement__ = 536;
      stan::model::assign(RE_L_u,
        (RE_sparse ? stan::math::csr_extract_u(RE_L) : vudummy),
        "assigning variable RE_L_u");
      current_statement__ = 537;
      totns = std::numeric_limits<int>::min();
      current_statement__ = 537;
      totns = (ns_ipd + ns_agd_arm);
      current_statement__ = 538;
      stan::math::validate_non_negative_index("trt",
        "narm_ipd + narm_agd_arm + ni_agd_contrast", ((narm_ipd +
        narm_agd_arm) + ni_agd_contrast));
      current_statement__ = 539;
      trt = std::vector<int>(((narm_ipd + narm_agd_arm) + ni_agd_contrast),
              std::numeric_limits<int>::min());
      current_statement__ = 539;
      stan::model::assign(trt,
        stan::math::append_array(
          stan::math::append_array(ipd_trt, agd_arm_trt), agd_contrast_trt),
        "assigning variable trt");
      current_statement__ = 540;
      stan::math::validate_non_negative_index("Xdummy", "nX", nX);
      current_statement__ = 541;
      Xdummy_data__ = Eigen::Matrix<double,-1,-1>::Constant(0, nX,
                        std::numeric_limits<double>::quiet_NaN());
      new (&Xdummy)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(Xdummy_data__.data(), 0, nX);
      current_statement__ = 542;
      stan::math::validate_non_negative_index("X_ipd", "ni_ipd", ni_ipd);
      current_statement__ = 543;
      stan::math::validate_non_negative_index("X_ipd", "nX", nX);
      current_statement__ = 544;
      X_ipd_data__ = Eigen::Matrix<double,-1,-1>::Constant(ni_ipd, nX,
                       std::numeric_limits<double>::quiet_NaN());
      new (&X_ipd)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(X_ipd_data__.data(), ni_ipd,
        nX);
      current_statement__ = 544;
      stan::model::assign(X_ipd,
        (ni_ipd ? stan::math::eval(
                    stan::model::rvalue(X, "X",
                      stan::model::index_min_max(1, ni_ipd))) : stan::math::eval(
                                                                  Xdummy)),
        "assigning variable X_ipd");
      current_statement__ = 545;
      stan::math::validate_non_negative_index("X_agd_arm",
        "nint_max * ni_agd_arm", (nint_max * ni_agd_arm));
      current_statement__ = 546;
      stan::math::validate_non_negative_index("X_agd_arm", "nX", nX);
      current_statement__ = 547;
      X_agd_arm_data__ = Eigen::Matrix<double,-1,-1>::Constant((nint_max *
                           ni_agd_arm), nX,
                           std::numeric_limits<double>::quiet_NaN());
      new (&X_agd_arm)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(X_agd_arm_data__.data(),
        (nint_max * ni_agd_arm), nX);
      current_statement__ = 547;
      stan::model::assign(X_agd_arm,
        (ni_agd_arm ? stan::math::eval(
                        stan::model::rvalue(X, "X",
                          stan::model::index_min_max((ni_ipd + 1), (ni_ipd +
                            (nint_max * ni_agd_arm))))) : stan::math::eval(
                                                            Xdummy)),
        "assigning variable X_agd_arm");
      current_statement__ = 548;
      stan::math::validate_non_negative_index("X_agd_contrast",
        "nint_max * ni_agd_contrast", (nint_max * ni_agd_contrast));
      current_statement__ = 549;
      stan::math::validate_non_negative_index("X_agd_contrast", "nX", nX);
      current_statement__ = 550;
      X_agd_contrast_data__ = Eigen::Matrix<double,-1,-1>::Constant((nint_max
                                * ni_agd_contrast), nX,
                                std::numeric_limits<double>::quiet_NaN());
      new (&X_agd_contrast)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(X_agd_contrast_data__.data(),
        (nint_max * ni_agd_contrast), nX);
      current_statement__ = 550;
      stan::model::assign(X_agd_contrast,
        (ni_agd_contrast ? stan::math::eval(
                             stan::model::rvalue(X, "X",
                               stan::model::index_min_max(((ni_ipd +
                                 (nint_max * ni_agd_arm)) + 1), (ni_ipd +
                                 (nint_max * (ni_agd_arm + ni_agd_contrast)))))) : 
        stan::math::eval(Xdummy)), "assigning variable X_agd_contrast");
      current_statement__ = 551;
      odummy_data__ = Eigen::Matrix<double,-1,1>::Constant(0,
                        std::numeric_limits<double>::quiet_NaN());
      new (&odummy)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(odummy_data__.data(), 0);
      current_statement__ = 552;
      stan::math::validate_non_negative_index("offset_ipd",
        "has_offset && ni_ipd ? ni_ipd : 0",
        ((stan::math::primitive_value(has_offset) &&
        stan::math::primitive_value(ni_ipd)) ? ni_ipd : 0));
      current_statement__ = 553;
      offset_ipd_data__ = Eigen::Matrix<double,-1,1>::Constant(((stan::math::primitive_value(
                                                                   has_offset)
                            &&
                            stan::math::primitive_value(ni_ipd)) ? ni_ipd : 0),
                            std::numeric_limits<double>::quiet_NaN());
      new (&offset_ipd)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(offset_ipd_data__.data(),
        ((stan::math::primitive_value(has_offset) &&
        stan::math::primitive_value(ni_ipd)) ? ni_ipd : 0));
      current_statement__ = 553;
      stan::model::assign(offset_ipd,
        ((stan::math::primitive_value(has_offset) &&
        stan::math::primitive_value(ni_ipd)) ? stan::math::eval(
                                                 stan::model::rvalue(offsets,
                                                   "offsets",
                                                   stan::model::index_min_max(
                                                     1, ni_ipd))) : stan::math::eval(
                                                                    odummy)),
        "assigning variable offset_ipd");
      current_statement__ = 554;
      stan::math::validate_non_negative_index("offset_agd_arm",
        "has_offset && ni_agd_arm ? nint_max * ni_agd_arm : 0",
        ((stan::math::primitive_value(has_offset) &&
        stan::math::primitive_value(ni_agd_arm)) ? (nint_max *
        ni_agd_arm) : 0));
      current_statement__ = 555;
      offset_agd_arm_data__ = Eigen::Matrix<double,-1,1>::Constant(((
                                stan::math::primitive_value(has_offset) &&
                                stan::math::primitive_value(ni_agd_arm)) ? (nint_max
                                * ni_agd_arm) : 0),
                                std::numeric_limits<double>::quiet_NaN());
      new (&offset_agd_arm)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(offset_agd_arm_data__.data(),
        ((stan::math::primitive_value(has_offset) &&
        stan::math::primitive_value(ni_agd_arm)) ? (nint_max *
        ni_agd_arm) : 0));
      current_statement__ = 555;
      stan::model::assign(offset_agd_arm,
        ((stan::math::primitive_value(has_offset) &&
        stan::math::primitive_value(ni_agd_arm)) ? stan::math::eval(
                                                     stan::model::rvalue(
                                                       offsets, "offsets",
                                                       stan::model::index_min_max(
                                                         (ni_ipd + 1),
                                                         (ni_ipd + (nint_max
                                                         * ni_agd_arm))))) : 
        stan::math::eval(odummy)), "assigning variable offset_agd_arm");
      current_statement__ = 556;
      stan::math::validate_non_negative_index("offset_agd_contrast",
        "has_offset && ni_agd_contrast ? nint_max * ni_agd_contrast : 0",
        ((stan::math::primitive_value(has_offset) &&
        stan::math::primitive_value(ni_agd_contrast)) ? (nint_max *
        ni_agd_contrast) : 0));
      current_statement__ = 557;
      offset_agd_contrast_data__ = Eigen::Matrix<double,-1,1>::Constant(((
                                     stan::math::primitive_value(has_offset)
                                     &&
                                     stan::math::primitive_value(
                                       ni_agd_contrast)) ? (nint_max *
                                     ni_agd_contrast) : 0),
                                     std::numeric_limits<double>::quiet_NaN());
      new (&offset_agd_contrast)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(offset_agd_contrast_data__.data(),
        ((stan::math::primitive_value(has_offset) &&
        stan::math::primitive_value(ni_agd_contrast)) ? (nint_max *
        ni_agd_contrast) : 0));
      current_statement__ = 557;
      stan::model::assign(offset_agd_contrast,
        ((stan::math::primitive_value(has_offset) &&
        stan::math::primitive_value(ni_agd_contrast)) ? stan::math::eval(
                                                          stan::model::rvalue(
                                                            offsets,
                                                            "offsets",
                                                            stan::model::index_min_max(
                                                              ((ni_ipd +
                                                              (nint_max *
                                                              ni_agd_arm)) +
                                                              1), (ni_ipd +
                                                              (nint_max *
                                                              (ni_agd_arm +
                                                              ni_agd_contrast)))))) : 
        stan::math::eval(odummy)), "assigning variable offset_agd_contrast");
      current_statement__ = 558;
      n_int_thin = std::numeric_limits<int>::min();
      current_statement__ = 558;
      n_int_thin = ((stan::math::primitive_value(
                       stan::math::logical_gt(nint_max, 1))
        &&
        stan::math::primitive_value(stan::math::logical_gt(int_thin, 0))) ? (nint
        / int_thin) : 0);
      current_statement__ = 559;
      stan::math::validate_non_negative_index("inv_Sigma",
        "ni_agd_contrast ? ni_agd_contrast : 1",
        (ni_agd_contrast ? ni_agd_contrast : 1));
      current_statement__ = 560;
      stan::math::validate_non_negative_index("inv_Sigma",
        "ni_agd_contrast ? ni_agd_contrast : 1",
        (ni_agd_contrast ? ni_agd_contrast : 1));
      current_statement__ = 561;
      inv_Sigma_data__ = Eigen::Matrix<double,-1,-1>::Constant((ni_agd_contrast ? ni_agd_contrast : 1),
                           (ni_agd_contrast ? ni_agd_contrast : 1),
                           std::numeric_limits<double>::quiet_NaN());
      new (&inv_Sigma)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(inv_Sigma_data__.data(),
        (ni_agd_contrast ? ni_agd_contrast : 1),
        (ni_agd_contrast ? ni_agd_contrast : 1));
      current_statement__ = 561;
      stan::model::assign(inv_Sigma,
        stan::math::inverse_spd(agd_contrast_Sigma),
        "assigning variable inv_Sigma");
      current_statement__ = 562;
      stan::math::validate_non_negative_index("nc_agd_contrast",
        "ns_agd_contrast", ns_agd_contrast);
      current_statement__ = 563;
      nc_agd_contrast = std::vector<int>(ns_agd_contrast,
                          std::numeric_limits<int>::min());
      current_statement__ = 577;
      if (ns_agd_contrast) {
        int s = std::numeric_limits<int>::min();
        current_statement__ = 564;
        s = 1;
        int c = std::numeric_limits<int>::min();
        current_statement__ = 565;
        c = 1;
        current_statement__ = 574;
        for (int i = 1; i <= (ni_agd_contrast - 1); ++i) {
          current_statement__ = 572;
          if (stan::math::logical_eq(
                stan::model::rvalue(agd_contrast_Sigma, "agd_contrast_Sigma",
                  stan::model::index_uni(i), stan::model::index_uni((i + 1))),
                0)) {
            current_statement__ = 568;
            stan::model::assign(nc_agd_contrast, c,
              "assigning variable nc_agd_contrast", stan::model::index_uni(s));
            current_statement__ = 569;
            s = (s + 1);
            current_statement__ = 570;
            c = 1;
          } else {
            current_statement__ = 566;
            c = (c + 1);
          }
        }
        current_statement__ = 575;
        stan::model::assign(nc_agd_contrast, c,
          "assigning variable nc_agd_contrast", stan::model::index_uni(s));
      }
      current_statement__ = 578;
      n_class_trts = std::numeric_limits<int>::min();
      current_statement__ = 578;
      n_class_trts = stan::math::num_elements(which_gt0a(which_CE, pstream__));
      current_statement__ = 579;
      stan::math::validate_non_negative_index("which_class_trt",
        "n_class_trts", n_class_trts);
      current_statement__ = 580;
      which_class_trt = std::vector<int>(n_class_trts,
                          std::numeric_limits<int>::min());
      current_statement__ = 580;
      stan::model::assign(which_class_trt, which_gt0a(which_CE, pstream__),
        "assigning variable which_class_trt");
      current_statement__ = 581;
      n_class = std::numeric_limits<int>::min();
      current_statement__ = 581;
      n_class = (class_effects ? stan::math::max(which_CE) : 0);
      current_statement__ = 582;
      stan::math::validate_non_negative_index("which_fclass",
        "class_effects ? nt - 1 : 0", (class_effects ? (nt - 1) : 0));
      current_statement__ = 583;
      which_fclass = std::vector<int>((class_effects ? (nt - 1) : 0),
                       std::numeric_limits<int>::min());
      current_statement__ = 594;
      if (class_effects) {
        int count = std::numeric_limits<int>::min();
        current_statement__ = 584;
        count = 1;
        current_statement__ = 592;
        for (int t = 1; t <= (nt - 1); ++t) {
          current_statement__ = 590;
          if (stan::math::logical_gt(
                stan::model::rvalue(which_CE_sd, "which_CE_sd",
                  stan::model::index_uni(t)), 0)) {
            current_statement__ = 587;
            stan::model::assign(which_fclass, count,
              "assigning variable which_fclass", stan::model::index_uni(t));
            current_statement__ = 588;
            count = (count + 1);
          } else {
            current_statement__ = 585;
            stan::model::assign(which_fclass, 0,
              "assigning variable which_fclass", stan::model::index_uni(t));
          }
        }
      }
      current_statement__ = 520;
      stan::math::check_greater_or_equal(function__, "nint", nint, 1);
      current_statement__ = 520;
      stan::math::check_less_or_equal(function__, "nint", nint, nint_max);
      current_statement__ = 521;
      stan::math::check_greater_or_equal(function__, "n_delta", n_delta, 0);
      current_statement__ = 526;
      stan::math::check_cholesky_factor_corr(function__, "RE_L", RE_L);
      current_statement__ = 539;
      stan::math::check_greater_or_equal(function__, "trt", trt, 1);
      current_statement__ = 578;
      stan::math::check_greater_or_equal(function__, "n_class_trts",
        n_class_trts, 0);
      current_statement__ = 581;
      stan::math::check_greater_or_equal(function__, "n_class", n_class, 0);
      current_statement__ = 583;
      stan::math::check_greater_or_equal(function__, "which_fclass",
        which_fclass, 0);
      current_statement__ = 595;
      stan::math::validate_non_negative_index("beta_tilde", "nX", nX);
      current_statement__ = 596;
      stan::math::validate_non_negative_index("u_delta", "n_delta", n_delta);
      current_statement__ = 597;
      tau_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 597;
      tau_1dim__ = (RE ? 1 : 0);
      current_statement__ = 597;
      stan::math::validate_non_negative_index("tau", "RE ? 1 : 0", tau_1dim__);
      current_statement__ = 598;
      class_mean_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 598;
      class_mean_1dim__ = (class_effects ? stan::math::max(which_CE) : 0);
      current_statement__ = 598;
      stan::math::validate_non_negative_index("class_mean",
        "class_effects ? max(which_CE) : 0", class_mean_1dim__);
      current_statement__ = 599;
      class_sd_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 599;
      class_sd_1dim__ = (class_effects ? stan::math::max(which_CE_sd) : 0);
      current_statement__ = 599;
      stan::math::validate_non_negative_index("class_sd",
        "class_effects ? max(which_CE_sd) : 0", class_sd_1dim__);
      current_statement__ = 600;
      z_class_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 600;
      z_class_1dim__ = (class_effects ? n_class_trts : 0);
      current_statement__ = 600;
      stan::math::validate_non_negative_index("z_class",
        "class_effects ? n_class_trts : 0", z_class_1dim__);
      current_statement__ = 601;
      f_cc_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 601;
      f_cc_1dim__ = (ncat - 2);
      current_statement__ = 601;
      stan::math::validate_non_negative_index("f_cc", "ncat - 2", f_cc_1dim__);
      current_statement__ = 602;
      cc_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 602;
      cc_1dim__ = (ncat - 1);
      current_statement__ = 602;
      stan::math::validate_non_negative_index("cc", "ncat - 1", cc_1dim__);
      current_statement__ = 603;
      stan::math::validate_non_negative_index("theta_ipd", "ni_ipd", ni_ipd);
      current_statement__ = 604;
      stan::math::validate_non_negative_index("theta_ipd", "ncat", ncat);
      current_statement__ = 605;
      theta_agd_arm_ii_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 605;
      theta_agd_arm_ii_1dim__ = (stan::math::logical_gt(nint_max, 1) ? (nint
        * ni_agd_arm) : 0);
      current_statement__ = 605;
      stan::math::validate_non_negative_index("theta_agd_arm_ii",
        "nint_max > 1 ? nint * ni_agd_arm : 0", theta_agd_arm_ii_1dim__);
      current_statement__ = 606;
      theta_agd_arm_ii_2dim__ = std::numeric_limits<int>::min();
      current_statement__ = 606;
      theta_agd_arm_ii_2dim__ = (stan::math::logical_gt(nint_max, 1) ? (ncat
        - 1) : 0);
      current_statement__ = 606;
      stan::math::validate_non_negative_index("theta_agd_arm_ii",
        "nint_max > 1 ? ncat - 1 : 0", theta_agd_arm_ii_2dim__);
      current_statement__ = 607;
      stan::math::validate_non_negative_index("q_agd_arm_bar", "ni_agd_arm",
        ni_agd_arm);
      current_statement__ = 608;
      stan::math::validate_non_negative_index("q_agd_arm_bar", "ncat", ncat);
      current_statement__ = 609;
      stan::math::validate_non_negative_index("theta_agd_arm_bar",
        "ni_agd_arm", ni_agd_arm);
      current_statement__ = 610;
      stan::math::validate_non_negative_index("theta_agd_arm_bar", "ncat",
        ncat);
      current_statement__ = 611;
      stan::math::validate_non_negative_index("eta_ipd", "ni_ipd", ni_ipd);
      current_statement__ = 612;
      stan::math::validate_non_negative_index("f_delta", "n_delta", n_delta);
      current_statement__ = 613;
      f_class_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 613;
      f_class_1dim__ = (class_effects ? stan::math::max(which_fclass) : 0);
      current_statement__ = 613;
      stan::math::validate_non_negative_index("f_class",
        "class_effects ? max(which_fclass) : 0", f_class_1dim__);
      current_statement__ = 614;
      stan::math::validate_non_negative_index("allbeta", "nX", nX);
      current_statement__ = 615;
      stan::math::validate_non_negative_index("mu", "totns", totns);
      current_statement__ = 616;
      d_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 616;
      d_1dim__ = (nt - 1);
      current_statement__ = 616;
      stan::math::validate_non_negative_index("d", "nt - 1", d_1dim__);
      current_statement__ = 617;
      stan::math::validate_non_negative_index("omega", "nodesplit", nodesplit);
      current_statement__ = 618;
      beta_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 618;
      beta_1dim__ = (((nX - totns) - (nt - 1)) - nodesplit);
      current_statement__ = 618;
      stan::math::validate_non_negative_index("beta",
        "nX - totns - (nt - 1) - nodesplit", beta_1dim__);
      current_statement__ = 619;
      eta_agd_contrast_ii_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 619;
      eta_agd_contrast_ii_1dim__ = (stan::math::logical_gt(nint_max, 1) ? (nint
        * ni_agd_contrast) : 0);
      current_statement__ = 619;
      stan::math::validate_non_negative_index("eta_agd_contrast_ii",
        "nint_max > 1 ? nint * ni_agd_contrast : 0",
        eta_agd_contrast_ii_1dim__);
      current_statement__ = 620;
      stan::math::validate_non_negative_index("eta_agd_contrast_bar",
        "ni_agd_contrast", ni_agd_contrast);
      current_statement__ = 621;
      stan::math::validate_non_negative_index("fitted_ipd", "ni_ipd", ni_ipd);
      current_statement__ = 622;
      stan::math::validate_non_negative_index("fitted_ipd", "ncat", ncat);
      current_statement__ = 623;
      stan::math::validate_non_negative_index("fitted_agd_arm", "ni_agd_arm",
        ni_agd_arm);
      current_statement__ = 624;
      stan::math::validate_non_negative_index("fitted_agd_arm", "ncat", ncat);
      current_statement__ = 625;
      theta_bar_cum_agd_arm_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 625;
      theta_bar_cum_agd_arm_1dim__ = (ni_agd_arm * n_int_thin);
      current_statement__ = 625;
      stan::math::validate_non_negative_index("theta_bar_cum_agd_arm",
        "ni_agd_arm * n_int_thin", theta_bar_cum_agd_arm_1dim__);
      current_statement__ = 626;
      stan::math::validate_non_negative_index("theta_bar_cum_agd_arm",
        "ncat", ncat);
      current_statement__ = 627;
      log_lik_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 627;
      log_lik_1dim__ = ((ni_ipd + ni_agd_arm) + ns_agd_contrast);
      current_statement__ = 627;
      stan::math::validate_non_negative_index("log_lik",
        "ni_ipd + ni_agd_arm + ns_agd_contrast", log_lik_1dim__);
      current_statement__ = 628;
      resdev_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 628;
      resdev_1dim__ = ((ni_ipd + ni_agd_arm) + ns_agd_contrast);
      current_statement__ = 628;
      stan::math::validate_non_negative_index("resdev",
        "ni_ipd + ni_agd_arm + ns_agd_contrast", resdev_1dim__);
      current_statement__ = 629;
      stan::math::validate_non_negative_index("fitted_agd_contrast",
        "ni_agd_contrast", ni_agd_contrast);
      current_statement__ = 630;
      theta_bar_cum_agd_contrast_1dim__ = std::numeric_limits<int>::min();
      current_statement__ = 630;
      theta_bar_cum_agd_contrast_1dim__ = (ni_agd_contrast * n_int_thin);
      current_statement__ = 630;
      stan::math::validate_non_negative_index("theta_bar_cum_agd_contrast",
        "ni_agd_contrast * n_int_thin", theta_bar_cum_agd_contrast_1dim__);
      current_statement__ = 631;
      stan::math::validate_non_negative_index("delta", "n_delta", n_delta);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    num_params_r__ = nX + n_delta + tau_1dim__ + class_mean_1dim__ +
      class_sd_1dim__ + z_class_1dim__ + f_cc_1dim__;
  }
  inline std::string model_name() const final {
    return "model_ordered_multinomial";
  }
  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_ordered_multinomial_namespace::log_prob";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<local_scalar_t__,-1,1> beta_tilde =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nX, DUMMY_VAR__);
      current_statement__ = 1;
      beta_tilde = in__.template read<
                     Eigen::Matrix<local_scalar_t__,-1,1>>(nX);
      Eigen::Matrix<local_scalar_t__,-1,1> u_delta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_delta, DUMMY_VAR__);
      current_statement__ = 2;
      u_delta = in__.template read<
                  Eigen::Matrix<local_scalar_t__,-1,1>>(n_delta);
      Eigen::Matrix<local_scalar_t__,-1,1> tau =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(tau_1dim__,
          DUMMY_VAR__);
      current_statement__ = 3;
      tau = in__.template read_constrain_lb<
              Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0, lp__,
              tau_1dim__);
      Eigen::Matrix<local_scalar_t__,-1,1> class_mean =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(class_mean_1dim__,
          DUMMY_VAR__);
      current_statement__ = 4;
      class_mean = in__.template read<
                     Eigen::Matrix<local_scalar_t__,-1,1>>(class_mean_1dim__);
      Eigen::Matrix<local_scalar_t__,-1,1> class_sd =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(class_sd_1dim__,
          DUMMY_VAR__);
      current_statement__ = 5;
      class_sd = in__.template read_constrain_lb<
                   Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0, lp__,
                   class_sd_1dim__);
      Eigen::Matrix<local_scalar_t__,-1,1> z_class =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(z_class_1dim__,
          DUMMY_VAR__);
      current_statement__ = 6;
      z_class = in__.template read<
                  Eigen::Matrix<local_scalar_t__,-1,1>>(z_class_1dim__);
      Eigen::Matrix<local_scalar_t__,-1,1> f_cc =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(f_cc_1dim__,
          DUMMY_VAR__);
      current_statement__ = 7;
      f_cc = in__.template read_constrain_positive_ordered<
               Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
               f_cc_1dim__);
      Eigen::Matrix<local_scalar_t__,-1,1> cc =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(cc_1dim__,
          DUMMY_VAR__);
      std::vector<Eigen::Matrix<local_scalar_t__,-1,1>> theta_ipd =
        std::vector<Eigen::Matrix<local_scalar_t__,-1,1>>(ni_ipd,
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant(ncat, DUMMY_VAR__));
      Eigen::Matrix<local_scalar_t__,-1,-1> theta_agd_arm_ii =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(theta_agd_arm_ii_1dim__,
          theta_agd_arm_ii_2dim__, DUMMY_VAR__);
      std::vector<Eigen::Matrix<local_scalar_t__,-1,1>> q_agd_arm_bar =
        std::vector<Eigen::Matrix<local_scalar_t__,-1,1>>(ni_agd_arm,
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant(ncat, DUMMY_VAR__));
      std::vector<Eigen::Matrix<local_scalar_t__,-1,1>> theta_agd_arm_bar =
        std::vector<Eigen::Matrix<local_scalar_t__,-1,1>>(ni_agd_arm,
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant(ncat, DUMMY_VAR__));
      Eigen::Matrix<local_scalar_t__,-1,1> eta_ipd =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(ni_ipd, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> f_delta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_delta, DUMMY_VAR__);
      current_statement__ = 14;
      stan::model::assign(f_delta,
        (RE ? stan::math::eval(
                (RE_sparse ? stan::math::eval(
                               stan::math::multiply(
                                 stan::model::rvalue(tau, "tau",
                                   stan::model::index_uni(1)),
                                 stan::math::csr_matrix_times_vector(n_delta,
                                   n_delta, RE_L_w, RE_L_v, RE_L_u, u_delta))) : 
                stan::math::eval(
                  stan::math::multiply(
                    stan::math::multiply(
                      stan::model::rvalue(tau, "tau",
                        stan::model::index_uni(1)), RE_L), u_delta)))) : 
        stan::math::eval(u_delta)), "assigning variable f_delta");
      Eigen::Matrix<local_scalar_t__,-1,1> f_class =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(f_class_1dim__,
          DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> allbeta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nX, DUMMY_VAR__);
      current_statement__ = 16;
      stan::model::assign(allbeta,
        (QR ? stan::math::eval(stan::math::multiply(R_inv, beta_tilde)) : 
        stan::math::eval(beta_tilde)), "assigning variable allbeta");
      Eigen::Matrix<local_scalar_t__,-1,1> mu =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(totns, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> d =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(d_1dim__, DUMMY_VAR__);
      current_statement__ = 18;
      stan::model::assign(d,
        stan::model::rvalue(allbeta, "allbeta",
          stan::model::index_min_max((totns + 1), ((totns + nt) - 1))),
        "assigning variable d");
      Eigen::Matrix<local_scalar_t__,-1,1> omega =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nodesplit,
          DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> beta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(beta_1dim__,
          DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> eta_agd_contrast_ii =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(eta_agd_contrast_ii_1dim__,
          DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> eta_agd_contrast_bar =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(ni_agd_contrast,
          DUMMY_VAR__);
      current_statement__ = 33;
      if (totns) {
        current_statement__ = 31;
        stan::model::assign(mu,
          stan::model::rvalue(allbeta, "allbeta",
            stan::model::index_min_max(1, totns)), "assigning variable mu");
      }
      current_statement__ = 36;
      if ((((nX - totns) - (nt - 1)) - nodesplit)) {
        current_statement__ = 34;
        stan::model::assign(beta,
          stan::model::rvalue(allbeta, "allbeta",
            stan::model::index_min(((totns + nt) + nodesplit))),
          "assigning variable beta");
      }
      current_statement__ = 39;
      if (nodesplit) {
        current_statement__ = 37;
        stan::model::assign(omega,
          stan::model::rvalue(allbeta, "allbeta",
            stan::model::index_uni((totns + nt))),
          "assigning variable omega", stan::model::index_uni(1));
      }
      current_statement__ = 43;
      if (class_effects) {
        current_statement__ = 40;
        stan::model::assign(f_class,
          stan::math::add(
            stan::math::subtract(
              stan::model::rvalue(class_mean, "class_mean",
                stan::model::index_multi(
                  stan::model::rvalue(which_CE, "which_CE",
                    stan::model::index_multi(which_class_trt)))),
              stan::model::rvalue(d, "d",
                stan::model::index_multi(which_class_trt))),
            stan::math::elt_multiply(
              stan::model::rvalue(class_sd, "class_sd",
                stan::model::index_multi(
                  stan::model::rvalue(which_CE_sd, "which_CE_sd",
                    stan::model::index_multi(which_class_trt)))), z_class)),
          "assigning variable f_class");
        current_statement__ = 41;
        stan::model::assign(d,
          stan::math::add(
            stan::model::rvalue(class_mean, "class_mean",
              stan::model::index_multi(
                stan::model::rvalue(which_CE, "which_CE",
                  stan::model::index_multi(which_class_trt)))),
            stan::math::elt_multiply(
              stan::model::rvalue(class_sd, "class_sd",
                stan::model::index_multi(
                  stan::model::rvalue(which_CE_sd, "which_CE_sd",
                    stan::model::index_multi(which_class_trt)))), z_class)),
          "assigning variable d", stan::model::index_multi(which_class_trt));
      }
      current_statement__ = 67;
      if (ni_ipd) {
        current_statement__ = 55;
        if (RE) {
          current_statement__ = 46;
          stan::math::validate_non_negative_index("eta_ipd_noRE", "ni_ipd",
            ni_ipd);
          Eigen::Matrix<local_scalar_t__,-1,1> eta_ipd_noRE =
            Eigen::Matrix<local_scalar_t__,-1,1>::Constant(ni_ipd,
              DUMMY_VAR__);
          current_statement__ = 47;
          stan::model::assign(eta_ipd_noRE,
            (has_offset ? stan::math::eval(
                            stan::math::add(
                              stan::math::multiply(X_ipd, beta_tilde),
                              offset_ipd)) : stan::math::eval(
                                               stan::math::multiply(X_ipd,
                                                 beta_tilde))),
            "assigning variable eta_ipd_noRE");
          current_statement__ = 52;
          for (int i = 1; i <= ni_ipd; ++i) {
            current_statement__ = 50;
            if (stan::model::rvalue(which_RE, "which_RE",
                  stan::model::index_uni(
                    stan::model::rvalue(ipd_arm, "ipd_arm",
                      stan::model::index_uni(i))))) {
              current_statement__ = 49;
              stan::model::assign(eta_ipd,
                (stan::model::rvalue(eta_ipd_noRE, "eta_ipd_noRE",
                   stan::model::index_uni(i)) +
                stan::model::rvalue(f_delta, "f_delta",
                  stan::model::index_uni(
                    stan::model::rvalue(which_RE, "which_RE",
                      stan::model::index_uni(
                        stan::model::rvalue(ipd_arm, "ipd_arm",
                          stan::model::index_uni(i))))))),
                "assigning variable eta_ipd", stan::model::index_uni(i));
            } else {
              current_statement__ = 48;
              stan::model::assign(eta_ipd,
                stan::model::rvalue(eta_ipd_noRE, "eta_ipd_noRE",
                  stan::model::index_uni(i)), "assigning variable eta_ipd",
                stan::model::index_uni(i));
            }
          }
        } else {
          current_statement__ = 44;
          stan::model::assign(eta_ipd,
            (has_offset ? stan::math::eval(
                            stan::math::add(
                              stan::math::multiply(X_ipd, beta_tilde),
                              offset_ipd)) : stan::math::eval(
                                               stan::math::multiply(X_ipd,
                                                 beta_tilde))),
            "assigning variable eta_ipd");
        }
        current_statement__ = 58;
        if (stan::math::logical_gt(brmr_n_col, 0)) {
          current_statement__ = 56;
          stan::model::assign(eta_ipd,
            stan::math::add(stan::model::deep_copy(eta_ipd),
              stan::math::elt_multiply(
                stan::math::subtract(
                  stan::math::subtract(
                    stan::math::multiply(
                      stan::model::rvalue(X_ipd, "X_ipd",
                        stan::model::index_omni(),
                        stan::model::index_min_max(1, totns)), mu), xbar_mu),
                  1),
                stan::math::multiply(
                  stan::model::rvalue(X_ipd, "X_ipd",
                    stan::model::index_omni(),
                    stan::model::index_multi(brmr_col)),
                  stan::model::rvalue(beta_tilde, "beta_tilde",
                    stan::model::index_multi(brmr_col))))),
            "assigning variable eta_ipd");
        }
        current_statement__ = 65;
        if (class_effects) {
          current_statement__ = 63;
          for (int i = 1; i <= ni_ipd; ++i) {
            current_statement__ = 61;
            if ((stan::math::primitive_value(
                   stan::math::logical_gt(
                     stan::model::rvalue(ipd_trt, "ipd_trt",
                       stan::model::index_uni(
                         stan::model::rvalue(ipd_arm, "ipd_arm",
                           stan::model::index_uni(i)))), 1))
                &&
                stan::math::primitive_value(
                  stan::model::rvalue(which_CE, "which_CE",
                    stan::model::index_uni(
                      (stan::model::rvalue(ipd_trt, "ipd_trt",
                         stan::model::index_uni(
                           stan::model::rvalue(ipd_arm, "ipd_arm",
                             stan::model::index_uni(i)))) - 1)))))) {
              current_statement__ = 59;
              stan::model::assign(eta_ipd,
                (stan::model::rvalue(eta_ipd, "eta_ipd",
                   stan::model::index_uni(i)) +
                stan::model::rvalue(f_class, "f_class",
                  stan::model::index_uni(
                    stan::model::rvalue(which_fclass, "which_fclass",
                      stan::model::index_uni(
                        (stan::model::rvalue(ipd_trt, "ipd_trt",
                           stan::model::index_uni(
                             stan::model::rvalue(ipd_arm, "ipd_arm",
                               stan::model::index_uni(i)))) - 1)))))),
                "assigning variable eta_ipd", stan::model::index_uni(i));
            }
          }
        }
      }
      current_statement__ = 122;
      if (ni_agd_contrast) {
        current_statement__ = 120;
        if (stan::math::logical_gt(nint_max, 1)) {
          current_statement__ = 90;
          stan::math::validate_non_negative_index("eta_agd_contrast_noRE",
            "nint_max * ni_agd_contrast", (nint_max * ni_agd_contrast));
          Eigen::Matrix<local_scalar_t__,-1,1> eta_agd_contrast_noRE =
            Eigen::Matrix<local_scalar_t__,-1,1>::Constant((nint_max *
              ni_agd_contrast), DUMMY_VAR__);
          current_statement__ = 91;
          stan::model::assign(eta_agd_contrast_noRE,
            (has_offset ? stan::math::eval(
                            stan::math::add(
                              stan::math::multiply(X_agd_contrast, beta_tilde),
                              offset_agd_contrast)) : stan::math::eval(
                                                        stan::math::multiply(
                                                          X_agd_contrast,
                                                          beta_tilde))),
            "assigning variable eta_agd_contrast_noRE");
          current_statement__ = 101;
          if (class_effects) {
            current_statement__ = 99;
            for (int i = 1; i <= ni_agd_arm; ++i) {
              current_statement__ = 94;
              if ((stan::math::primitive_value(
                     stan::math::logical_gt(
                       stan::model::rvalue(agd_contrast_trt,
                         "agd_contrast_trt", stan::model::index_uni(i)), 1))
                  &&
                  stan::math::primitive_value(
                    stan::model::rvalue(which_CE, "which_CE",
                      stan::model::index_uni(
                        (stan::model::rvalue(agd_contrast_trt,
                           "agd_contrast_trt", stan::model::index_uni(i)) -
                        1)))))) {
                current_statement__ = 92;
                stan::model::assign(eta_agd_contrast_noRE,
                  stan::math::add(
                    stan::model::deep_copy(
                      stan::model::rvalue(eta_agd_contrast_noRE,
                        "eta_agd_contrast_noRE",
                        stan::model::index_min_max((1 + ((i - 1) *
                          nint_max)), (((i - 1) * nint_max) + nint)))),
                    stan::model::rvalue(f_class, "f_class",
                      stan::model::index_uni(
                        stan::model::rvalue(which_fclass, "which_fclass",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_contrast_trt,
                               "agd_contrast_trt", stan::model::index_uni(i))
                            - 1)))))),
                  "assigning variable eta_agd_contrast_noRE",
                  stan::model::index_min_max((1 + ((i - 1) * nint_max)), (((i
                    - 1) * nint_max) + nint)));
              }
              current_statement__ = 97;
              if ((stan::math::primitive_value(
                     stan::math::logical_gt(
                       stan::model::rvalue(agd_contrast_trt_b,
                         "agd_contrast_trt_b", stan::model::index_uni(i)), 1))
                  &&
                  stan::math::primitive_value(
                    stan::model::rvalue(which_CE, "which_CE",
                      stan::model::index_uni(
                        (stan::model::rvalue(agd_contrast_trt_b,
                           "agd_contrast_trt_b", stan::model::index_uni(i)) -
                        1)))))) {
                current_statement__ = 95;
                stan::model::assign(eta_agd_contrast_noRE,
                  stan::math::subtract(
                    stan::model::deep_copy(
                      stan::model::rvalue(eta_agd_contrast_noRE,
                        "eta_agd_contrast_noRE",
                        stan::model::index_min_max((1 + ((i - 1) *
                          nint_max)), (((i - 1) * nint_max) + nint)))),
                    stan::model::rvalue(f_class, "f_class",
                      stan::model::index_uni(
                        stan::model::rvalue(which_fclass, "which_fclass",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_contrast_trt_b,
                               "agd_contrast_trt_b",
                               stan::model::index_uni(i)) - 1)))))),
                  "assigning variable eta_agd_contrast_noRE",
                  stan::model::index_min_max((1 + ((i - 1) * nint_max)), (((i
                    - 1) * nint_max) + nint)));
              }
            }
          }
          current_statement__ = 118;
          if (RE) {
            current_statement__ = 116;
            for (int i = 1; i <= ni_agd_contrast; ++i) {
              current_statement__ = 113;
              if (stan::model::rvalue(which_RE, "which_RE",
                    stan::model::index_uni(((narm_ipd + narm_agd_arm) + i)))) {
                current_statement__ = 112;
                stan::model::assign(eta_agd_contrast_ii,
                  stan::math::add(
                    stan::model::rvalue(eta_agd_contrast_noRE,
                      "eta_agd_contrast_noRE",
                      stan::model::index_min_max((1 + ((i - 1) * nint_max)),
                        (((i - 1) * nint_max) + nint))),
                    stan::model::rvalue(f_delta, "f_delta",
                      stan::model::index_uni(
                        stan::model::rvalue(which_RE, "which_RE",
                          stan::model::index_uni(((narm_ipd + narm_agd_arm) +
                            i)))))),
                  "assigning variable eta_agd_contrast_ii",
                  stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                    nint)));
              } else {
                current_statement__ = 111;
                stan::model::assign(eta_agd_contrast_ii,
                  stan::model::rvalue(eta_agd_contrast_noRE,
                    "eta_agd_contrast_noRE",
                    stan::model::index_min_max((1 + ((i - 1) * nint_max)),
                      (((i - 1) * nint_max) + nint))),
                  "assigning variable eta_agd_contrast_ii",
                  stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                    nint)));
              }
              current_statement__ = 114;
              stan::model::assign(eta_agd_contrast_bar,
                stan::math::mean(
                  stan::model::rvalue(eta_agd_contrast_ii,
                    "eta_agd_contrast_ii",
                    stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                      nint)))), "assigning variable eta_agd_contrast_bar",
                stan::model::index_uni(i));
            }
          } else {
            current_statement__ = 106;
            if (stan::math::logical_eq(nint, nint_max)) {
              current_statement__ = 105;
              stan::model::assign(eta_agd_contrast_ii, eta_agd_contrast_noRE,
                "assigning variable eta_agd_contrast_ii");
            } else {
              current_statement__ = 104;
              for (int i = 1; i <= ni_agd_contrast; ++i) {
                current_statement__ = 102;
                stan::model::assign(eta_agd_contrast_ii,
                  stan::model::rvalue(eta_agd_contrast_noRE,
                    "eta_agd_contrast_noRE",
                    stan::model::index_min_max((1 + ((i - 1) * nint_max)),
                      (((i - 1) * nint_max) + nint))),
                  "assigning variable eta_agd_contrast_ii",
                  stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                    nint)));
              }
            }
            current_statement__ = 109;
            for (int i = 1; i <= ni_agd_contrast; ++i) {
              current_statement__ = 107;
              stan::model::assign(eta_agd_contrast_bar,
                stan::math::mean(
                  stan::model::rvalue(eta_agd_contrast_ii,
                    "eta_agd_contrast_ii",
                    stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                      nint)))), "assigning variable eta_agd_contrast_bar",
                stan::model::index_uni(i));
            }
          }
        } else {
          current_statement__ = 78;
          if (RE) {
            current_statement__ = 70;
            stan::math::validate_non_negative_index("eta_agd_contrast_noRE",
              "nint * ni_agd_contrast", (nint * ni_agd_contrast));
            Eigen::Matrix<local_scalar_t__,-1,1> eta_agd_contrast_noRE =
              Eigen::Matrix<local_scalar_t__,-1,1>::Constant((nint *
                ni_agd_contrast), DUMMY_VAR__);
            current_statement__ = 71;
            stan::model::assign(eta_agd_contrast_noRE,
              (has_offset ? stan::math::eval(
                              stan::math::add(
                                stan::math::multiply(X_agd_contrast,
                                  beta_tilde), offset_agd_contrast)) : 
              stan::math::eval(
                stan::math::multiply(X_agd_contrast, beta_tilde))),
              "assigning variable eta_agd_contrast_noRE");
            current_statement__ = 76;
            for (int i = 1; i <= ni_agd_contrast; ++i) {
              current_statement__ = 74;
              if (stan::model::rvalue(which_RE, "which_RE",
                    stan::model::index_uni(((narm_ipd + narm_agd_arm) + i)))) {
                current_statement__ = 73;
                stan::model::assign(eta_agd_contrast_bar,
                  (stan::model::rvalue(eta_agd_contrast_noRE,
                     "eta_agd_contrast_noRE", stan::model::index_uni(i)) +
                  stan::model::rvalue(f_delta, "f_delta",
                    stan::model::index_uni(
                      stan::model::rvalue(which_RE, "which_RE",
                        stan::model::index_uni(((narm_ipd + narm_agd_arm) +
                          i)))))), "assigning variable eta_agd_contrast_bar",
                  stan::model::index_uni(i));
              } else {
                current_statement__ = 72;
                stan::model::assign(eta_agd_contrast_bar,
                  stan::model::rvalue(eta_agd_contrast_noRE,
                    "eta_agd_contrast_noRE", stan::model::index_uni(i)),
                  "assigning variable eta_agd_contrast_bar",
                  stan::model::index_uni(i));
              }
            }
          } else {
            current_statement__ = 68;
            stan::model::assign(eta_agd_contrast_bar,
              (has_offset ? stan::math::eval(
                              stan::math::add(
                                stan::math::multiply(X_agd_contrast,
                                  beta_tilde), offset_agd_contrast)) : 
              stan::math::eval(
                stan::math::multiply(X_agd_contrast, beta_tilde))),
              "assigning variable eta_agd_contrast_bar");
          }
          current_statement__ = 88;
          if (class_effects) {
            current_statement__ = 86;
            for (int i = 1; i <= ni_agd_contrast; ++i) {
              current_statement__ = 81;
              if ((stan::math::primitive_value(
                     stan::math::logical_gt(
                       stan::model::rvalue(agd_contrast_trt,
                         "agd_contrast_trt", stan::model::index_uni(i)), 1))
                  &&
                  stan::math::primitive_value(
                    stan::model::rvalue(which_CE, "which_CE",
                      stan::model::index_uni(
                        (stan::model::rvalue(agd_contrast_trt,
                           "agd_contrast_trt", stan::model::index_uni(i)) -
                        1)))))) {
                current_statement__ = 79;
                stan::model::assign(eta_agd_contrast_bar,
                  (stan::model::rvalue(eta_agd_contrast_bar,
                     "eta_agd_contrast_bar", stan::model::index_uni(i)) +
                  stan::model::rvalue(f_class, "f_class",
                    stan::model::index_uni(
                      stan::model::rvalue(which_fclass, "which_fclass",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_contrast_trt,
                             "agd_contrast_trt", stan::model::index_uni(i)) -
                          1)))))), "assigning variable eta_agd_contrast_bar",
                  stan::model::index_uni(i));
              }
              current_statement__ = 84;
              if ((stan::math::primitive_value(
                     stan::math::logical_gt(
                       stan::model::rvalue(agd_contrast_trt_b,
                         "agd_contrast_trt_b", stan::model::index_uni(i)), 1))
                  &&
                  stan::math::primitive_value(
                    stan::model::rvalue(which_CE, "which_CE",
                      stan::model::index_uni(
                        (stan::model::rvalue(agd_contrast_trt_b,
                           "agd_contrast_trt_b", stan::model::index_uni(i)) -
                        1)))))) {
                current_statement__ = 82;
                stan::model::assign(eta_agd_contrast_bar,
                  (stan::model::rvalue(eta_agd_contrast_bar,
                     "eta_agd_contrast_bar", stan::model::index_uni(i)) -
                  stan::model::rvalue(f_class, "f_class",
                    stan::model::index_uni(
                      stan::model::rvalue(which_fclass, "which_fclass",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_contrast_trt_b,
                             "agd_contrast_trt_b", stan::model::index_uni(i))
                          - 1)))))),
                  "assigning variable eta_agd_contrast_bar",
                  stan::model::index_uni(i));
              }
            }
          }
        }
      }
      current_statement__ = 123;
      stan::model::assign(cc, 0, "assigning variable cc",
        stan::model::index_uni(1));
      current_statement__ = 125;
      if (stan::math::logical_gt(ncat, 2)) {
        current_statement__ = 124;
        stan::model::assign(cc, f_cc, "assigning variable cc",
          stan::model::index_min(2));
      }
      current_statement__ = 126;
      stan::model::assign(theta_ipd, theta_ipd0,
        "assigning variable theta_ipd");
      current_statement__ = 127;
      stan::model::assign(theta_agd_arm_bar, theta_agd_arm_bar0,
        "assigning variable theta_agd_arm_bar");
      current_statement__ = 144;
      for (int i = 1; i <= ni_ipd; ++i) {
        current_statement__ = 128;
        stan::math::validate_non_negative_index("q_temp", "ipd_ncat[i] - 1",
          (stan::model::rvalue(ipd_ncat, "ipd_ncat",
             stan::model::index_uni(i)) - 1));
        Eigen::Matrix<local_scalar_t__,-1,1> q_temp =
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant((stan::model::rvalue(
                                                            ipd_ncat,
                                                            "ipd_ncat",
                                                            stan::model::index_uni(
                                                              i)) - 1),
            DUMMY_VAR__);
        current_statement__ = 137;
        for (int k = 1; k <=
             (stan::model::rvalue(ipd_ncat, "ipd_ncat",
                stan::model::index_uni(i)) - 1); ++k) {
          current_statement__ = 135;
          if (stan::math::logical_eq(link, 1)) {
            current_statement__ = 134;
            stan::model::assign(q_temp,
              stan::math::inv_logit(
                (stan::model::rvalue(eta_ipd, "eta_ipd",
                   stan::model::index_uni(i)) -
                stan::model::rvalue(cc, "cc",
                  stan::model::index_uni(
                    (stan::model::rvalue(ipd_cat, "ipd_cat",
                       stan::model::index_uni(i),
                       stan::model::index_uni((k + 1))) - 1))))),
              "assigning variable q_temp", stan::model::index_uni(k));
          } else {
            current_statement__ = 133;
            if (stan::math::logical_eq(link, 2)) {
              current_statement__ = 132;
              stan::model::assign(q_temp,
                stan::math::Phi(
                  (stan::model::rvalue(eta_ipd, "eta_ipd",
                     stan::model::index_uni(i)) -
                  stan::model::rvalue(cc, "cc",
                    stan::model::index_uni(
                      (stan::model::rvalue(ipd_cat, "ipd_cat",
                         stan::model::index_uni(i),
                         stan::model::index_uni((k + 1))) - 1))))),
                "assigning variable q_temp", stan::model::index_uni(k));
            } else {
              current_statement__ = 131;
              if (stan::math::logical_eq(link, 3)) {
                current_statement__ = 130;
                stan::model::assign(q_temp,
                  stan::math::inv_cloglog(
                    (stan::model::rvalue(eta_ipd, "eta_ipd",
                       stan::model::index_uni(i)) -
                    stan::model::rvalue(cc, "cc",
                      stan::model::index_uni(
                        (stan::model::rvalue(ipd_cat, "ipd_cat",
                           stan::model::index_uni(i),
                           stan::model::index_uni((k + 1))) - 1))))),
                  "assigning variable q_temp", stan::model::index_uni(k));
              }
            }
          }
        }
        current_statement__ = 138;
        stan::model::assign(theta_ipd, (1 -
          stan::model::rvalue(q_temp, "q_temp", stan::model::index_uni(1))),
          "assigning variable theta_ipd", stan::model::index_uni(i),
          stan::model::index_uni(1));
        current_statement__ = 141;
        for (int k = 2; k <=
             (stan::model::rvalue(ipd_ncat, "ipd_ncat",
                stan::model::index_uni(i)) - 1); ++k) {
          current_statement__ = 139;
          stan::model::assign(theta_ipd,
            (stan::model::rvalue(q_temp, "q_temp",
               stan::model::index_uni((k - 1))) -
            stan::model::rvalue(q_temp, "q_temp", stan::model::index_uni(k))),
            "assigning variable theta_ipd", stan::model::index_uni(i),
            stan::model::index_uni(
              stan::model::rvalue(ipd_cat, "ipd_cat",
                stan::model::index_uni(i), stan::model::index_uni(k))));
        }
        current_statement__ = 142;
        stan::model::assign(theta_ipd,
          stan::model::rvalue(q_temp, "q_temp",
            stan::model::index_uni(
              (stan::model::rvalue(ipd_ncat, "ipd_ncat",
                 stan::model::index_uni(i)) - 1))),
          "assigning variable theta_ipd", stan::model::index_uni(i),
          stan::model::index_uni(
            stan::model::rvalue(ipd_cat, "ipd_cat",
              stan::model::index_uni(i),
              stan::model::index_uni(
                stan::model::rvalue(ipd_ncat, "ipd_ncat",
                  stan::model::index_uni(i))))));
      }
      current_statement__ = 297;
      if (ni_agd_arm) {
        current_statement__ = 145;
        stan::math::validate_non_negative_index("eta_agd_arm_noRE",
          "nint_max * ni_agd_arm", (nint_max * ni_agd_arm));
        Eigen::Matrix<local_scalar_t__,-1,1> eta_agd_arm_noRE =
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant((nint_max *
            ni_agd_arm), DUMMY_VAR__);
        current_statement__ = 146;
        stan::model::assign(eta_agd_arm_noRE,
          (has_offset ? stan::math::eval(
                          stan::math::add(
                            stan::math::multiply(X_agd_arm, beta_tilde),
                            offset_agd_arm)) : stan::math::eval(
                                                 stan::math::multiply(
                                                   X_agd_arm, beta_tilde))),
          "assigning variable eta_agd_arm_noRE");
        current_statement__ = 149;
        if (stan::math::logical_gt(brmr_n_col, 0)) {
          current_statement__ = 147;
          stan::model::assign(eta_agd_arm_noRE,
            stan::math::add(stan::model::deep_copy(eta_agd_arm_noRE),
              stan::math::elt_multiply(
                stan::math::subtract(
                  stan::math::subtract(
                    stan::math::multiply(
                      stan::model::rvalue(X_agd_arm, "X_agd_arm",
                        stan::model::index_omni(),
                        stan::model::index_min_max(1, totns)), mu), xbar_mu),
                  1),
                stan::math::multiply(
                  stan::model::rvalue(X_agd_arm, "X_agd_arm",
                    stan::model::index_omni(),
                    stan::model::index_multi(brmr_col)),
                  stan::model::rvalue(beta_tilde, "beta_tilde",
                    stan::model::index_multi(brmr_col))))),
            "assigning variable eta_agd_arm_noRE");
        }
        current_statement__ = 156;
        if (class_effects) {
          current_statement__ = 154;
          for (int i = 1; i <= ni_agd_arm; ++i) {
            current_statement__ = 152;
            if ((stan::math::primitive_value(
                   stan::math::logical_gt(
                     stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                       stan::model::index_uni(i)), 1))
                &&
                stan::math::primitive_value(
                  stan::model::rvalue(which_CE, "which_CE",
                    stan::model::index_uni(
                      (stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                         stan::model::index_uni(i)) - 1)))))) {
              current_statement__ = 150;
              stan::model::assign(eta_agd_arm_noRE,
                stan::math::add(
                  stan::model::deep_copy(
                    stan::model::rvalue(eta_agd_arm_noRE, "eta_agd_arm_noRE",
                      stan::model::index_min_max((1 + ((i - 1) * nint_max)),
                        (((i - 1) * nint_max) + nint)))),
                  stan::model::rvalue(f_class, "f_class",
                    stan::model::index_uni(
                      stan::model::rvalue(which_fclass, "which_fclass",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                             stan::model::index_uni(i)) - 1)))))),
                "assigning variable eta_agd_arm_noRE",
                stan::model::index_min_max((1 + ((i - 1) * nint_max)), (((i -
                  1) * nint_max) + nint)));
            }
          }
        }
        current_statement__ = 289;
        if (stan::math::logical_gt(nint_max, 1)) {
          current_statement__ = 282;
          if (RE) {
            current_statement__ = 249;
            stan::math::validate_non_negative_index("eta_agd_arm_RE", "nint",
              nint);
            Eigen::Matrix<local_scalar_t__,-1,1> eta_agd_arm_RE =
              Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nint,
                DUMMY_VAR__);
            current_statement__ = 280;
            if (stan::math::logical_eq(link, 1)) {
              current_statement__ = 278;
              for (int i = 1; i <= ni_agd_arm; ++i) {
                current_statement__ = 273;
                if (stan::model::rvalue(which_RE, "which_RE",
                      stan::model::index_uni((narm_ipd + i)))) {
                  current_statement__ = 272;
                  stan::model::assign(eta_agd_arm_RE,
                    stan::math::add(
                      stan::model::rvalue(eta_agd_arm_noRE,
                        "eta_agd_arm_noRE",
                        stan::model::index_min_max((1 + ((i - 1) *
                          nint_max)), (((i - 1) * nint_max) + nint))),
                      stan::model::rvalue(f_delta, "f_delta",
                        stan::model::index_uni(
                          stan::model::rvalue(which_RE, "which_RE",
                            stan::model::index_uni((narm_ipd + i)))))),
                    "assigning variable eta_agd_arm_RE");
                } else {
                  current_statement__ = 271;
                  stan::model::assign(eta_agd_arm_RE,
                    stan::model::rvalue(eta_agd_arm_noRE, "eta_agd_arm_noRE",
                      stan::model::index_min_max((1 + ((i - 1) * nint_max)),
                        (((i - 1) * nint_max) + nint))),
                    "assigning variable eta_agd_arm_RE");
                }
                current_statement__ = 276;
                for (int k = 1; k <=
                     (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                        stan::model::index_uni(i)) - 1); ++k) {
                  current_statement__ = 274;
                  stan::model::assign(theta_agd_arm_ii,
                    stan::math::inv_logit(
                      stan::math::subtract(eta_agd_arm_RE,
                        stan::model::rvalue(cc, "cc",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                               stan::model::index_uni(i),
                               stan::model::index_uni((k + 1))) - 1))))),
                    "assigning variable theta_agd_arm_ii",
                    stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                      nint)), stan::model::index_uni(k));
                }
              }
            } else {
              current_statement__ = 270;
              if (stan::math::logical_eq(link, 2)) {
                current_statement__ = 268;
                for (int i = 1; i <= ni_agd_arm; ++i) {
                  current_statement__ = 263;
                  if (stan::model::rvalue(which_RE, "which_RE",
                        stan::model::index_uni((narm_ipd + i)))) {
                    current_statement__ = 262;
                    stan::model::assign(eta_agd_arm_RE,
                      stan::math::add(
                        stan::model::rvalue(eta_agd_arm_noRE,
                          "eta_agd_arm_noRE",
                          stan::model::index_min_max((1 + ((i - 1) *
                            nint_max)), (((i - 1) * nint_max) + nint))),
                        stan::model::rvalue(f_delta, "f_delta",
                          stan::model::index_uni(
                            stan::model::rvalue(which_RE, "which_RE",
                              stan::model::index_uni((narm_ipd + i)))))),
                      "assigning variable eta_agd_arm_RE");
                  } else {
                    current_statement__ = 261;
                    stan::model::assign(eta_agd_arm_RE,
                      stan::model::rvalue(eta_agd_arm_noRE,
                        "eta_agd_arm_noRE",
                        stan::model::index_min_max((1 + ((i - 1) *
                          nint_max)), (((i - 1) * nint_max) + nint))),
                      "assigning variable eta_agd_arm_RE");
                  }
                  current_statement__ = 266;
                  for (int k = 1; k <=
                       (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                          stan::model::index_uni(i)) - 1); ++k) {
                    current_statement__ = 264;
                    stan::model::assign(theta_agd_arm_ii,
                      stan::math::Phi(
                        stan::math::subtract(eta_agd_arm_RE,
                          stan::model::rvalue(cc, "cc",
                            stan::model::index_uni(
                              (stan::model::rvalue(agd_arm_cat,
                                 "agd_arm_cat", stan::model::index_uni(i),
                                 stan::model::index_uni((k + 1))) - 1))))),
                      "assigning variable theta_agd_arm_ii",
                      stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                        nint)), stan::model::index_uni(k));
                  }
                }
              } else {
                current_statement__ = 260;
                if (stan::math::logical_eq(link, 3)) {
                  current_statement__ = 258;
                  for (int i = 1; i <= ni_agd_arm; ++i) {
                    current_statement__ = 253;
                    if (stan::model::rvalue(which_RE, "which_RE",
                          stan::model::index_uni((narm_ipd + i)))) {
                      current_statement__ = 252;
                      stan::model::assign(eta_agd_arm_RE,
                        stan::math::add(
                          stan::model::rvalue(eta_agd_arm_noRE,
                            "eta_agd_arm_noRE",
                            stan::model::index_min_max((1 + ((i - 1) *
                              nint_max)), (((i - 1) * nint_max) + nint))),
                          stan::model::rvalue(f_delta, "f_delta",
                            stan::model::index_uni(
                              stan::model::rvalue(which_RE, "which_RE",
                                stan::model::index_uni((narm_ipd + i)))))),
                        "assigning variable eta_agd_arm_RE");
                    } else {
                      current_statement__ = 251;
                      stan::model::assign(eta_agd_arm_RE,
                        stan::model::rvalue(eta_agd_arm_noRE,
                          "eta_agd_arm_noRE",
                          stan::model::index_min_max((1 + ((i - 1) *
                            nint_max)), (((i - 1) * nint_max) + nint))),
                        "assigning variable eta_agd_arm_RE");
                    }
                    current_statement__ = 256;
                    for (int k = 1; k <=
                         (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                            stan::model::index_uni(i)) - 1); ++k) {
                      current_statement__ = 254;
                      stan::model::assign(theta_agd_arm_ii,
                        stan::math::inv_cloglog(
                          stan::math::subtract(eta_agd_arm_RE,
                            stan::model::rvalue(cc, "cc",
                              stan::model::index_uni(
                                (stan::model::rvalue(agd_arm_cat,
                                   "agd_arm_cat", stan::model::index_uni(i),
                                   stan::model::index_uni((k + 1))) - 1))))),
                        "assigning variable theta_agd_arm_ii",
                        stan::model::index_min_max((1 + ((i - 1) * nint)), (i
                          * nint)), stan::model::index_uni(k));
                    }
                  }
                }
              }
            }
          } else {
            current_statement__ = 247;
            if (stan::math::logical_eq(link, 1)) {
              current_statement__ = 245;
              for (int i = 1; i <= ni_agd_arm; ++i) {
                current_statement__ = 243;
                for (int k = 1; k <=
                     (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                        stan::model::index_uni(i)) - 1); ++k) {
                  current_statement__ = 241;
                  stan::model::assign(theta_agd_arm_ii,
                    stan::math::inv_logit(
                      stan::math::subtract(
                        stan::model::rvalue(eta_agd_arm_noRE,
                          "eta_agd_arm_noRE",
                          stan::model::index_min_max((1 + ((i - 1) *
                            nint_max)), (((i - 1) * nint_max) + nint))),
                        stan::model::rvalue(cc, "cc",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                               stan::model::index_uni(i),
                               stan::model::index_uni((k + 1))) - 1))))),
                    "assigning variable theta_agd_arm_ii",
                    stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                      nint)), stan::model::index_uni(k));
                }
              }
            } else {
              current_statement__ = 240;
              if (stan::math::logical_eq(link, 2)) {
                current_statement__ = 238;
                for (int i = 1; i <= ni_agd_arm; ++i) {
                  current_statement__ = 236;
                  for (int k = 1; k <=
                       (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                          stan::model::index_uni(i)) - 1); ++k) {
                    current_statement__ = 234;
                    stan::model::assign(theta_agd_arm_ii,
                      stan::math::Phi(
                        stan::math::subtract(
                          stan::model::rvalue(eta_agd_arm_noRE,
                            "eta_agd_arm_noRE",
                            stan::model::index_min_max((1 + ((i - 1) *
                              nint_max)), (((i - 1) * nint_max) + nint))),
                          stan::model::rvalue(cc, "cc",
                            stan::model::index_uni(
                              (stan::model::rvalue(agd_arm_cat,
                                 "agd_arm_cat", stan::model::index_uni(i),
                                 stan::model::index_uni((k + 1))) - 1))))),
                      "assigning variable theta_agd_arm_ii",
                      stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                        nint)), stan::model::index_uni(k));
                  }
                }
              } else {
                current_statement__ = 233;
                if (stan::math::logical_eq(link, 3)) {
                  current_statement__ = 231;
                  for (int i = 1; i <= ni_agd_arm; ++i) {
                    current_statement__ = 229;
                    for (int k = 1; k <=
                         (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                            stan::model::index_uni(i)) - 1); ++k) {
                      current_statement__ = 227;
                      stan::model::assign(theta_agd_arm_ii,
                        stan::math::inv_cloglog(
                          stan::math::subtract(
                            stan::model::rvalue(eta_agd_arm_noRE,
                              "eta_agd_arm_noRE",
                              stan::model::index_min_max((1 + ((i - 1) *
                                nint_max)), (((i - 1) * nint_max) + nint))),
                            stan::model::rvalue(cc, "cc",
                              stan::model::index_uni(
                                (stan::model::rvalue(agd_arm_cat,
                                   "agd_arm_cat", stan::model::index_uni(i),
                                   stan::model::index_uni((k + 1))) - 1))))),
                        "assigning variable theta_agd_arm_ii",
                        stan::model::index_min_max((1 + ((i - 1) * nint)), (i
                          * nint)), stan::model::index_uni(k));
                    }
                  }
                }
              }
            }
          }
          current_statement__ = 287;
          for (int i = 1; i <= ni_agd_arm; ++i) {
            current_statement__ = 285;
            for (int k = 1; k <=
                 (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                    stan::model::index_uni(i)) - 1); ++k) {
              current_statement__ = 283;
              stan::model::assign(q_agd_arm_bar,
                stan::math::mean(
                  stan::model::rvalue(theta_agd_arm_ii, "theta_agd_arm_ii",
                    stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                      nint)), stan::model::index_uni(k))),
                "assigning variable q_agd_arm_bar",
                stan::model::index_uni(i), stan::model::index_uni(k));
            }
          }
        } else {
          current_statement__ = 225;
          if (RE) {
            local_scalar_t__ eta_agd_arm_RE = DUMMY_VAR__;
            current_statement__ = 193;
            if (class_effects) {
              current_statement__ = 191;
              for (int i = 1; i <= ni_agd_arm; ++i) {
                current_statement__ = 189;
                if ((stan::math::primitive_value(
                       stan::math::logical_gt(
                         stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                           stan::model::index_uni(i)), 1))
                    &&
                    stan::math::primitive_value(
                      stan::model::rvalue(which_CE, "which_CE",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                             stan::model::index_uni(i)) - 1)))))) {
                  current_statement__ = 187;
                  stan::model::assign(eta_agd_arm_noRE,
                    (stan::model::rvalue(eta_agd_arm_noRE,
                       "eta_agd_arm_noRE", stan::model::index_uni(i)) +
                    stan::model::rvalue(f_class, "f_class",
                      stan::model::index_uni(
                        stan::model::rvalue(which_fclass, "which_fclass",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                               stan::model::index_uni(i)) - 1)))))),
                    "assigning variable eta_agd_arm_noRE",
                    stan::model::index_uni(i));
                }
              }
            }
            current_statement__ = 223;
            if (stan::math::logical_eq(link, 1)) {
              current_statement__ = 221;
              for (int i = 1; i <= ni_agd_arm; ++i) {
                current_statement__ = 216;
                if (stan::model::rvalue(which_RE, "which_RE",
                      stan::model::index_uni((narm_ipd + i)))) {
                  current_statement__ = 215;
                  eta_agd_arm_RE = (stan::model::rvalue(eta_agd_arm_noRE,
                                      "eta_agd_arm_noRE",
                                      stan::model::index_uni(i))
                    +
                    stan::model::rvalue(f_delta, "f_delta",
                      stan::model::index_uni(
                        stan::model::rvalue(which_RE, "which_RE",
                          stan::model::index_uni((narm_ipd + i))))));
                } else {
                  current_statement__ = 214;
                  eta_agd_arm_RE = stan::model::rvalue(eta_agd_arm_noRE,
                                     "eta_agd_arm_noRE",
                                     stan::model::index_uni(i));
                }
                current_statement__ = 219;
                for (int k = 1; k <=
                     (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                        stan::model::index_uni(i)) - 1); ++k) {
                  current_statement__ = 217;
                  stan::model::assign(q_agd_arm_bar,
                    stan::math::inv_logit((eta_agd_arm_RE -
                      stan::model::rvalue(cc, "cc",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                             stan::model::index_uni(i),
                             stan::model::index_uni((k + 1))) - 1))))),
                    "assigning variable q_agd_arm_bar",
                    stan::model::index_uni(i), stan::model::index_uni(k));
                }
              }
            } else {
              current_statement__ = 213;
              if (stan::math::logical_eq(link, 2)) {
                current_statement__ = 211;
                for (int i = 1; i <= ni_agd_arm; ++i) {
                  current_statement__ = 206;
                  if (stan::model::rvalue(which_RE, "which_RE",
                        stan::model::index_uni((narm_ipd + i)))) {
                    current_statement__ = 205;
                    eta_agd_arm_RE = (stan::model::rvalue(eta_agd_arm_noRE,
                                        "eta_agd_arm_noRE",
                                        stan::model::index_uni(i))
                      +
                      stan::model::rvalue(f_delta, "f_delta",
                        stan::model::index_uni(
                          stan::model::rvalue(which_RE, "which_RE",
                            stan::model::index_uni((narm_ipd + i))))));
                  } else {
                    current_statement__ = 204;
                    eta_agd_arm_RE = stan::model::rvalue(eta_agd_arm_noRE,
                                       "eta_agd_arm_noRE",
                                       stan::model::index_uni(i));
                  }
                  current_statement__ = 209;
                  for (int k = 1; k <=
                       (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                          stan::model::index_uni(i)) - 1); ++k) {
                    current_statement__ = 207;
                    stan::model::assign(q_agd_arm_bar,
                      stan::math::Phi((eta_agd_arm_RE -
                        stan::model::rvalue(cc, "cc",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                               stan::model::index_uni(i),
                               stan::model::index_uni((k + 1))) - 1))))),
                      "assigning variable q_agd_arm_bar",
                      stan::model::index_uni(i), stan::model::index_uni(k));
                  }
                }
              } else {
                current_statement__ = 203;
                if (stan::math::logical_eq(link, 3)) {
                  current_statement__ = 201;
                  for (int i = 1; i <= ni_agd_arm; ++i) {
                    current_statement__ = 196;
                    if (stan::model::rvalue(which_RE, "which_RE",
                          stan::model::index_uni((narm_ipd + i)))) {
                      current_statement__ = 195;
                      eta_agd_arm_RE = (stan::model::rvalue(eta_agd_arm_noRE,
                                          "eta_agd_arm_noRE",
                                          stan::model::index_uni(i))
                        +
                        stan::model::rvalue(f_delta, "f_delta",
                          stan::model::index_uni(
                            stan::model::rvalue(which_RE, "which_RE",
                              stan::model::index_uni((narm_ipd + i))))));
                    } else {
                      current_statement__ = 194;
                      eta_agd_arm_RE = stan::model::rvalue(eta_agd_arm_noRE,
                                         "eta_agd_arm_noRE",
                                         stan::model::index_uni(i));
                    }
                    current_statement__ = 199;
                    for (int k = 1; k <=
                         (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                            stan::model::index_uni(i)) - 1); ++k) {
                      current_statement__ = 197;
                      stan::model::assign(q_agd_arm_bar,
                        stan::math::inv_cloglog((eta_agd_arm_RE -
                          stan::model::rvalue(cc, "cc",
                            stan::model::index_uni(
                              (stan::model::rvalue(agd_arm_cat,
                                 "agd_arm_cat", stan::model::index_uni(i),
                                 stan::model::index_uni((k + 1))) - 1))))),
                        "assigning variable q_agd_arm_bar",
                        stan::model::index_uni(i), stan::model::index_uni(k));
                    }
                  }
                }
              }
            }
          } else {
            current_statement__ = 163;
            if (class_effects) {
              current_statement__ = 161;
              for (int i = 1; i <= ni_agd_arm; ++i) {
                current_statement__ = 159;
                if ((stan::math::primitive_value(
                       stan::math::logical_gt(
                         stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                           stan::model::index_uni(i)), 1))
                    &&
                    stan::math::primitive_value(
                      stan::model::rvalue(which_CE, "which_CE",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                             stan::model::index_uni(i)) - 1)))))) {
                  current_statement__ = 157;
                  stan::model::assign(eta_agd_arm_noRE,
                    (stan::model::rvalue(eta_agd_arm_noRE,
                       "eta_agd_arm_noRE", stan::model::index_uni(i)) +
                    stan::model::rvalue(f_class, "f_class",
                      stan::model::index_uni(
                        stan::model::rvalue(which_fclass, "which_fclass",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                               stan::model::index_uni(i)) - 1)))))),
                    "assigning variable eta_agd_arm_noRE",
                    stan::model::index_uni(i));
                }
              }
            }
            current_statement__ = 184;
            if (stan::math::logical_eq(link, 1)) {
              current_statement__ = 182;
              for (int i = 1; i <= ni_agd_arm; ++i) {
                current_statement__ = 180;
                for (int k = 1; k <=
                     (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                        stan::model::index_uni(i)) - 1); ++k) {
                  current_statement__ = 178;
                  stan::model::assign(q_agd_arm_bar,
                    stan::math::inv_logit(
                      (stan::model::rvalue(eta_agd_arm_noRE,
                         "eta_agd_arm_noRE", stan::model::index_uni(i)) -
                      stan::model::rvalue(cc, "cc",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                             stan::model::index_uni(i),
                             stan::model::index_uni((k + 1))) - 1))))),
                    "assigning variable q_agd_arm_bar",
                    stan::model::index_uni(i), stan::model::index_uni(k));
                }
              }
            } else {
              current_statement__ = 177;
              if (stan::math::logical_eq(link, 2)) {
                current_statement__ = 175;
                for (int i = 1; i <= ni_agd_arm; ++i) {
                  current_statement__ = 173;
                  for (int k = 1; k <=
                       (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                          stan::model::index_uni(i)) - 1); ++k) {
                    current_statement__ = 171;
                    stan::model::assign(q_agd_arm_bar,
                      stan::math::Phi(
                        (stan::model::rvalue(eta_agd_arm_noRE,
                           "eta_agd_arm_noRE", stan::model::index_uni(i)) -
                        stan::model::rvalue(cc, "cc",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                               stan::model::index_uni(i),
                               stan::model::index_uni((k + 1))) - 1))))),
                      "assigning variable q_agd_arm_bar",
                      stan::model::index_uni(i), stan::model::index_uni(k));
                  }
                }
              } else {
                current_statement__ = 170;
                if (stan::math::logical_eq(link, 3)) {
                  current_statement__ = 168;
                  for (int i = 1; i <= ni_agd_arm; ++i) {
                    current_statement__ = 166;
                    for (int k = 1; k <=
                         (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                            stan::model::index_uni(i)) - 1); ++k) {
                      current_statement__ = 164;
                      stan::model::assign(q_agd_arm_bar,
                        stan::math::inv_cloglog(
                          (stan::model::rvalue(eta_agd_arm_noRE,
                             "eta_agd_arm_noRE", stan::model::index_uni(i)) -
                          stan::model::rvalue(cc, "cc",
                            stan::model::index_uni(
                              (stan::model::rvalue(agd_arm_cat,
                                 "agd_arm_cat", stan::model::index_uni(i),
                                 stan::model::index_uni((k + 1))) - 1))))),
                        "assigning variable q_agd_arm_bar",
                        stan::model::index_uni(i), stan::model::index_uni(k));
                    }
                  }
                }
              }
            }
          }
        }
        current_statement__ = 295;
        for (int i = 1; i <= ni_agd_arm; ++i) {
          current_statement__ = 290;
          stan::model::assign(theta_agd_arm_bar, (1 -
            stan::model::rvalue(q_agd_arm_bar, "q_agd_arm_bar",
              stan::model::index_uni(i), stan::model::index_uni(1))),
            "assigning variable theta_agd_arm_bar",
            stan::model::index_uni(i), stan::model::index_uni(1));
          current_statement__ = 292;
          for (int k = 2; k <=
               (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                  stan::model::index_uni(i)) - 1); ++k) {
            current_statement__ = 291;
            stan::model::assign(theta_agd_arm_bar,
              (stan::model::rvalue(q_agd_arm_bar, "q_agd_arm_bar",
                 stan::model::index_uni(i), stan::model::index_uni((k - 1)))
              -
              stan::model::rvalue(q_agd_arm_bar, "q_agd_arm_bar",
                stan::model::index_uni(i), stan::model::index_uni(k))),
              "assigning variable theta_agd_arm_bar",
              stan::model::index_uni(i),
              stan::model::index_uni(
                stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                  stan::model::index_uni(i), stan::model::index_uni(k))));
          }
          current_statement__ = 293;
          stan::model::assign(theta_agd_arm_bar,
            stan::model::rvalue(q_agd_arm_bar, "q_agd_arm_bar",
              stan::model::index_uni(i),
              stan::model::index_uni(
                (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                   stan::model::index_uni(i)) - 1))),
            "assigning variable theta_agd_arm_bar",
            stan::model::index_uni(i),
            stan::model::index_uni(
              stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                stan::model::index_uni(i),
                stan::model::index_uni(
                  stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                    stan::model::index_uni(i))))));
        }
      }
      {
        current_statement__ = 359;
        prior_select_lp<propto__>(mu, prior_intercept_dist,
          prior_intercept_location, prior_intercept_scale,
          prior_intercept_df, lp__, lp_accum__, pstream__);
        current_statement__ = 365;
        if (stan::math::logical_eq(class_effects, 0)) {
          current_statement__ = 363;
          prior_select_lp<propto__>(d, prior_trt_dist, prior_trt_location,
            prior_trt_scale, prior_trt_df, lp__, lp_accum__, pstream__);
        } else {
          current_statement__ = 360;
          prior_select_lp<propto__>(class_mean, prior_class_mean_dist,
            prior_class_mean_location, prior_class_mean_scale,
            prior_class_mean_df, lp__, lp_accum__, pstream__);
          current_statement__ = 361;
          prior_select_lp<propto__>(class_sd, prior_class_sd_dist,
            prior_class_sd_location, prior_class_sd_scale, prior_class_sd_df,
            lp__, lp_accum__, pstream__);
        }
        current_statement__ = 366;
        prior_select_lp<propto__>(beta, prior_reg_dist, prior_reg_location,
          prior_reg_scale, prior_reg_df, lp__, lp_accum__, pstream__);
        current_statement__ = 367;
        prior_select_lp<propto__>(omega, prior_trt_dist, prior_trt_location,
          prior_trt_scale, prior_trt_df, lp__, lp_accum__, pstream__);
        current_statement__ = 385;
        if (RE) {
          current_statement__ = 383;
          if (stan::math::logical_eq(prior_het_type, 1)) {
            current_statement__ = 381;
            prior_select_lp<propto__>(tau, prior_het_dist,
              prior_het_location, prior_het_scale, prior_het_df, lp__,
              lp_accum__, pstream__);
          } else {
            current_statement__ = 368;
            stan::math::validate_non_negative_index("tau_t", "RE ? 1 : 0",
              (RE ? 1 : 0));
            Eigen::Matrix<local_scalar_t__,-1,1> tau_t =
              Eigen::Matrix<local_scalar_t__,-1,1>::Constant((RE ? 1 : 0),
                DUMMY_VAR__);
            current_statement__ = 377;
            if (stan::math::logical_eq(prior_het_type, 2)) {
              current_statement__ = 374;
              stan::model::assign(tau_t,
                stan::math::pow(
                  stan::model::rvalue(tau, "tau", stan::model::index_uni(1)),
                  2), "assigning variable tau_t", stan::model::index_uni(1));
              current_statement__ = 375;
              lp_accum__.add(stan::math::log(tau));
            } else {
              current_statement__ = 373;
              if (stan::math::logical_eq(prior_het_type, 3)) {
                current_statement__ = 370;
                stan::model::assign(tau_t,
                  stan::math::pow(
                    stan::model::rvalue(tau, "tau", stan::model::index_uni(1)),
                    -2), "assigning variable tau_t",
                  stan::model::index_uni(1));
                current_statement__ = 371;
                lp_accum__.add(stan::math::multiply(-3, stan::math::log(tau)));
              }
            }
            current_statement__ = 378;
            prior_select_lp<propto__>(tau_t, prior_het_dist,
              prior_het_location, prior_het_scale, prior_het_df, lp__,
              lp_accum__, pstream__);
          }
        }
        current_statement__ = 386;
        lp_accum__.add(stan::math::std_normal_lpdf<propto__>(u_delta));
        current_statement__ = 389;
        if (ni_agd_contrast) {
          current_statement__ = 387;
          lp_accum__.add(stan::math::multi_normal_lpdf<propto__>(
                           agd_contrast_y, eta_agd_contrast_bar,
                           agd_contrast_Sigma));
        }
        current_statement__ = 398;
        if (class_effects) {
          current_statement__ = 396;
          for (int t = 1; t <= (nt - 1); ++t) {
            current_statement__ = 394;
            if (stan::math::logical_eq(
                  stan::model::rvalue(which_CE, "which_CE",
                    stan::model::index_uni(t)), 0)) {
              current_statement__ = 392;
              prior_select2_lp<propto__>(
                stan::model::rvalue(d, "d", stan::model::index_uni(t)),
                prior_trt_dist, prior_trt_location, prior_trt_scale,
                prior_trt_df, lp__, lp_accum__, pstream__);
            } else {
              current_statement__ = 390;
              lp_accum__.add(stan::math::std_normal_lpdf<propto__>(
                               stan::model::rvalue(allbeta, "allbeta",
                                 stan::model::index_uni((totns + t)))));
            }
          }
        }
        current_statement__ = 399;
        lp_accum__.add(stan::math::std_normal_lpdf<propto__>(z_class));
        current_statement__ = 401;
        for (int i = 1; i <= ni_ipd; ++i) {
          current_statement__ = 400;
          lp_accum__.add(stan::math::categorical_lpmf<propto__>(
                           stan::model::rvalue(ipd_r, "ipd_r",
                             stan::model::index_uni(i)),
                           stan::model::rvalue(theta_ipd, "theta_ipd",
                             stan::model::index_uni(i))));
        }
        current_statement__ = 403;
        for (int i = 1; i <= ni_agd_arm; ++i) {
          current_statement__ = 402;
          lp_accum__.add(stan::math::multinomial_lpmf<propto__>(
                           stan::model::rvalue(agd_arm_r, "agd_arm_r",
                             stan::model::index_uni(i)),
                           stan::model::rvalue(theta_agd_arm_bar,
                             "theta_agd_arm_bar", stan::model::index_uni(i))));
        }
        current_statement__ = 410;
        if (stan::math::logical_gt(prior_aux_dist, 0)) {
          current_statement__ = 404;
          stan::math::validate_non_negative_index("diff_cc", "ncat - 2",
            (ncat - 2));
          Eigen::Matrix<local_scalar_t__,-1,1> diff_cc =
            Eigen::Matrix<local_scalar_t__,-1,1>::Constant((ncat - 2),
              DUMMY_VAR__);
          current_statement__ = 407;
          for (int k = 1; k <= (ncat - 2); ++k) {
            current_statement__ = 406;
            stan::model::assign(diff_cc,
              (stan::model::rvalue(cc, "cc", stan::model::index_uni((k + 1)))
              - stan::model::rvalue(cc, "cc", stan::model::index_uni(k))),
              "assigning variable diff_cc", stan::model::index_uni(k));
          }
          current_statement__ = 408;
          prior_select_lp<propto__>(diff_cc, prior_aux_dist,
            prior_aux_location, prior_aux_scale, prior_aux_df, lp__,
            lp_accum__, pstream__);
        }
      }
    } 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_ordered_multinomial_namespace::write_array";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<double,-1,1> beta_tilde =
        Eigen::Matrix<double,-1,1>::Constant(nX,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 1;
      beta_tilde = in__.template read<
                     Eigen::Matrix<local_scalar_t__,-1,1>>(nX);
      Eigen::Matrix<double,-1,1> u_delta =
        Eigen::Matrix<double,-1,1>::Constant(n_delta,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 2;
      u_delta = in__.template read<
                  Eigen::Matrix<local_scalar_t__,-1,1>>(n_delta);
      Eigen::Matrix<double,-1,1> tau =
        Eigen::Matrix<double,-1,1>::Constant(tau_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 3;
      tau = in__.template read_constrain_lb<
              Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0, lp__,
              tau_1dim__);
      Eigen::Matrix<double,-1,1> class_mean =
        Eigen::Matrix<double,-1,1>::Constant(class_mean_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 4;
      class_mean = in__.template read<
                     Eigen::Matrix<local_scalar_t__,-1,1>>(class_mean_1dim__);
      Eigen::Matrix<double,-1,1> class_sd =
        Eigen::Matrix<double,-1,1>::Constant(class_sd_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 5;
      class_sd = in__.template read_constrain_lb<
                   Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0, lp__,
                   class_sd_1dim__);
      Eigen::Matrix<double,-1,1> z_class =
        Eigen::Matrix<double,-1,1>::Constant(z_class_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 6;
      z_class = in__.template read<
                  Eigen::Matrix<local_scalar_t__,-1,1>>(z_class_1dim__);
      Eigen::Matrix<double,-1,1> f_cc =
        Eigen::Matrix<double,-1,1>::Constant(f_cc_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 7;
      f_cc = in__.template read_constrain_positive_ordered<
               Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(lp__,
               f_cc_1dim__);
      Eigen::Matrix<double,-1,1> cc =
        Eigen::Matrix<double,-1,1>::Constant(cc_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      std::vector<Eigen::Matrix<double,-1,1>> theta_ipd =
        std::vector<Eigen::Matrix<double,-1,1>>(ni_ipd,
          Eigen::Matrix<double,-1,1>::Constant(ncat,
            std::numeric_limits<double>::quiet_NaN()));
      Eigen::Matrix<double,-1,-1> theta_agd_arm_ii =
        Eigen::Matrix<double,-1,-1>::Constant(theta_agd_arm_ii_1dim__,
          theta_agd_arm_ii_2dim__, std::numeric_limits<double>::quiet_NaN());
      std::vector<Eigen::Matrix<double,-1,1>> q_agd_arm_bar =
        std::vector<Eigen::Matrix<double,-1,1>>(ni_agd_arm,
          Eigen::Matrix<double,-1,1>::Constant(ncat,
            std::numeric_limits<double>::quiet_NaN()));
      std::vector<Eigen::Matrix<double,-1,1>> theta_agd_arm_bar =
        std::vector<Eigen::Matrix<double,-1,1>>(ni_agd_arm,
          Eigen::Matrix<double,-1,1>::Constant(ncat,
            std::numeric_limits<double>::quiet_NaN()));
      Eigen::Matrix<double,-1,1> eta_ipd =
        Eigen::Matrix<double,-1,1>::Constant(ni_ipd,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> f_delta =
        Eigen::Matrix<double,-1,1>::Constant(n_delta,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> f_class =
        Eigen::Matrix<double,-1,1>::Constant(f_class_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> allbeta =
        Eigen::Matrix<double,-1,1>::Constant(nX,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> mu =
        Eigen::Matrix<double,-1,1>::Constant(totns,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> d =
        Eigen::Matrix<double,-1,1>::Constant(d_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> omega =
        Eigen::Matrix<double,-1,1>::Constant(nodesplit,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> beta =
        Eigen::Matrix<double,-1,1>::Constant(beta_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> eta_agd_contrast_ii =
        Eigen::Matrix<double,-1,1>::Constant(eta_agd_contrast_ii_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> eta_agd_contrast_bar =
        Eigen::Matrix<double,-1,1>::Constant(ni_agd_contrast,
          std::numeric_limits<double>::quiet_NaN());
      out__.write(beta_tilde);
      out__.write(u_delta);
      out__.write(tau);
      out__.write(class_mean);
      out__.write(class_sd);
      out__.write(z_class);
      out__.write(f_cc);
      if (stan::math::logical_negation(
            (stan::math::primitive_value(emit_transformed_parameters__) ||
            stan::math::primitive_value(emit_generated_quantities__)))) {
        return ;
      }
      current_statement__ = 14;
      stan::model::assign(f_delta,
        (RE ? stan::math::eval(
                (RE_sparse ? stan::math::eval(
                               stan::math::multiply(
                                 stan::model::rvalue(tau, "tau",
                                   stan::model::index_uni(1)),
                                 stan::math::csr_matrix_times_vector(n_delta,
                                   n_delta, RE_L_w, RE_L_v, RE_L_u, u_delta))) : 
                stan::math::eval(
                  stan::math::multiply(
                    stan::math::multiply(
                      stan::model::rvalue(tau, "tau",
                        stan::model::index_uni(1)), RE_L), u_delta)))) : 
        stan::math::eval(u_delta)), "assigning variable f_delta");
      current_statement__ = 16;
      stan::model::assign(allbeta,
        (QR ? stan::math::eval(stan::math::multiply(R_inv, beta_tilde)) : 
        stan::math::eval(beta_tilde)), "assigning variable allbeta");
      current_statement__ = 18;
      stan::model::assign(d,
        stan::model::rvalue(allbeta, "allbeta",
          stan::model::index_min_max((totns + 1), ((totns + nt) - 1))),
        "assigning variable d");
      current_statement__ = 33;
      if (totns) {
        current_statement__ = 31;
        stan::model::assign(mu,
          stan::model::rvalue(allbeta, "allbeta",
            stan::model::index_min_max(1, totns)), "assigning variable mu");
      }
      current_statement__ = 36;
      if ((((nX - totns) - (nt - 1)) - nodesplit)) {
        current_statement__ = 34;
        stan::model::assign(beta,
          stan::model::rvalue(allbeta, "allbeta",
            stan::model::index_min(((totns + nt) + nodesplit))),
          "assigning variable beta");
      }
      current_statement__ = 39;
      if (nodesplit) {
        current_statement__ = 37;
        stan::model::assign(omega,
          stan::model::rvalue(allbeta, "allbeta",
            stan::model::index_uni((totns + nt))),
          "assigning variable omega", stan::model::index_uni(1));
      }
      current_statement__ = 43;
      if (class_effects) {
        current_statement__ = 40;
        stan::model::assign(f_class,
          stan::math::add(
            stan::math::subtract(
              stan::model::rvalue(class_mean, "class_mean",
                stan::model::index_multi(
                  stan::model::rvalue(which_CE, "which_CE",
                    stan::model::index_multi(which_class_trt)))),
              stan::model::rvalue(d, "d",
                stan::model::index_multi(which_class_trt))),
            stan::math::elt_multiply(
              stan::model::rvalue(class_sd, "class_sd",
                stan::model::index_multi(
                  stan::model::rvalue(which_CE_sd, "which_CE_sd",
                    stan::model::index_multi(which_class_trt)))), z_class)),
          "assigning variable f_class");
        current_statement__ = 41;
        stan::model::assign(d,
          stan::math::add(
            stan::model::rvalue(class_mean, "class_mean",
              stan::model::index_multi(
                stan::model::rvalue(which_CE, "which_CE",
                  stan::model::index_multi(which_class_trt)))),
            stan::math::elt_multiply(
              stan::model::rvalue(class_sd, "class_sd",
                stan::model::index_multi(
                  stan::model::rvalue(which_CE_sd, "which_CE_sd",
                    stan::model::index_multi(which_class_trt)))), z_class)),
          "assigning variable d", stan::model::index_multi(which_class_trt));
      }
      current_statement__ = 67;
      if (ni_ipd) {
        current_statement__ = 55;
        if (RE) {
          current_statement__ = 46;
          stan::math::validate_non_negative_index("eta_ipd_noRE", "ni_ipd",
            ni_ipd);
          Eigen::Matrix<double,-1,1> eta_ipd_noRE =
            Eigen::Matrix<double,-1,1>::Constant(ni_ipd,
              std::numeric_limits<double>::quiet_NaN());
          current_statement__ = 47;
          stan::model::assign(eta_ipd_noRE,
            (has_offset ? stan::math::eval(
                            stan::math::add(
                              stan::math::multiply(X_ipd, beta_tilde),
                              offset_ipd)) : stan::math::eval(
                                               stan::math::multiply(X_ipd,
                                                 beta_tilde))),
            "assigning variable eta_ipd_noRE");
          current_statement__ = 52;
          for (int i = 1; i <= ni_ipd; ++i) {
            current_statement__ = 50;
            if (stan::model::rvalue(which_RE, "which_RE",
                  stan::model::index_uni(
                    stan::model::rvalue(ipd_arm, "ipd_arm",
                      stan::model::index_uni(i))))) {
              current_statement__ = 49;
              stan::model::assign(eta_ipd,
                (stan::model::rvalue(eta_ipd_noRE, "eta_ipd_noRE",
                   stan::model::index_uni(i)) +
                stan::model::rvalue(f_delta, "f_delta",
                  stan::model::index_uni(
                    stan::model::rvalue(which_RE, "which_RE",
                      stan::model::index_uni(
                        stan::model::rvalue(ipd_arm, "ipd_arm",
                          stan::model::index_uni(i))))))),
                "assigning variable eta_ipd", stan::model::index_uni(i));
            } else {
              current_statement__ = 48;
              stan::model::assign(eta_ipd,
                stan::model::rvalue(eta_ipd_noRE, "eta_ipd_noRE",
                  stan::model::index_uni(i)), "assigning variable eta_ipd",
                stan::model::index_uni(i));
            }
          }
        } else {
          current_statement__ = 44;
          stan::model::assign(eta_ipd,
            (has_offset ? stan::math::eval(
                            stan::math::add(
                              stan::math::multiply(X_ipd, beta_tilde),
                              offset_ipd)) : stan::math::eval(
                                               stan::math::multiply(X_ipd,
                                                 beta_tilde))),
            "assigning variable eta_ipd");
        }
        current_statement__ = 58;
        if (stan::math::logical_gt(brmr_n_col, 0)) {
          current_statement__ = 56;
          stan::model::assign(eta_ipd,
            stan::math::add(stan::model::deep_copy(eta_ipd),
              stan::math::elt_multiply(
                stan::math::subtract(
                  stan::math::subtract(
                    stan::math::multiply(
                      stan::model::rvalue(X_ipd, "X_ipd",
                        stan::model::index_omni(),
                        stan::model::index_min_max(1, totns)), mu), xbar_mu),
                  1),
                stan::math::multiply(
                  stan::model::rvalue(X_ipd, "X_ipd",
                    stan::model::index_omni(),
                    stan::model::index_multi(brmr_col)),
                  stan::model::rvalue(beta_tilde, "beta_tilde",
                    stan::model::index_multi(brmr_col))))),
            "assigning variable eta_ipd");
        }
        current_statement__ = 65;
        if (class_effects) {
          current_statement__ = 63;
          for (int i = 1; i <= ni_ipd; ++i) {
            current_statement__ = 61;
            if ((stan::math::primitive_value(
                   stan::math::logical_gt(
                     stan::model::rvalue(ipd_trt, "ipd_trt",
                       stan::model::index_uni(
                         stan::model::rvalue(ipd_arm, "ipd_arm",
                           stan::model::index_uni(i)))), 1))
                &&
                stan::math::primitive_value(
                  stan::model::rvalue(which_CE, "which_CE",
                    stan::model::index_uni(
                      (stan::model::rvalue(ipd_trt, "ipd_trt",
                         stan::model::index_uni(
                           stan::model::rvalue(ipd_arm, "ipd_arm",
                             stan::model::index_uni(i)))) - 1)))))) {
              current_statement__ = 59;
              stan::model::assign(eta_ipd,
                (stan::model::rvalue(eta_ipd, "eta_ipd",
                   stan::model::index_uni(i)) +
                stan::model::rvalue(f_class, "f_class",
                  stan::model::index_uni(
                    stan::model::rvalue(which_fclass, "which_fclass",
                      stan::model::index_uni(
                        (stan::model::rvalue(ipd_trt, "ipd_trt",
                           stan::model::index_uni(
                             stan::model::rvalue(ipd_arm, "ipd_arm",
                               stan::model::index_uni(i)))) - 1)))))),
                "assigning variable eta_ipd", stan::model::index_uni(i));
            }
          }
        }
      }
      current_statement__ = 122;
      if (ni_agd_contrast) {
        current_statement__ = 120;
        if (stan::math::logical_gt(nint_max, 1)) {
          current_statement__ = 90;
          stan::math::validate_non_negative_index("eta_agd_contrast_noRE",
            "nint_max * ni_agd_contrast", (nint_max * ni_agd_contrast));
          Eigen::Matrix<double,-1,1> eta_agd_contrast_noRE =
            Eigen::Matrix<double,-1,1>::Constant((nint_max *
              ni_agd_contrast), std::numeric_limits<double>::quiet_NaN());
          current_statement__ = 91;
          stan::model::assign(eta_agd_contrast_noRE,
            (has_offset ? stan::math::eval(
                            stan::math::add(
                              stan::math::multiply(X_agd_contrast, beta_tilde),
                              offset_agd_contrast)) : stan::math::eval(
                                                        stan::math::multiply(
                                                          X_agd_contrast,
                                                          beta_tilde))),
            "assigning variable eta_agd_contrast_noRE");
          current_statement__ = 101;
          if (class_effects) {
            current_statement__ = 99;
            for (int i = 1; i <= ni_agd_arm; ++i) {
              current_statement__ = 94;
              if ((stan::math::primitive_value(
                     stan::math::logical_gt(
                       stan::model::rvalue(agd_contrast_trt,
                         "agd_contrast_trt", stan::model::index_uni(i)), 1))
                  &&
                  stan::math::primitive_value(
                    stan::model::rvalue(which_CE, "which_CE",
                      stan::model::index_uni(
                        (stan::model::rvalue(agd_contrast_trt,
                           "agd_contrast_trt", stan::model::index_uni(i)) -
                        1)))))) {
                current_statement__ = 92;
                stan::model::assign(eta_agd_contrast_noRE,
                  stan::math::add(
                    stan::model::deep_copy(
                      stan::model::rvalue(eta_agd_contrast_noRE,
                        "eta_agd_contrast_noRE",
                        stan::model::index_min_max((1 + ((i - 1) *
                          nint_max)), (((i - 1) * nint_max) + nint)))),
                    stan::model::rvalue(f_class, "f_class",
                      stan::model::index_uni(
                        stan::model::rvalue(which_fclass, "which_fclass",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_contrast_trt,
                               "agd_contrast_trt", stan::model::index_uni(i))
                            - 1)))))),
                  "assigning variable eta_agd_contrast_noRE",
                  stan::model::index_min_max((1 + ((i - 1) * nint_max)), (((i
                    - 1) * nint_max) + nint)));
              }
              current_statement__ = 97;
              if ((stan::math::primitive_value(
                     stan::math::logical_gt(
                       stan::model::rvalue(agd_contrast_trt_b,
                         "agd_contrast_trt_b", stan::model::index_uni(i)), 1))
                  &&
                  stan::math::primitive_value(
                    stan::model::rvalue(which_CE, "which_CE",
                      stan::model::index_uni(
                        (stan::model::rvalue(agd_contrast_trt_b,
                           "agd_contrast_trt_b", stan::model::index_uni(i)) -
                        1)))))) {
                current_statement__ = 95;
                stan::model::assign(eta_agd_contrast_noRE,
                  stan::math::subtract(
                    stan::model::deep_copy(
                      stan::model::rvalue(eta_agd_contrast_noRE,
                        "eta_agd_contrast_noRE",
                        stan::model::index_min_max((1 + ((i - 1) *
                          nint_max)), (((i - 1) * nint_max) + nint)))),
                    stan::model::rvalue(f_class, "f_class",
                      stan::model::index_uni(
                        stan::model::rvalue(which_fclass, "which_fclass",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_contrast_trt_b,
                               "agd_contrast_trt_b",
                               stan::model::index_uni(i)) - 1)))))),
                  "assigning variable eta_agd_contrast_noRE",
                  stan::model::index_min_max((1 + ((i - 1) * nint_max)), (((i
                    - 1) * nint_max) + nint)));
              }
            }
          }
          current_statement__ = 118;
          if (RE) {
            current_statement__ = 116;
            for (int i = 1; i <= ni_agd_contrast; ++i) {
              current_statement__ = 113;
              if (stan::model::rvalue(which_RE, "which_RE",
                    stan::model::index_uni(((narm_ipd + narm_agd_arm) + i)))) {
                current_statement__ = 112;
                stan::model::assign(eta_agd_contrast_ii,
                  stan::math::add(
                    stan::model::rvalue(eta_agd_contrast_noRE,
                      "eta_agd_contrast_noRE",
                      stan::model::index_min_max((1 + ((i - 1) * nint_max)),
                        (((i - 1) * nint_max) + nint))),
                    stan::model::rvalue(f_delta, "f_delta",
                      stan::model::index_uni(
                        stan::model::rvalue(which_RE, "which_RE",
                          stan::model::index_uni(((narm_ipd + narm_agd_arm) +
                            i)))))),
                  "assigning variable eta_agd_contrast_ii",
                  stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                    nint)));
              } else {
                current_statement__ = 111;
                stan::model::assign(eta_agd_contrast_ii,
                  stan::model::rvalue(eta_agd_contrast_noRE,
                    "eta_agd_contrast_noRE",
                    stan::model::index_min_max((1 + ((i - 1) * nint_max)),
                      (((i - 1) * nint_max) + nint))),
                  "assigning variable eta_agd_contrast_ii",
                  stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                    nint)));
              }
              current_statement__ = 114;
              stan::model::assign(eta_agd_contrast_bar,
                stan::math::mean(
                  stan::model::rvalue(eta_agd_contrast_ii,
                    "eta_agd_contrast_ii",
                    stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                      nint)))), "assigning variable eta_agd_contrast_bar",
                stan::model::index_uni(i));
            }
          } else {
            current_statement__ = 106;
            if (stan::math::logical_eq(nint, nint_max)) {
              current_statement__ = 105;
              stan::model::assign(eta_agd_contrast_ii, eta_agd_contrast_noRE,
                "assigning variable eta_agd_contrast_ii");
            } else {
              current_statement__ = 104;
              for (int i = 1; i <= ni_agd_contrast; ++i) {
                current_statement__ = 102;
                stan::model::assign(eta_agd_contrast_ii,
                  stan::model::rvalue(eta_agd_contrast_noRE,
                    "eta_agd_contrast_noRE",
                    stan::model::index_min_max((1 + ((i - 1) * nint_max)),
                      (((i - 1) * nint_max) + nint))),
                  "assigning variable eta_agd_contrast_ii",
                  stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                    nint)));
              }
            }
            current_statement__ = 109;
            for (int i = 1; i <= ni_agd_contrast; ++i) {
              current_statement__ = 107;
              stan::model::assign(eta_agd_contrast_bar,
                stan::math::mean(
                  stan::model::rvalue(eta_agd_contrast_ii,
                    "eta_agd_contrast_ii",
                    stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                      nint)))), "assigning variable eta_agd_contrast_bar",
                stan::model::index_uni(i));
            }
          }
        } else {
          current_statement__ = 78;
          if (RE) {
            current_statement__ = 70;
            stan::math::validate_non_negative_index("eta_agd_contrast_noRE",
              "nint * ni_agd_contrast", (nint * ni_agd_contrast));
            Eigen::Matrix<double,-1,1> eta_agd_contrast_noRE =
              Eigen::Matrix<double,-1,1>::Constant((nint * ni_agd_contrast),
                std::numeric_limits<double>::quiet_NaN());
            current_statement__ = 71;
            stan::model::assign(eta_agd_contrast_noRE,
              (has_offset ? stan::math::eval(
                              stan::math::add(
                                stan::math::multiply(X_agd_contrast,
                                  beta_tilde), offset_agd_contrast)) : 
              stan::math::eval(
                stan::math::multiply(X_agd_contrast, beta_tilde))),
              "assigning variable eta_agd_contrast_noRE");
            current_statement__ = 76;
            for (int i = 1; i <= ni_agd_contrast; ++i) {
              current_statement__ = 74;
              if (stan::model::rvalue(which_RE, "which_RE",
                    stan::model::index_uni(((narm_ipd + narm_agd_arm) + i)))) {
                current_statement__ = 73;
                stan::model::assign(eta_agd_contrast_bar,
                  (stan::model::rvalue(eta_agd_contrast_noRE,
                     "eta_agd_contrast_noRE", stan::model::index_uni(i)) +
                  stan::model::rvalue(f_delta, "f_delta",
                    stan::model::index_uni(
                      stan::model::rvalue(which_RE, "which_RE",
                        stan::model::index_uni(((narm_ipd + narm_agd_arm) +
                          i)))))), "assigning variable eta_agd_contrast_bar",
                  stan::model::index_uni(i));
              } else {
                current_statement__ = 72;
                stan::model::assign(eta_agd_contrast_bar,
                  stan::model::rvalue(eta_agd_contrast_noRE,
                    "eta_agd_contrast_noRE", stan::model::index_uni(i)),
                  "assigning variable eta_agd_contrast_bar",
                  stan::model::index_uni(i));
              }
            }
          } else {
            current_statement__ = 68;
            stan::model::assign(eta_agd_contrast_bar,
              (has_offset ? stan::math::eval(
                              stan::math::add(
                                stan::math::multiply(X_agd_contrast,
                                  beta_tilde), offset_agd_contrast)) : 
              stan::math::eval(
                stan::math::multiply(X_agd_contrast, beta_tilde))),
              "assigning variable eta_agd_contrast_bar");
          }
          current_statement__ = 88;
          if (class_effects) {
            current_statement__ = 86;
            for (int i = 1; i <= ni_agd_contrast; ++i) {
              current_statement__ = 81;
              if ((stan::math::primitive_value(
                     stan::math::logical_gt(
                       stan::model::rvalue(agd_contrast_trt,
                         "agd_contrast_trt", stan::model::index_uni(i)), 1))
                  &&
                  stan::math::primitive_value(
                    stan::model::rvalue(which_CE, "which_CE",
                      stan::model::index_uni(
                        (stan::model::rvalue(agd_contrast_trt,
                           "agd_contrast_trt", stan::model::index_uni(i)) -
                        1)))))) {
                current_statement__ = 79;
                stan::model::assign(eta_agd_contrast_bar,
                  (stan::model::rvalue(eta_agd_contrast_bar,
                     "eta_agd_contrast_bar", stan::model::index_uni(i)) +
                  stan::model::rvalue(f_class, "f_class",
                    stan::model::index_uni(
                      stan::model::rvalue(which_fclass, "which_fclass",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_contrast_trt,
                             "agd_contrast_trt", stan::model::index_uni(i)) -
                          1)))))), "assigning variable eta_agd_contrast_bar",
                  stan::model::index_uni(i));
              }
              current_statement__ = 84;
              if ((stan::math::primitive_value(
                     stan::math::logical_gt(
                       stan::model::rvalue(agd_contrast_trt_b,
                         "agd_contrast_trt_b", stan::model::index_uni(i)), 1))
                  &&
                  stan::math::primitive_value(
                    stan::model::rvalue(which_CE, "which_CE",
                      stan::model::index_uni(
                        (stan::model::rvalue(agd_contrast_trt_b,
                           "agd_contrast_trt_b", stan::model::index_uni(i)) -
                        1)))))) {
                current_statement__ = 82;
                stan::model::assign(eta_agd_contrast_bar,
                  (stan::model::rvalue(eta_agd_contrast_bar,
                     "eta_agd_contrast_bar", stan::model::index_uni(i)) -
                  stan::model::rvalue(f_class, "f_class",
                    stan::model::index_uni(
                      stan::model::rvalue(which_fclass, "which_fclass",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_contrast_trt_b,
                             "agd_contrast_trt_b", stan::model::index_uni(i))
                          - 1)))))),
                  "assigning variable eta_agd_contrast_bar",
                  stan::model::index_uni(i));
              }
            }
          }
        }
      }
      current_statement__ = 123;
      stan::model::assign(cc, 0, "assigning variable cc",
        stan::model::index_uni(1));
      current_statement__ = 125;
      if (stan::math::logical_gt(ncat, 2)) {
        current_statement__ = 124;
        stan::model::assign(cc, f_cc, "assigning variable cc",
          stan::model::index_min(2));
      }
      current_statement__ = 126;
      stan::model::assign(theta_ipd, theta_ipd0,
        "assigning variable theta_ipd");
      current_statement__ = 127;
      stan::model::assign(theta_agd_arm_bar, theta_agd_arm_bar0,
        "assigning variable theta_agd_arm_bar");
      current_statement__ = 144;
      for (int i = 1; i <= ni_ipd; ++i) {
        current_statement__ = 128;
        stan::math::validate_non_negative_index("q_temp", "ipd_ncat[i] - 1",
          (stan::model::rvalue(ipd_ncat, "ipd_ncat",
             stan::model::index_uni(i)) - 1));
        Eigen::Matrix<double,-1,1> q_temp =
          Eigen::Matrix<double,-1,1>::Constant((stan::model::rvalue(ipd_ncat,
                                                  "ipd_ncat",
                                                  stan::model::index_uni(i))
            - 1), std::numeric_limits<double>::quiet_NaN());
        current_statement__ = 137;
        for (int k = 1; k <=
             (stan::model::rvalue(ipd_ncat, "ipd_ncat",
                stan::model::index_uni(i)) - 1); ++k) {
          current_statement__ = 135;
          if (stan::math::logical_eq(link, 1)) {
            current_statement__ = 134;
            stan::model::assign(q_temp,
              stan::math::inv_logit(
                (stan::model::rvalue(eta_ipd, "eta_ipd",
                   stan::model::index_uni(i)) -
                stan::model::rvalue(cc, "cc",
                  stan::model::index_uni(
                    (stan::model::rvalue(ipd_cat, "ipd_cat",
                       stan::model::index_uni(i),
                       stan::model::index_uni((k + 1))) - 1))))),
              "assigning variable q_temp", stan::model::index_uni(k));
          } else {
            current_statement__ = 133;
            if (stan::math::logical_eq(link, 2)) {
              current_statement__ = 132;
              stan::model::assign(q_temp,
                stan::math::Phi(
                  (stan::model::rvalue(eta_ipd, "eta_ipd",
                     stan::model::index_uni(i)) -
                  stan::model::rvalue(cc, "cc",
                    stan::model::index_uni(
                      (stan::model::rvalue(ipd_cat, "ipd_cat",
                         stan::model::index_uni(i),
                         stan::model::index_uni((k + 1))) - 1))))),
                "assigning variable q_temp", stan::model::index_uni(k));
            } else {
              current_statement__ = 131;
              if (stan::math::logical_eq(link, 3)) {
                current_statement__ = 130;
                stan::model::assign(q_temp,
                  stan::math::inv_cloglog(
                    (stan::model::rvalue(eta_ipd, "eta_ipd",
                       stan::model::index_uni(i)) -
                    stan::model::rvalue(cc, "cc",
                      stan::model::index_uni(
                        (stan::model::rvalue(ipd_cat, "ipd_cat",
                           stan::model::index_uni(i),
                           stan::model::index_uni((k + 1))) - 1))))),
                  "assigning variable q_temp", stan::model::index_uni(k));
              }
            }
          }
        }
        current_statement__ = 138;
        stan::model::assign(theta_ipd, (1 -
          stan::model::rvalue(q_temp, "q_temp", stan::model::index_uni(1))),
          "assigning variable theta_ipd", stan::model::index_uni(i),
          stan::model::index_uni(1));
        current_statement__ = 141;
        for (int k = 2; k <=
             (stan::model::rvalue(ipd_ncat, "ipd_ncat",
                stan::model::index_uni(i)) - 1); ++k) {
          current_statement__ = 139;
          stan::model::assign(theta_ipd,
            (stan::model::rvalue(q_temp, "q_temp",
               stan::model::index_uni((k - 1))) -
            stan::model::rvalue(q_temp, "q_temp", stan::model::index_uni(k))),
            "assigning variable theta_ipd", stan::model::index_uni(i),
            stan::model::index_uni(
              stan::model::rvalue(ipd_cat, "ipd_cat",
                stan::model::index_uni(i), stan::model::index_uni(k))));
        }
        current_statement__ = 142;
        stan::model::assign(theta_ipd,
          stan::model::rvalue(q_temp, "q_temp",
            stan::model::index_uni(
              (stan::model::rvalue(ipd_ncat, "ipd_ncat",
                 stan::model::index_uni(i)) - 1))),
          "assigning variable theta_ipd", stan::model::index_uni(i),
          stan::model::index_uni(
            stan::model::rvalue(ipd_cat, "ipd_cat",
              stan::model::index_uni(i),
              stan::model::index_uni(
                stan::model::rvalue(ipd_ncat, "ipd_ncat",
                  stan::model::index_uni(i))))));
      }
      current_statement__ = 297;
      if (ni_agd_arm) {
        current_statement__ = 145;
        stan::math::validate_non_negative_index("eta_agd_arm_noRE",
          "nint_max * ni_agd_arm", (nint_max * ni_agd_arm));
        Eigen::Matrix<double,-1,1> eta_agd_arm_noRE =
          Eigen::Matrix<double,-1,1>::Constant((nint_max * ni_agd_arm),
            std::numeric_limits<double>::quiet_NaN());
        current_statement__ = 146;
        stan::model::assign(eta_agd_arm_noRE,
          (has_offset ? stan::math::eval(
                          stan::math::add(
                            stan::math::multiply(X_agd_arm, beta_tilde),
                            offset_agd_arm)) : stan::math::eval(
                                                 stan::math::multiply(
                                                   X_agd_arm, beta_tilde))),
          "assigning variable eta_agd_arm_noRE");
        current_statement__ = 149;
        if (stan::math::logical_gt(brmr_n_col, 0)) {
          current_statement__ = 147;
          stan::model::assign(eta_agd_arm_noRE,
            stan::math::add(stan::model::deep_copy(eta_agd_arm_noRE),
              stan::math::elt_multiply(
                stan::math::subtract(
                  stan::math::subtract(
                    stan::math::multiply(
                      stan::model::rvalue(X_agd_arm, "X_agd_arm",
                        stan::model::index_omni(),
                        stan::model::index_min_max(1, totns)), mu), xbar_mu),
                  1),
                stan::math::multiply(
                  stan::model::rvalue(X_agd_arm, "X_agd_arm",
                    stan::model::index_omni(),
                    stan::model::index_multi(brmr_col)),
                  stan::model::rvalue(beta_tilde, "beta_tilde",
                    stan::model::index_multi(brmr_col))))),
            "assigning variable eta_agd_arm_noRE");
        }
        current_statement__ = 156;
        if (class_effects) {
          current_statement__ = 154;
          for (int i = 1; i <= ni_agd_arm; ++i) {
            current_statement__ = 152;
            if ((stan::math::primitive_value(
                   stan::math::logical_gt(
                     stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                       stan::model::index_uni(i)), 1))
                &&
                stan::math::primitive_value(
                  stan::model::rvalue(which_CE, "which_CE",
                    stan::model::index_uni(
                      (stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                         stan::model::index_uni(i)) - 1)))))) {
              current_statement__ = 150;
              stan::model::assign(eta_agd_arm_noRE,
                stan::math::add(
                  stan::model::deep_copy(
                    stan::model::rvalue(eta_agd_arm_noRE, "eta_agd_arm_noRE",
                      stan::model::index_min_max((1 + ((i - 1) * nint_max)),
                        (((i - 1) * nint_max) + nint)))),
                  stan::model::rvalue(f_class, "f_class",
                    stan::model::index_uni(
                      stan::model::rvalue(which_fclass, "which_fclass",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                             stan::model::index_uni(i)) - 1)))))),
                "assigning variable eta_agd_arm_noRE",
                stan::model::index_min_max((1 + ((i - 1) * nint_max)), (((i -
                  1) * nint_max) + nint)));
            }
          }
        }
        current_statement__ = 289;
        if (stan::math::logical_gt(nint_max, 1)) {
          current_statement__ = 282;
          if (RE) {
            current_statement__ = 249;
            stan::math::validate_non_negative_index("eta_agd_arm_RE", "nint",
              nint);
            Eigen::Matrix<double,-1,1> eta_agd_arm_RE =
              Eigen::Matrix<double,-1,1>::Constant(nint,
                std::numeric_limits<double>::quiet_NaN());
            current_statement__ = 280;
            if (stan::math::logical_eq(link, 1)) {
              current_statement__ = 278;
              for (int i = 1; i <= ni_agd_arm; ++i) {
                current_statement__ = 273;
                if (stan::model::rvalue(which_RE, "which_RE",
                      stan::model::index_uni((narm_ipd + i)))) {
                  current_statement__ = 272;
                  stan::model::assign(eta_agd_arm_RE,
                    stan::math::add(
                      stan::model::rvalue(eta_agd_arm_noRE,
                        "eta_agd_arm_noRE",
                        stan::model::index_min_max((1 + ((i - 1) *
                          nint_max)), (((i - 1) * nint_max) + nint))),
                      stan::model::rvalue(f_delta, "f_delta",
                        stan::model::index_uni(
                          stan::model::rvalue(which_RE, "which_RE",
                            stan::model::index_uni((narm_ipd + i)))))),
                    "assigning variable eta_agd_arm_RE");
                } else {
                  current_statement__ = 271;
                  stan::model::assign(eta_agd_arm_RE,
                    stan::model::rvalue(eta_agd_arm_noRE, "eta_agd_arm_noRE",
                      stan::model::index_min_max((1 + ((i - 1) * nint_max)),
                        (((i - 1) * nint_max) + nint))),
                    "assigning variable eta_agd_arm_RE");
                }
                current_statement__ = 276;
                for (int k = 1; k <=
                     (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                        stan::model::index_uni(i)) - 1); ++k) {
                  current_statement__ = 274;
                  stan::model::assign(theta_agd_arm_ii,
                    stan::math::inv_logit(
                      stan::math::subtract(eta_agd_arm_RE,
                        stan::model::rvalue(cc, "cc",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                               stan::model::index_uni(i),
                               stan::model::index_uni((k + 1))) - 1))))),
                    "assigning variable theta_agd_arm_ii",
                    stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                      nint)), stan::model::index_uni(k));
                }
              }
            } else {
              current_statement__ = 270;
              if (stan::math::logical_eq(link, 2)) {
                current_statement__ = 268;
                for (int i = 1; i <= ni_agd_arm; ++i) {
                  current_statement__ = 263;
                  if (stan::model::rvalue(which_RE, "which_RE",
                        stan::model::index_uni((narm_ipd + i)))) {
                    current_statement__ = 262;
                    stan::model::assign(eta_agd_arm_RE,
                      stan::math::add(
                        stan::model::rvalue(eta_agd_arm_noRE,
                          "eta_agd_arm_noRE",
                          stan::model::index_min_max((1 + ((i - 1) *
                            nint_max)), (((i - 1) * nint_max) + nint))),
                        stan::model::rvalue(f_delta, "f_delta",
                          stan::model::index_uni(
                            stan::model::rvalue(which_RE, "which_RE",
                              stan::model::index_uni((narm_ipd + i)))))),
                      "assigning variable eta_agd_arm_RE");
                  } else {
                    current_statement__ = 261;
                    stan::model::assign(eta_agd_arm_RE,
                      stan::model::rvalue(eta_agd_arm_noRE,
                        "eta_agd_arm_noRE",
                        stan::model::index_min_max((1 + ((i - 1) *
                          nint_max)), (((i - 1) * nint_max) + nint))),
                      "assigning variable eta_agd_arm_RE");
                  }
                  current_statement__ = 266;
                  for (int k = 1; k <=
                       (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                          stan::model::index_uni(i)) - 1); ++k) {
                    current_statement__ = 264;
                    stan::model::assign(theta_agd_arm_ii,
                      stan::math::Phi(
                        stan::math::subtract(eta_agd_arm_RE,
                          stan::model::rvalue(cc, "cc",
                            stan::model::index_uni(
                              (stan::model::rvalue(agd_arm_cat,
                                 "agd_arm_cat", stan::model::index_uni(i),
                                 stan::model::index_uni((k + 1))) - 1))))),
                      "assigning variable theta_agd_arm_ii",
                      stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                        nint)), stan::model::index_uni(k));
                  }
                }
              } else {
                current_statement__ = 260;
                if (stan::math::logical_eq(link, 3)) {
                  current_statement__ = 258;
                  for (int i = 1; i <= ni_agd_arm; ++i) {
                    current_statement__ = 253;
                    if (stan::model::rvalue(which_RE, "which_RE",
                          stan::model::index_uni((narm_ipd + i)))) {
                      current_statement__ = 252;
                      stan::model::assign(eta_agd_arm_RE,
                        stan::math::add(
                          stan::model::rvalue(eta_agd_arm_noRE,
                            "eta_agd_arm_noRE",
                            stan::model::index_min_max((1 + ((i - 1) *
                              nint_max)), (((i - 1) * nint_max) + nint))),
                          stan::model::rvalue(f_delta, "f_delta",
                            stan::model::index_uni(
                              stan::model::rvalue(which_RE, "which_RE",
                                stan::model::index_uni((narm_ipd + i)))))),
                        "assigning variable eta_agd_arm_RE");
                    } else {
                      current_statement__ = 251;
                      stan::model::assign(eta_agd_arm_RE,
                        stan::model::rvalue(eta_agd_arm_noRE,
                          "eta_agd_arm_noRE",
                          stan::model::index_min_max((1 + ((i - 1) *
                            nint_max)), (((i - 1) * nint_max) + nint))),
                        "assigning variable eta_agd_arm_RE");
                    }
                    current_statement__ = 256;
                    for (int k = 1; k <=
                         (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                            stan::model::index_uni(i)) - 1); ++k) {
                      current_statement__ = 254;
                      stan::model::assign(theta_agd_arm_ii,
                        stan::math::inv_cloglog(
                          stan::math::subtract(eta_agd_arm_RE,
                            stan::model::rvalue(cc, "cc",
                              stan::model::index_uni(
                                (stan::model::rvalue(agd_arm_cat,
                                   "agd_arm_cat", stan::model::index_uni(i),
                                   stan::model::index_uni((k + 1))) - 1))))),
                        "assigning variable theta_agd_arm_ii",
                        stan::model::index_min_max((1 + ((i - 1) * nint)), (i
                          * nint)), stan::model::index_uni(k));
                    }
                  }
                }
              }
            }
          } else {
            current_statement__ = 247;
            if (stan::math::logical_eq(link, 1)) {
              current_statement__ = 245;
              for (int i = 1; i <= ni_agd_arm; ++i) {
                current_statement__ = 243;
                for (int k = 1; k <=
                     (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                        stan::model::index_uni(i)) - 1); ++k) {
                  current_statement__ = 241;
                  stan::model::assign(theta_agd_arm_ii,
                    stan::math::inv_logit(
                      stan::math::subtract(
                        stan::model::rvalue(eta_agd_arm_noRE,
                          "eta_agd_arm_noRE",
                          stan::model::index_min_max((1 + ((i - 1) *
                            nint_max)), (((i - 1) * nint_max) + nint))),
                        stan::model::rvalue(cc, "cc",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                               stan::model::index_uni(i),
                               stan::model::index_uni((k + 1))) - 1))))),
                    "assigning variable theta_agd_arm_ii",
                    stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                      nint)), stan::model::index_uni(k));
                }
              }
            } else {
              current_statement__ = 240;
              if (stan::math::logical_eq(link, 2)) {
                current_statement__ = 238;
                for (int i = 1; i <= ni_agd_arm; ++i) {
                  current_statement__ = 236;
                  for (int k = 1; k <=
                       (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                          stan::model::index_uni(i)) - 1); ++k) {
                    current_statement__ = 234;
                    stan::model::assign(theta_agd_arm_ii,
                      stan::math::Phi(
                        stan::math::subtract(
                          stan::model::rvalue(eta_agd_arm_noRE,
                            "eta_agd_arm_noRE",
                            stan::model::index_min_max((1 + ((i - 1) *
                              nint_max)), (((i - 1) * nint_max) + nint))),
                          stan::model::rvalue(cc, "cc",
                            stan::model::index_uni(
                              (stan::model::rvalue(agd_arm_cat,
                                 "agd_arm_cat", stan::model::index_uni(i),
                                 stan::model::index_uni((k + 1))) - 1))))),
                      "assigning variable theta_agd_arm_ii",
                      stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                        nint)), stan::model::index_uni(k));
                  }
                }
              } else {
                current_statement__ = 233;
                if (stan::math::logical_eq(link, 3)) {
                  current_statement__ = 231;
                  for (int i = 1; i <= ni_agd_arm; ++i) {
                    current_statement__ = 229;
                    for (int k = 1; k <=
                         (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                            stan::model::index_uni(i)) - 1); ++k) {
                      current_statement__ = 227;
                      stan::model::assign(theta_agd_arm_ii,
                        stan::math::inv_cloglog(
                          stan::math::subtract(
                            stan::model::rvalue(eta_agd_arm_noRE,
                              "eta_agd_arm_noRE",
                              stan::model::index_min_max((1 + ((i - 1) *
                                nint_max)), (((i - 1) * nint_max) + nint))),
                            stan::model::rvalue(cc, "cc",
                              stan::model::index_uni(
                                (stan::model::rvalue(agd_arm_cat,
                                   "agd_arm_cat", stan::model::index_uni(i),
                                   stan::model::index_uni((k + 1))) - 1))))),
                        "assigning variable theta_agd_arm_ii",
                        stan::model::index_min_max((1 + ((i - 1) * nint)), (i
                          * nint)), stan::model::index_uni(k));
                    }
                  }
                }
              }
            }
          }
          current_statement__ = 287;
          for (int i = 1; i <= ni_agd_arm; ++i) {
            current_statement__ = 285;
            for (int k = 1; k <=
                 (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                    stan::model::index_uni(i)) - 1); ++k) {
              current_statement__ = 283;
              stan::model::assign(q_agd_arm_bar,
                stan::math::mean(
                  stan::model::rvalue(theta_agd_arm_ii, "theta_agd_arm_ii",
                    stan::model::index_min_max((1 + ((i - 1) * nint)), (i *
                      nint)), stan::model::index_uni(k))),
                "assigning variable q_agd_arm_bar",
                stan::model::index_uni(i), stan::model::index_uni(k));
            }
          }
        } else {
          current_statement__ = 225;
          if (RE) {
            double eta_agd_arm_RE = std::numeric_limits<double>::quiet_NaN();
            current_statement__ = 193;
            if (class_effects) {
              current_statement__ = 191;
              for (int i = 1; i <= ni_agd_arm; ++i) {
                current_statement__ = 189;
                if ((stan::math::primitive_value(
                       stan::math::logical_gt(
                         stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                           stan::model::index_uni(i)), 1))
                    &&
                    stan::math::primitive_value(
                      stan::model::rvalue(which_CE, "which_CE",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                             stan::model::index_uni(i)) - 1)))))) {
                  current_statement__ = 187;
                  stan::model::assign(eta_agd_arm_noRE,
                    (stan::model::rvalue(eta_agd_arm_noRE,
                       "eta_agd_arm_noRE", stan::model::index_uni(i)) +
                    stan::model::rvalue(f_class, "f_class",
                      stan::model::index_uni(
                        stan::model::rvalue(which_fclass, "which_fclass",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                               stan::model::index_uni(i)) - 1)))))),
                    "assigning variable eta_agd_arm_noRE",
                    stan::model::index_uni(i));
                }
              }
            }
            current_statement__ = 223;
            if (stan::math::logical_eq(link, 1)) {
              current_statement__ = 221;
              for (int i = 1; i <= ni_agd_arm; ++i) {
                current_statement__ = 216;
                if (stan::model::rvalue(which_RE, "which_RE",
                      stan::model::index_uni((narm_ipd + i)))) {
                  current_statement__ = 215;
                  eta_agd_arm_RE = (stan::model::rvalue(eta_agd_arm_noRE,
                                      "eta_agd_arm_noRE",
                                      stan::model::index_uni(i))
                    +
                    stan::model::rvalue(f_delta, "f_delta",
                      stan::model::index_uni(
                        stan::model::rvalue(which_RE, "which_RE",
                          stan::model::index_uni((narm_ipd + i))))));
                } else {
                  current_statement__ = 214;
                  eta_agd_arm_RE = stan::model::rvalue(eta_agd_arm_noRE,
                                     "eta_agd_arm_noRE",
                                     stan::model::index_uni(i));
                }
                current_statement__ = 219;
                for (int k = 1; k <=
                     (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                        stan::model::index_uni(i)) - 1); ++k) {
                  current_statement__ = 217;
                  stan::model::assign(q_agd_arm_bar,
                    stan::math::inv_logit((eta_agd_arm_RE -
                      stan::model::rvalue(cc, "cc",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                             stan::model::index_uni(i),
                             stan::model::index_uni((k + 1))) - 1))))),
                    "assigning variable q_agd_arm_bar",
                    stan::model::index_uni(i), stan::model::index_uni(k));
                }
              }
            } else {
              current_statement__ = 213;
              if (stan::math::logical_eq(link, 2)) {
                current_statement__ = 211;
                for (int i = 1; i <= ni_agd_arm; ++i) {
                  current_statement__ = 206;
                  if (stan::model::rvalue(which_RE, "which_RE",
                        stan::model::index_uni((narm_ipd + i)))) {
                    current_statement__ = 205;
                    eta_agd_arm_RE = (stan::model::rvalue(eta_agd_arm_noRE,
                                        "eta_agd_arm_noRE",
                                        stan::model::index_uni(i))
                      +
                      stan::model::rvalue(f_delta, "f_delta",
                        stan::model::index_uni(
                          stan::model::rvalue(which_RE, "which_RE",
                            stan::model::index_uni((narm_ipd + i))))));
                  } else {
                    current_statement__ = 204;
                    eta_agd_arm_RE = stan::model::rvalue(eta_agd_arm_noRE,
                                       "eta_agd_arm_noRE",
                                       stan::model::index_uni(i));
                  }
                  current_statement__ = 209;
                  for (int k = 1; k <=
                       (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                          stan::model::index_uni(i)) - 1); ++k) {
                    current_statement__ = 207;
                    stan::model::assign(q_agd_arm_bar,
                      stan::math::Phi((eta_agd_arm_RE -
                        stan::model::rvalue(cc, "cc",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                               stan::model::index_uni(i),
                               stan::model::index_uni((k + 1))) - 1))))),
                      "assigning variable q_agd_arm_bar",
                      stan::model::index_uni(i), stan::model::index_uni(k));
                  }
                }
              } else {
                current_statement__ = 203;
                if (stan::math::logical_eq(link, 3)) {
                  current_statement__ = 201;
                  for (int i = 1; i <= ni_agd_arm; ++i) {
                    current_statement__ = 196;
                    if (stan::model::rvalue(which_RE, "which_RE",
                          stan::model::index_uni((narm_ipd + i)))) {
                      current_statement__ = 195;
                      eta_agd_arm_RE = (stan::model::rvalue(eta_agd_arm_noRE,
                                          "eta_agd_arm_noRE",
                                          stan::model::index_uni(i))
                        +
                        stan::model::rvalue(f_delta, "f_delta",
                          stan::model::index_uni(
                            stan::model::rvalue(which_RE, "which_RE",
                              stan::model::index_uni((narm_ipd + i))))));
                    } else {
                      current_statement__ = 194;
                      eta_agd_arm_RE = stan::model::rvalue(eta_agd_arm_noRE,
                                         "eta_agd_arm_noRE",
                                         stan::model::index_uni(i));
                    }
                    current_statement__ = 199;
                    for (int k = 1; k <=
                         (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                            stan::model::index_uni(i)) - 1); ++k) {
                      current_statement__ = 197;
                      stan::model::assign(q_agd_arm_bar,
                        stan::math::inv_cloglog((eta_agd_arm_RE -
                          stan::model::rvalue(cc, "cc",
                            stan::model::index_uni(
                              (stan::model::rvalue(agd_arm_cat,
                                 "agd_arm_cat", stan::model::index_uni(i),
                                 stan::model::index_uni((k + 1))) - 1))))),
                        "assigning variable q_agd_arm_bar",
                        stan::model::index_uni(i), stan::model::index_uni(k));
                    }
                  }
                }
              }
            }
          } else {
            current_statement__ = 163;
            if (class_effects) {
              current_statement__ = 161;
              for (int i = 1; i <= ni_agd_arm; ++i) {
                current_statement__ = 159;
                if ((stan::math::primitive_value(
                       stan::math::logical_gt(
                         stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                           stan::model::index_uni(i)), 1))
                    &&
                    stan::math::primitive_value(
                      stan::model::rvalue(which_CE, "which_CE",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                             stan::model::index_uni(i)) - 1)))))) {
                  current_statement__ = 157;
                  stan::model::assign(eta_agd_arm_noRE,
                    (stan::model::rvalue(eta_agd_arm_noRE,
                       "eta_agd_arm_noRE", stan::model::index_uni(i)) +
                    stan::model::rvalue(f_class, "f_class",
                      stan::model::index_uni(
                        stan::model::rvalue(which_fclass, "which_fclass",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_arm_trt, "agd_arm_trt",
                               stan::model::index_uni(i)) - 1)))))),
                    "assigning variable eta_agd_arm_noRE",
                    stan::model::index_uni(i));
                }
              }
            }
            current_statement__ = 184;
            if (stan::math::logical_eq(link, 1)) {
              current_statement__ = 182;
              for (int i = 1; i <= ni_agd_arm; ++i) {
                current_statement__ = 180;
                for (int k = 1; k <=
                     (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                        stan::model::index_uni(i)) - 1); ++k) {
                  current_statement__ = 178;
                  stan::model::assign(q_agd_arm_bar,
                    stan::math::inv_logit(
                      (stan::model::rvalue(eta_agd_arm_noRE,
                         "eta_agd_arm_noRE", stan::model::index_uni(i)) -
                      stan::model::rvalue(cc, "cc",
                        stan::model::index_uni(
                          (stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                             stan::model::index_uni(i),
                             stan::model::index_uni((k + 1))) - 1))))),
                    "assigning variable q_agd_arm_bar",
                    stan::model::index_uni(i), stan::model::index_uni(k));
                }
              }
            } else {
              current_statement__ = 177;
              if (stan::math::logical_eq(link, 2)) {
                current_statement__ = 175;
                for (int i = 1; i <= ni_agd_arm; ++i) {
                  current_statement__ = 173;
                  for (int k = 1; k <=
                       (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                          stan::model::index_uni(i)) - 1); ++k) {
                    current_statement__ = 171;
                    stan::model::assign(q_agd_arm_bar,
                      stan::math::Phi(
                        (stan::model::rvalue(eta_agd_arm_noRE,
                           "eta_agd_arm_noRE", stan::model::index_uni(i)) -
                        stan::model::rvalue(cc, "cc",
                          stan::model::index_uni(
                            (stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                               stan::model::index_uni(i),
                               stan::model::index_uni((k + 1))) - 1))))),
                      "assigning variable q_agd_arm_bar",
                      stan::model::index_uni(i), stan::model::index_uni(k));
                  }
                }
              } else {
                current_statement__ = 170;
                if (stan::math::logical_eq(link, 3)) {
                  current_statement__ = 168;
                  for (int i = 1; i <= ni_agd_arm; ++i) {
                    current_statement__ = 166;
                    for (int k = 1; k <=
                         (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                            stan::model::index_uni(i)) - 1); ++k) {
                      current_statement__ = 164;
                      stan::model::assign(q_agd_arm_bar,
                        stan::math::inv_cloglog(
                          (stan::model::rvalue(eta_agd_arm_noRE,
                             "eta_agd_arm_noRE", stan::model::index_uni(i)) -
                          stan::model::rvalue(cc, "cc",
                            stan::model::index_uni(
                              (stan::model::rvalue(agd_arm_cat,
                                 "agd_arm_cat", stan::model::index_uni(i),
                                 stan::model::index_uni((k + 1))) - 1))))),
                        "assigning variable q_agd_arm_bar",
                        stan::model::index_uni(i), stan::model::index_uni(k));
                    }
                  }
                }
              }
            }
          }
        }
        current_statement__ = 295;
        for (int i = 1; i <= ni_agd_arm; ++i) {
          current_statement__ = 290;
          stan::model::assign(theta_agd_arm_bar, (1 -
            stan::model::rvalue(q_agd_arm_bar, "q_agd_arm_bar",
              stan::model::index_uni(i), stan::model::index_uni(1))),
            "assigning variable theta_agd_arm_bar",
            stan::model::index_uni(i), stan::model::index_uni(1));
          current_statement__ = 292;
          for (int k = 2; k <=
               (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                  stan::model::index_uni(i)) - 1); ++k) {
            current_statement__ = 291;
            stan::model::assign(theta_agd_arm_bar,
              (stan::model::rvalue(q_agd_arm_bar, "q_agd_arm_bar",
                 stan::model::index_uni(i), stan::model::index_uni((k - 1)))
              -
              stan::model::rvalue(q_agd_arm_bar, "q_agd_arm_bar",
                stan::model::index_uni(i), stan::model::index_uni(k))),
              "assigning variable theta_agd_arm_bar",
              stan::model::index_uni(i),
              stan::model::index_uni(
                stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                  stan::model::index_uni(i), stan::model::index_uni(k))));
          }
          current_statement__ = 293;
          stan::model::assign(theta_agd_arm_bar,
            stan::model::rvalue(q_agd_arm_bar, "q_agd_arm_bar",
              stan::model::index_uni(i),
              stan::model::index_uni(
                (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                   stan::model::index_uni(i)) - 1))),
            "assigning variable theta_agd_arm_bar",
            stan::model::index_uni(i),
            stan::model::index_uni(
              stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                stan::model::index_uni(i),
                stan::model::index_uni(
                  stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                    stan::model::index_uni(i))))));
        }
      }
      if (emit_transformed_parameters__) {
        out__.write(cc);
        for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
          for (int sym2__ = 1; sym2__ <= ni_ipd; ++sym2__) {
            out__.write(theta_ipd[(sym2__ - 1)][(sym1__ - 1)]);
          }
        }
        out__.write(theta_agd_arm_ii);
        for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
          for (int sym2__ = 1; sym2__ <= ni_agd_arm; ++sym2__) {
            out__.write(q_agd_arm_bar[(sym2__ - 1)][(sym1__ - 1)]);
          }
        }
        for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
          for (int sym2__ = 1; sym2__ <= ni_agd_arm; ++sym2__) {
            out__.write(theta_agd_arm_bar[(sym2__ - 1)][(sym1__ - 1)]);
          }
        }
        out__.write(eta_ipd);
        out__.write(f_delta);
        out__.write(f_class);
        out__.write(allbeta);
        out__.write(mu);
        out__.write(d);
        out__.write(omega);
        out__.write(beta);
        out__.write(eta_agd_contrast_ii);
        out__.write(eta_agd_contrast_bar);
      }
      if (stan::math::logical_negation(emit_generated_quantities__)) {
        return ;
      }
      std::vector<Eigen::Matrix<double,-1,1>> fitted_ipd =
        std::vector<Eigen::Matrix<double,-1,1>>(ni_ipd,
          Eigen::Matrix<double,-1,1>::Constant(ncat,
            std::numeric_limits<double>::quiet_NaN()));
      std::vector<Eigen::Matrix<double,-1,1>> fitted_agd_arm =
        std::vector<Eigen::Matrix<double,-1,1>>(ni_agd_arm,
          Eigen::Matrix<double,-1,1>::Constant(ncat,
            std::numeric_limits<double>::quiet_NaN()));
      Eigen::Matrix<double,-1,-1> theta_bar_cum_agd_arm =
        Eigen::Matrix<double,-1,-1>::Constant(theta_bar_cum_agd_arm_1dim__,
          ncat, std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 25;
      stan::model::assign(theta_bar_cum_agd_arm,
        stan::math::rep_matrix(0, (ni_agd_arm * n_int_thin), ncat),
        "assigning variable theta_bar_cum_agd_arm");
      Eigen::Matrix<double,-1,1> log_lik =
        Eigen::Matrix<double,-1,1>::Constant(log_lik_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> resdev =
        Eigen::Matrix<double,-1,1>::Constant(resdev_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> fitted_agd_contrast =
        Eigen::Matrix<double,-1,1>::Constant(ni_agd_contrast,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> theta_bar_cum_agd_contrast =
        Eigen::Matrix<double,-1,1>::Constant(theta_bar_cum_agd_contrast_1dim__,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> delta =
        Eigen::Matrix<double,-1,1>::Constant(n_delta,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 314;
      if (RE) {
        int s = std::numeric_limits<int>::min();
        current_statement__ = 298;
        s = 1;
        current_statement__ = 304;
        for (int i = 1; i <= (narm_ipd + narm_agd_arm); ++i) {
          current_statement__ = 302;
          if (stan::model::rvalue(which_RE, "which_RE",
                stan::model::index_uni(i))) {
            current_statement__ = 299;
            stan::model::assign(delta,
              ((stan::math::logical_gt(
                  stan::model::rvalue(trt, "trt", stan::model::index_uni(i)),
                  1) ? stan::model::rvalue(d, "d",
                         stan::model::index_uni(
                           (stan::model::rvalue(trt, "trt",
                              stan::model::index_uni(i)) - 1))) : 0) +
              (stan::model::rvalue(which_RE, "which_RE",
                 stan::model::index_uni(i)) ? stan::model::rvalue(f_delta,
                                                "f_delta",
                                                stan::model::index_uni(
                                                  stan::model::rvalue(
                                                    which_RE, "which_RE",
                                                    stan::model::index_uni(i)))) : 0)),
              "assigning variable delta", stan::model::index_uni(s));
            current_statement__ = 300;
            s = (s + 1);
          }
        }
        current_statement__ = 312;
        for (int i = 1; i <= ni_agd_contrast; ++i) {
          current_statement__ = 310;
          if (stan::model::rvalue(which_RE, "which_RE",
                stan::model::index_uni(((narm_ipd + narm_agd_arm) + i)))) {
            current_statement__ = 305;
            stan::model::assign(delta,
              ((stan::math::logical_gt(
                  stan::model::rvalue(trt, "trt",
                    stan::model::index_uni(((narm_ipd + narm_agd_arm) + i))),
                  1) ? stan::model::rvalue(d, "d",
                         stan::model::index_uni(
                           (stan::model::rvalue(trt, "trt",
                              stan::model::index_uni(((narm_ipd +
                                narm_agd_arm) + i))) - 1))) : 0) +
              (stan::model::rvalue(which_RE, "which_RE",
                 stan::model::index_uni(((narm_ipd + narm_agd_arm) + i))) ? 
              stan::model::rvalue(f_delta, "f_delta",
                stan::model::index_uni(
                  stan::model::rvalue(which_RE, "which_RE",
                    stan::model::index_uni(((narm_ipd + narm_agd_arm) + i))))) : 0)),
              "assigning variable delta", stan::model::index_uni(s));
            current_statement__ = 307;
            if (stan::math::logical_gt(
                  stan::model::rvalue(agd_contrast_trt_b,
                    "agd_contrast_trt_b", stan::model::index_uni(i)), 1)) {
              current_statement__ = 306;
              stan::model::assign(delta,
                (stan::model::rvalue(delta, "delta",
                   stan::model::index_uni(s)) -
                stan::model::rvalue(d, "d",
                  stan::model::index_uni(
                    (stan::model::rvalue(agd_contrast_trt_b,
                       "agd_contrast_trt_b", stan::model::index_uni(i)) - 1)))),
                "assigning variable delta", stan::model::index_uni(s));
            }
            current_statement__ = 308;
            s = (s + 1);
          }
        }
      }
      current_statement__ = 319;
      for (int i = 1; i <= ni_agd_contrast; ++i) {
        current_statement__ = 317;
        for (int j = 1; j <= n_int_thin; ++j) {
          current_statement__ = 315;
          stan::model::assign(theta_bar_cum_agd_contrast,
            stan::math::mean(
              stan::model::rvalue(eta_agd_contrast_ii, "eta_agd_contrast_ii",
                stan::model::index_min_max((1 + ((i - 1) * nint)), (((i - 1)
                  * nint) + (j * int_thin))))),
            "assigning variable theta_bar_cum_agd_contrast",
            stan::model::index_uni((((i - 1) * n_int_thin) + j)));
        }
      }
      current_statement__ = 320;
      stan::model::assign(fitted_agd_contrast, eta_agd_contrast_bar,
        "assigning variable fitted_agd_contrast");
      {
        int a = std::numeric_limits<int>::min();
        current_statement__ = 321;
        a = 0;
        int nc = std::numeric_limits<int>::min();
        current_statement__ = 328;
        for (int s = 1; s <= ns_agd_contrast; ++s) {
          current_statement__ = 323;
          nc = stan::model::rvalue(nc_agd_contrast, "nc_agd_contrast",
                 stan::model::index_uni(s));
          current_statement__ = 324;
          stan::model::assign(log_lik,
            stan::math::multi_normal_lpdf<false>(
              stan::model::rvalue(agd_contrast_y, "agd_contrast_y",
                stan::model::index_min_max((a + 1), (a + nc))),
              stan::model::rvalue(eta_agd_contrast_bar,
                "eta_agd_contrast_bar",
                stan::model::index_min_max((a + 1), (a + nc))),
              stan::model::rvalue(agd_contrast_Sigma, "agd_contrast_Sigma",
                stan::model::index_min_max((a + 1), (a + nc)),
                stan::model::index_min_max((a + 1), (a + nc)))),
            "assigning variable log_lik",
            stan::model::index_uni(((ni_ipd + ni_agd_arm) + s)));
          current_statement__ = 325;
          stan::model::assign(resdev,
            stan::math::quad_form(
              stan::model::rvalue(inv_Sigma, "inv_Sigma",
                stan::model::index_min_max((a + 1), (a + nc)),
                stan::model::index_min_max((a + 1), (a + nc))),
              stan::math::subtract(
                stan::model::rvalue(agd_contrast_y, "agd_contrast_y",
                  stan::model::index_min_max((a + 1), (a + nc))),
                stan::model::rvalue(eta_agd_contrast_bar,
                  "eta_agd_contrast_bar",
                  stan::model::index_min_max((a + 1), (a + nc))))),
            "assigning variable resdev",
            stan::model::index_uni(((ni_ipd + ni_agd_arm) + s)));
          current_statement__ = 326;
          a = (a + nc);
        }
      }
      current_statement__ = 334;
      for (int i = 1; i <= ni_ipd; ++i) {
        current_statement__ = 330;
        stan::model::assign(log_lik,
          stan::math::categorical_lpmf<false>(
            stan::model::rvalue(ipd_r, "ipd_r", stan::model::index_uni(i)),
            stan::model::rvalue(theta_ipd, "theta_ipd",
              stan::model::index_uni(i))), "assigning variable log_lik",
          stan::model::index_uni(i));
        current_statement__ = 331;
        stan::model::assign(resdev, (-2 *
          stan::model::rvalue(log_lik, "log_lik", stan::model::index_uni(i))),
          "assigning variable resdev", stan::model::index_uni(i));
        current_statement__ = 332;
        stan::model::assign(fitted_ipd,
          stan::model::rvalue(theta_ipd, "theta_ipd",
            stan::model::index_uni(i)), "assigning variable fitted_ipd",
          stan::model::index_uni(i));
      }
      {
        current_statement__ = 335;
        stan::math::validate_non_negative_index("dv", "ni_agd_arm",
          ni_agd_arm);
        current_statement__ = 336;
        stan::math::validate_non_negative_index("dv", "ncat", ncat);
        std::vector<Eigen::Matrix<double,-1,1>> dv =
          std::vector<Eigen::Matrix<double,-1,1>>(ni_agd_arm,
            Eigen::Matrix<double,-1,1>::Constant(ncat,
              std::numeric_limits<double>::quiet_NaN()));
        current_statement__ = 345;
        for (int i = 1; i <= ni_agd_arm; ++i) {
          current_statement__ = 338;
          stan::model::assign(log_lik,
            stan::math::multinomial_lpmf<false>(
              stan::model::rvalue(agd_arm_r, "agd_arm_r",
                stan::model::index_uni(i)),
              stan::model::rvalue(theta_agd_arm_bar, "theta_agd_arm_bar",
                stan::model::index_uni(i))), "assigning variable log_lik",
            stan::model::index_uni((ni_ipd + i)));
          current_statement__ = 339;
          stan::model::assign(fitted_agd_arm,
            stan::math::multiply(
              stan::model::rvalue(agd_arm_n, "agd_arm_n",
                stan::model::index_uni(i)),
              stan::model::rvalue(theta_agd_arm_bar, "theta_agd_arm_bar",
                stan::model::index_uni(i))),
            "assigning variable fitted_agd_arm", stan::model::index_uni(i));
          current_statement__ = 342;
          for (int k = 1; k <=
               stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                 stan::model::index_uni(i)); ++k) {
            current_statement__ = 340;
            stan::model::assign(dv,
              (stan::math::logical_eq(
                 stan::model::rvalue(agd_arm_r, "agd_arm_r",
                   stan::model::index_uni(i),
                   stan::model::index_uni(
                     stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                       stan::model::index_uni(i), stan::model::index_uni(k)))),
                 0) ? 0 : stan::math::multiply_log(
                            stan::model::rvalue(agd_arm_r, "agd_arm_r",
                              stan::model::index_uni(i),
                              stan::model::index_uni(
                                stan::model::rvalue(agd_arm_cat,
                                  "agd_arm_cat", stan::model::index_uni(i),
                                  stan::model::index_uni(k)))),
                            (stan::model::rvalue(agd_arm_r, "agd_arm_r",
                               stan::model::index_uni(i),
                               stan::model::index_uni(
                                 stan::model::rvalue(agd_arm_cat,
                                   "agd_arm_cat", stan::model::index_uni(i),
                                   stan::model::index_uni(k)))) /
                            stan::model::rvalue(fitted_agd_arm,
                              "fitted_agd_arm", stan::model::index_uni(i),
                              stan::model::index_uni(
                                stan::model::rvalue(agd_arm_cat,
                                  "agd_arm_cat", stan::model::index_uni(i),
                                  stan::model::index_uni(k))))))),
              "assigning variable dv", stan::model::index_uni(i),
              stan::model::index_uni(k));
          }
          current_statement__ = 343;
          stan::model::assign(resdev, (2 *
            stan::math::sum(
              stan::model::rvalue(dv, "dv", stan::model::index_uni(i),
                stan::model::index_min_max(1,
                  stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                    stan::model::index_uni(i)))))),
            "assigning variable resdev", stan::model::index_uni((ni_ipd + i)));
        }
      }
      current_statement__ = 358;
      for (int i = 1; i <= ni_agd_arm; ++i) {
        current_statement__ = 356;
        for (int j = 1; j <= n_int_thin; ++j) {
          current_statement__ = 347;
          stan::math::validate_non_negative_index("q_agd_arm_bar_cum",
            "ncat - 1", (ncat - 1));
          Eigen::Matrix<double,-1,1> q_agd_arm_bar_cum =
            Eigen::Matrix<double,-1,1>::Constant((ncat - 1),
              std::numeric_limits<double>::quiet_NaN());
          current_statement__ = 350;
          for (int k = 1; k <=
               (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                  stan::model::index_uni(i)) - 1); ++k) {
            current_statement__ = 349;
            stan::model::assign(q_agd_arm_bar_cum,
              stan::math::mean(
                stan::model::rvalue(theta_agd_arm_ii, "theta_agd_arm_ii",
                  stan::model::index_min_max((1 + ((i - 1) * nint)), (((i -
                    1) * nint) + (j * int_thin))), stan::model::index_uni(k))),
              "assigning variable q_agd_arm_bar_cum",
              stan::model::index_uni(k));
          }
          current_statement__ = 351;
          stan::model::assign(theta_bar_cum_agd_arm, (1 -
            stan::model::rvalue(q_agd_arm_bar_cum, "q_agd_arm_bar_cum",
              stan::model::index_uni(1))),
            "assigning variable theta_bar_cum_agd_arm",
            stan::model::index_uni((((i - 1) * n_int_thin) + j)),
            stan::model::index_uni(1));
          current_statement__ = 353;
          for (int k = 2; k <=
               (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                  stan::model::index_uni(i)) - 1); ++k) {
            current_statement__ = 352;
            stan::model::assign(theta_bar_cum_agd_arm,
              (stan::model::rvalue(q_agd_arm_bar_cum, "q_agd_arm_bar_cum",
                 stan::model::index_uni((k - 1))) -
              stan::model::rvalue(q_agd_arm_bar_cum, "q_agd_arm_bar_cum",
                stan::model::index_uni(k))),
              "assigning variable theta_bar_cum_agd_arm",
              stan::model::index_uni((((i - 1) * n_int_thin) + j)),
              stan::model::index_uni(
                stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                  stan::model::index_uni(i), stan::model::index_uni(k))));
          }
          current_statement__ = 354;
          stan::model::assign(theta_bar_cum_agd_arm,
            stan::model::rvalue(q_agd_arm_bar_cum, "q_agd_arm_bar_cum",
              stan::model::index_uni(
                (stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                   stan::model::index_uni(i)) - 1))),
            "assigning variable theta_bar_cum_agd_arm",
            stan::model::index_uni((((i - 1) * n_int_thin) + j)),
            stan::model::index_uni(
              stan::model::rvalue(agd_arm_cat, "agd_arm_cat",
                stan::model::index_uni(i),
                stan::model::index_uni(
                  stan::model::rvalue(agd_arm_ncat, "agd_arm_ncat",
                    stan::model::index_uni(i))))));
        }
      }
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= ni_ipd; ++sym2__) {
          out__.write(fitted_ipd[(sym2__ - 1)][(sym1__ - 1)]);
        }
      }
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= ni_agd_arm; ++sym2__) {
          out__.write(fitted_agd_arm[(sym2__ - 1)][(sym1__ - 1)]);
        }
      }
      out__.write(theta_bar_cum_agd_arm);
      out__.write(log_lik);
      out__.write(resdev);
      out__.write(fitted_agd_contrast);
      out__.write(theta_bar_cum_agd_contrast);
      out__.write(delta);
    } 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;
      Eigen::Matrix<local_scalar_t__,-1,1> beta_tilde =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nX, DUMMY_VAR__);
      current_statement__ = 1;
      stan::model::assign(beta_tilde,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(nX),
        "assigning variable beta_tilde");
      out__.write(beta_tilde);
      Eigen::Matrix<local_scalar_t__,-1,1> u_delta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_delta, DUMMY_VAR__);
      current_statement__ = 2;
      stan::model::assign(u_delta,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(n_delta),
        "assigning variable u_delta");
      out__.write(u_delta);
      Eigen::Matrix<local_scalar_t__,-1,1> tau =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(tau_1dim__,
          DUMMY_VAR__);
      current_statement__ = 3;
      stan::model::assign(tau,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(tau_1dim__),
        "assigning variable tau");
      out__.write_free_lb(0, tau);
      Eigen::Matrix<local_scalar_t__,-1,1> class_mean =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(class_mean_1dim__,
          DUMMY_VAR__);
      current_statement__ = 4;
      stan::model::assign(class_mean,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(class_mean_1dim__),
        "assigning variable class_mean");
      out__.write(class_mean);
      Eigen::Matrix<local_scalar_t__,-1,1> class_sd =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(class_sd_1dim__,
          DUMMY_VAR__);
      current_statement__ = 5;
      stan::model::assign(class_sd,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(class_sd_1dim__),
        "assigning variable class_sd");
      out__.write_free_lb(0, class_sd);
      Eigen::Matrix<local_scalar_t__,-1,1> z_class =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(z_class_1dim__,
          DUMMY_VAR__);
      current_statement__ = 6;
      stan::model::assign(z_class,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(z_class_1dim__),
        "assigning variable z_class");
      out__.write(z_class);
      Eigen::Matrix<local_scalar_t__,-1,1> f_cc =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(f_cc_1dim__,
          DUMMY_VAR__);
      current_statement__ = 7;
      stan::model::assign(f_cc,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(f_cc_1dim__),
        "assigning variable f_cc");
      out__.write_free_positive_ordered(f_cc);
    } 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", "beta_tilde",
        "double", std::vector<size_t>{static_cast<size_t>(nX)});
      current_statement__ = 2;
      context__.validate_dims("parameter initialization", "u_delta",
        "double", std::vector<size_t>{static_cast<size_t>(n_delta)});
      current_statement__ = 3;
      context__.validate_dims("parameter initialization", "tau", "double",
        std::vector<size_t>{static_cast<size_t>(tau_1dim__)});
      current_statement__ = 4;
      context__.validate_dims("parameter initialization", "class_mean",
        "double",
        std::vector<size_t>{static_cast<size_t>(class_mean_1dim__)});
      current_statement__ = 5;
      context__.validate_dims("parameter initialization", "class_sd",
        "double", std::vector<size_t>{static_cast<size_t>(class_sd_1dim__)});
      current_statement__ = 6;
      context__.validate_dims("parameter initialization", "z_class",
        "double", std::vector<size_t>{static_cast<size_t>(z_class_1dim__)});
      current_statement__ = 7;
      context__.validate_dims("parameter initialization", "f_cc", "double",
        std::vector<size_t>{static_cast<size_t>(f_cc_1dim__)});
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      Eigen::Matrix<local_scalar_t__,-1,1> beta_tilde =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(nX, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> beta_tilde_flat__;
        current_statement__ = 1;
        beta_tilde_flat__ = context__.vals_r("beta_tilde");
        current_statement__ = 1;
        pos__ = 1;
        current_statement__ = 1;
        for (int sym1__ = 1; sym1__ <= nX; ++sym1__) {
          current_statement__ = 1;
          stan::model::assign(beta_tilde, beta_tilde_flat__[(pos__ - 1)],
            "assigning variable beta_tilde", stan::model::index_uni(sym1__));
          current_statement__ = 1;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(beta_tilde);
      Eigen::Matrix<local_scalar_t__,-1,1> u_delta =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(n_delta, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> u_delta_flat__;
        current_statement__ = 2;
        u_delta_flat__ = context__.vals_r("u_delta");
        current_statement__ = 2;
        pos__ = 1;
        current_statement__ = 2;
        for (int sym1__ = 1; sym1__ <= n_delta; ++sym1__) {
          current_statement__ = 2;
          stan::model::assign(u_delta, u_delta_flat__[(pos__ - 1)],
            "assigning variable u_delta", stan::model::index_uni(sym1__));
          current_statement__ = 2;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(u_delta);
      Eigen::Matrix<local_scalar_t__,-1,1> tau =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(tau_1dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> tau_flat__;
        current_statement__ = 3;
        tau_flat__ = context__.vals_r("tau");
        current_statement__ = 3;
        pos__ = 1;
        current_statement__ = 3;
        for (int sym1__ = 1; sym1__ <= tau_1dim__; ++sym1__) {
          current_statement__ = 3;
          stan::model::assign(tau, tau_flat__[(pos__ - 1)],
            "assigning variable tau", stan::model::index_uni(sym1__));
          current_statement__ = 3;
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_lb(0, tau);
      Eigen::Matrix<local_scalar_t__,-1,1> class_mean =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(class_mean_1dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> class_mean_flat__;
        current_statement__ = 4;
        class_mean_flat__ = context__.vals_r("class_mean");
        current_statement__ = 4;
        pos__ = 1;
        current_statement__ = 4;
        for (int sym1__ = 1; sym1__ <= class_mean_1dim__; ++sym1__) {
          current_statement__ = 4;
          stan::model::assign(class_mean, class_mean_flat__[(pos__ - 1)],
            "assigning variable class_mean", stan::model::index_uni(sym1__));
          current_statement__ = 4;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(class_mean);
      Eigen::Matrix<local_scalar_t__,-1,1> class_sd =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(class_sd_1dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> class_sd_flat__;
        current_statement__ = 5;
        class_sd_flat__ = context__.vals_r("class_sd");
        current_statement__ = 5;
        pos__ = 1;
        current_statement__ = 5;
        for (int sym1__ = 1; sym1__ <= class_sd_1dim__; ++sym1__) {
          current_statement__ = 5;
          stan::model::assign(class_sd, class_sd_flat__[(pos__ - 1)],
            "assigning variable class_sd", stan::model::index_uni(sym1__));
          current_statement__ = 5;
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_lb(0, class_sd);
      Eigen::Matrix<local_scalar_t__,-1,1> z_class =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(z_class_1dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> z_class_flat__;
        current_statement__ = 6;
        z_class_flat__ = context__.vals_r("z_class");
        current_statement__ = 6;
        pos__ = 1;
        current_statement__ = 6;
        for (int sym1__ = 1; sym1__ <= z_class_1dim__; ++sym1__) {
          current_statement__ = 6;
          stan::model::assign(z_class, z_class_flat__[(pos__ - 1)],
            "assigning variable z_class", stan::model::index_uni(sym1__));
          current_statement__ = 6;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(z_class);
      Eigen::Matrix<local_scalar_t__,-1,1> f_cc =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(f_cc_1dim__,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> f_cc_flat__;
        current_statement__ = 7;
        f_cc_flat__ = context__.vals_r("f_cc");
        current_statement__ = 7;
        pos__ = 1;
        current_statement__ = 7;
        for (int sym1__ = 1; sym1__ <= f_cc_1dim__; ++sym1__) {
          current_statement__ = 7;
          stan::model::assign(f_cc, f_cc_flat__[(pos__ - 1)],
            "assigning variable f_cc", stan::model::index_uni(sym1__));
          current_statement__ = 7;
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_positive_ordered(f_cc);
    } 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>{"beta_tilde", "u_delta", "tau",
                "class_mean", "class_sd", "z_class", "f_cc"};
    if (emit_transformed_parameters__) {
      std::vector<std::string>
        temp{"cc", "theta_ipd", "theta_agd_arm_ii", "q_agd_arm_bar",
             "theta_agd_arm_bar", "eta_ipd", "f_delta", "f_class", "allbeta",
             "mu", "d", "omega", "beta", "eta_agd_contrast_ii",
             "eta_agd_contrast_bar"};
      names__.reserve(names__.size() + temp.size());
      names__.insert(names__.end(), temp.begin(), temp.end());
    }
    if (emit_generated_quantities__) {
      std::vector<std::string>
        temp{"fitted_ipd", "fitted_agd_arm", "theta_bar_cum_agd_arm",
             "log_lik", "resdev", "fitted_agd_contrast",
             "theta_bar_cum_agd_contrast", "delta"};
      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>(
                                                                    nX)},
                std::vector<size_t>{static_cast<size_t>(n_delta)},
                std::vector<size_t>{static_cast<size_t>(tau_1dim__)},
                std::vector<size_t>{static_cast<size_t>(class_mean_1dim__)},
                std::vector<size_t>{static_cast<size_t>(class_sd_1dim__)},
                std::vector<size_t>{static_cast<size_t>(z_class_1dim__)},
                std::vector<size_t>{static_cast<size_t>(f_cc_1dim__)}};
    if (emit_transformed_parameters__) {
      std::vector<std::vector<size_t>>
        temp{std::vector<size_t>{static_cast<size_t>(cc_1dim__)},
             std::vector<size_t>{static_cast<size_t>(ni_ipd),
               static_cast<size_t>(ncat)},
             std::vector<size_t>{static_cast<size_t>(theta_agd_arm_ii_1dim__),
               static_cast<size_t>(theta_agd_arm_ii_2dim__)},
             std::vector<size_t>{static_cast<size_t>(ni_agd_arm),
               static_cast<size_t>(ncat)},
             std::vector<size_t>{static_cast<size_t>(ni_agd_arm),
               static_cast<size_t>(ncat)},
             std::vector<size_t>{static_cast<size_t>(ni_ipd)},
             std::vector<size_t>{static_cast<size_t>(n_delta)},
             std::vector<size_t>{static_cast<size_t>(f_class_1dim__)},
             std::vector<size_t>{static_cast<size_t>(nX)},
             std::vector<size_t>{static_cast<size_t>(totns)},
             std::vector<size_t>{static_cast<size_t>(d_1dim__)},
             std::vector<size_t>{static_cast<size_t>(nodesplit)},
             std::vector<size_t>{static_cast<size_t>(beta_1dim__)},
             std::vector<size_t>{static_cast<size_t>(
                                   eta_agd_contrast_ii_1dim__)},
             std::vector<size_t>{static_cast<size_t>(ni_agd_contrast)}};
      dimss__.reserve(dimss__.size() + temp.size());
      dimss__.insert(dimss__.end(), temp.begin(), temp.end());
    }
    if (emit_generated_quantities__) {
      std::vector<std::vector<size_t>>
        temp{std::vector<size_t>{static_cast<size_t>(ni_ipd),
               static_cast<size_t>(ncat)},
             std::vector<size_t>{static_cast<size_t>(ni_agd_arm),
               static_cast<size_t>(ncat)},
             std::vector<size_t>{static_cast<size_t>(
                                   theta_bar_cum_agd_arm_1dim__),
               static_cast<size_t>(ncat)},
             std::vector<size_t>{static_cast<size_t>(log_lik_1dim__)},
             std::vector<size_t>{static_cast<size_t>(resdev_1dim__)},
             std::vector<size_t>{static_cast<size_t>(ni_agd_contrast)},
             std::vector<size_t>{static_cast<size_t>(
                                   theta_bar_cum_agd_contrast_1dim__)},
             std::vector<size_t>{static_cast<size_t>(n_delta)}};
      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__ <= nX; ++sym1__) {
      param_names__.emplace_back(std::string() + "beta_tilde" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= n_delta; ++sym1__) {
      param_names__.emplace_back(std::string() + "u_delta" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= tau_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "tau" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= class_mean_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "class_mean" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= class_sd_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "class_sd" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= z_class_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "z_class" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= f_cc_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "f_cc" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= cc_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "cc" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= ni_ipd; ++sym2__) {
          param_names__.emplace_back(std::string() + "theta_ipd" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= theta_agd_arm_ii_2dim__; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= theta_agd_arm_ii_1dim__; ++sym2__) {
          param_names__.emplace_back(std::string() + "theta_agd_arm_ii" + '.'
            + std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= ni_agd_arm; ++sym2__) {
          param_names__.emplace_back(std::string() + "q_agd_arm_bar" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= ni_agd_arm; ++sym2__) {
          param_names__.emplace_back(std::string() + "theta_agd_arm_bar" +
            '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= ni_ipd; ++sym1__) {
        param_names__.emplace_back(std::string() + "eta_ipd" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= n_delta; ++sym1__) {
        param_names__.emplace_back(std::string() + "f_delta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= f_class_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "f_class" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= nX; ++sym1__) {
        param_names__.emplace_back(std::string() + "allbeta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= totns; ++sym1__) {
        param_names__.emplace_back(std::string() + "mu" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= d_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "d" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= nodesplit; ++sym1__) {
        param_names__.emplace_back(std::string() + "omega" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= beta_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "beta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= eta_agd_contrast_ii_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "eta_agd_contrast_ii" +
          '.' + std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= ni_agd_contrast; ++sym1__) {
        param_names__.emplace_back(std::string() + "eta_agd_contrast_bar" +
          '.' + std::to_string(sym1__));
      }
    }
    if (emit_generated_quantities__) {
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= ni_ipd; ++sym2__) {
          param_names__.emplace_back(std::string() + "fitted_ipd" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= ni_agd_arm; ++sym2__) {
          param_names__.emplace_back(std::string() + "fitted_agd_arm" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= theta_bar_cum_agd_arm_1dim__; ++sym2__) {
          param_names__.emplace_back(std::string() + "theta_bar_cum_agd_arm"
            + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_lik" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= resdev_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "resdev" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= ni_agd_contrast; ++sym1__) {
        param_names__.emplace_back(std::string() + "fitted_agd_contrast" +
          '.' + std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <=
           theta_bar_cum_agd_contrast_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() +
          "theta_bar_cum_agd_contrast" + '.' + std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= n_delta; ++sym1__) {
        param_names__.emplace_back(std::string() + "delta" + '.' +
          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__ <= nX; ++sym1__) {
      param_names__.emplace_back(std::string() + "beta_tilde" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= n_delta; ++sym1__) {
      param_names__.emplace_back(std::string() + "u_delta" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= tau_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "tau" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= class_mean_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "class_mean" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= class_sd_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "class_sd" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= z_class_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "z_class" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= f_cc_1dim__; ++sym1__) {
      param_names__.emplace_back(std::string() + "f_cc" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= cc_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "cc" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= ni_ipd; ++sym2__) {
          param_names__.emplace_back(std::string() + "theta_ipd" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= theta_agd_arm_ii_2dim__; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= theta_agd_arm_ii_1dim__; ++sym2__) {
          param_names__.emplace_back(std::string() + "theta_agd_arm_ii" + '.'
            + std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= ni_agd_arm; ++sym2__) {
          param_names__.emplace_back(std::string() + "q_agd_arm_bar" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= ni_agd_arm; ++sym2__) {
          param_names__.emplace_back(std::string() + "theta_agd_arm_bar" +
            '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= ni_ipd; ++sym1__) {
        param_names__.emplace_back(std::string() + "eta_ipd" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= n_delta; ++sym1__) {
        param_names__.emplace_back(std::string() + "f_delta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= f_class_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "f_class" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= nX; ++sym1__) {
        param_names__.emplace_back(std::string() + "allbeta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= totns; ++sym1__) {
        param_names__.emplace_back(std::string() + "mu" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= d_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "d" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= nodesplit; ++sym1__) {
        param_names__.emplace_back(std::string() + "omega" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= beta_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "beta" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= eta_agd_contrast_ii_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "eta_agd_contrast_ii" +
          '.' + std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= ni_agd_contrast; ++sym1__) {
        param_names__.emplace_back(std::string() + "eta_agd_contrast_bar" +
          '.' + std::to_string(sym1__));
      }
    }
    if (emit_generated_quantities__) {
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= ni_ipd; ++sym2__) {
          param_names__.emplace_back(std::string() + "fitted_ipd" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= ni_agd_arm; ++sym2__) {
          param_names__.emplace_back(std::string() + "fitted_agd_arm" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= ncat; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= theta_bar_cum_agd_arm_1dim__; ++sym2__) {
          param_names__.emplace_back(std::string() + "theta_bar_cum_agd_arm"
            + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_lik" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= resdev_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() + "resdev" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= ni_agd_contrast; ++sym1__) {
        param_names__.emplace_back(std::string() + "fitted_agd_contrast" +
          '.' + std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <=
           theta_bar_cum_agd_contrast_1dim__; ++sym1__) {
        param_names__.emplace_back(std::string() +
          "theta_bar_cum_agd_contrast" + '.' + std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= n_delta; ++sym1__) {
        param_names__.emplace_back(std::string() + "delta" + '.' +
          std::to_string(sym1__));
      }
    }
  }
  inline std::string get_constrained_sizedtypes() const {
    return std::string("[{\"name\":\"beta_tilde\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nX) + "},\"block\":\"parameters\"},{\"name\":\"u_delta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_delta) + "},\"block\":\"parameters\"},{\"name\":\"tau\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(tau_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"class_mean\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(class_mean_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"class_sd\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(class_sd_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"z_class\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(z_class_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"f_cc\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(f_cc_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"cc\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(cc_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"theta_ipd\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(ni_ipd) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(ncat) + "}},\"block\":\"transformed_parameters\"},{\"name\":\"theta_agd_arm_ii\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(theta_agd_arm_ii_1dim__) + ",\"cols\":" + std::to_string(theta_agd_arm_ii_2dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q_agd_arm_bar\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(ni_agd_arm) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(ncat) + "}},\"block\":\"transformed_parameters\"},{\"name\":\"theta_agd_arm_bar\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(ni_agd_arm) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(ncat) + "}},\"block\":\"transformed_parameters\"},{\"name\":\"eta_ipd\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(ni_ipd) + "},\"block\":\"transformed_parameters\"},{\"name\":\"f_delta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_delta) + "},\"block\":\"transformed_parameters\"},{\"name\":\"f_class\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(f_class_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"allbeta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nX) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(totns) + "},\"block\":\"transformed_parameters\"},{\"name\":\"d\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(d_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"omega\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nodesplit) + "},\"block\":\"transformed_parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(beta_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"eta_agd_contrast_ii\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(eta_agd_contrast_ii_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"eta_agd_contrast_bar\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(ni_agd_contrast) + "},\"block\":\"transformed_parameters\"},{\"name\":\"fitted_ipd\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(ni_ipd) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(ncat) + "}},\"block\":\"generated_quantities\"},{\"name\":\"fitted_agd_arm\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(ni_agd_arm) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(ncat) + "}},\"block\":\"generated_quantities\"},{\"name\":\"theta_bar_cum_agd_arm\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(theta_bar_cum_agd_arm_1dim__) + ",\"cols\":" + std::to_string(ncat) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"resdev\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(resdev_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"fitted_agd_contrast\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(ni_agd_contrast) + "},\"block\":\"generated_quantities\"},{\"name\":\"theta_bar_cum_agd_contrast\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(theta_bar_cum_agd_contrast_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"delta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_delta) + "},\"block\":\"generated_quantities\"}]");
  }
  inline std::string get_unconstrained_sizedtypes() const {
    return std::string("[{\"name\":\"beta_tilde\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nX) + "},\"block\":\"parameters\"},{\"name\":\"u_delta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_delta) + "},\"block\":\"parameters\"},{\"name\":\"tau\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(tau_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"class_mean\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(class_mean_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"class_sd\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(class_sd_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"z_class\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(z_class_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"f_cc\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(f_cc_1dim__) + "},\"block\":\"parameters\"},{\"name\":\"cc\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(cc_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"theta_ipd\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(ni_ipd) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(ncat) + "}},\"block\":\"transformed_parameters\"},{\"name\":\"theta_agd_arm_ii\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(theta_agd_arm_ii_1dim__) + ",\"cols\":" + std::to_string(theta_agd_arm_ii_2dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q_agd_arm_bar\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(ni_agd_arm) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(ncat) + "}},\"block\":\"transformed_parameters\"},{\"name\":\"theta_agd_arm_bar\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(ni_agd_arm) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(ncat) + "}},\"block\":\"transformed_parameters\"},{\"name\":\"eta_ipd\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(ni_ipd) + "},\"block\":\"transformed_parameters\"},{\"name\":\"f_delta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_delta) + "},\"block\":\"transformed_parameters\"},{\"name\":\"f_class\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(f_class_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"allbeta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nX) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(totns) + "},\"block\":\"transformed_parameters\"},{\"name\":\"d\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(d_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"omega\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nodesplit) + "},\"block\":\"transformed_parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(beta_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"eta_agd_contrast_ii\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(eta_agd_contrast_ii_1dim__) + "},\"block\":\"transformed_parameters\"},{\"name\":\"eta_agd_contrast_bar\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(ni_agd_contrast) + "},\"block\":\"transformed_parameters\"},{\"name\":\"fitted_ipd\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(ni_ipd) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(ncat) + "}},\"block\":\"generated_quantities\"},{\"name\":\"fitted_agd_arm\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(ni_agd_arm) + ",\"element_type\":{\"name\":\"vector\",\"length\":" + std::to_string(ncat) + "}},\"block\":\"generated_quantities\"},{\"name\":\"theta_bar_cum_agd_arm\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(theta_bar_cum_agd_arm_1dim__) + ",\"cols\":" + std::to_string(ncat) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"resdev\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(resdev_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"fitted_agd_contrast\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(ni_agd_contrast) + "},\"block\":\"generated_quantities\"},{\"name\":\"theta_bar_cum_agd_contrast\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(theta_bar_cum_agd_contrast_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"delta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(n_delta) + "},\"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__ = ((((((nX + n_delta) + tau_1dim__) +
      class_mean_1dim__) + class_sd_1dim__) + z_class_1dim__) + f_cc_1dim__);
    const size_t num_transformed = emit_transformed_parameters *
      (((((((((((((((cc_1dim__ + (ni_ipd * ncat)) + (theta_agd_arm_ii_1dim__
      * theta_agd_arm_ii_2dim__)) + (ni_agd_arm * ncat)) + (ni_agd_arm *
      ncat)) + ni_ipd) + n_delta) + f_class_1dim__) + nX) + totns) +
      d_1dim__) + nodesplit) + beta_1dim__) + eta_agd_contrast_ii_1dim__) +
      ni_agd_contrast));
    const size_t num_gen_quantities = emit_generated_quantities *
      (((((((((ni_ipd * ncat) + (ni_agd_arm * ncat)) +
      (theta_bar_cum_agd_arm_1dim__ * ncat)) + log_lik_1dim__) +
      resdev_1dim__) + ni_agd_contrast) + theta_bar_cum_agd_contrast_1dim__)
      + n_delta));
    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__ = ((((((nX + n_delta) + tau_1dim__) +
      class_mean_1dim__) + class_sd_1dim__) + z_class_1dim__) + f_cc_1dim__);
    const size_t num_transformed = emit_transformed_parameters *
      (((((((((((((((cc_1dim__ + (ni_ipd * ncat)) + (theta_agd_arm_ii_1dim__
      * theta_agd_arm_ii_2dim__)) + (ni_agd_arm * ncat)) + (ni_agd_arm *
      ncat)) + ni_ipd) + n_delta) + f_class_1dim__) + nX) + totns) +
      d_1dim__) + nodesplit) + beta_1dim__) + eta_agd_contrast_ii_1dim__) +
      ni_agd_contrast));
    const size_t num_gen_quantities = emit_generated_quantities *
      (((((((((ni_ipd * ncat) + (ni_agd_arm * ncat)) +
      (theta_bar_cum_agd_arm_1dim__ * ncat)) + log_lik_1dim__) +
      resdev_1dim__) + ni_agd_contrast) + theta_bar_cum_agd_contrast_1dim__)
      + n_delta));
    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_ordered_multinomial_namespace::model_ordered_multinomial;
#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_ordered_multinomial_namespace::profiles__;
}
#endif
#endif
