Running ‘testthat.R’ [209s/210s]
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
  > # Part of the rstanarm package for estimating model parameters
  > # Copyright (C) 2015 Trustees of Columbia University
  > # 
  > # This program 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.
  > # 
  > # This program 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 this program; if not, write to the Free Software
  > # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  > 
  > library(testthat)
  > library(rstanarm)
  Loading required package: Rcpp
  rstanarm (Version 2.15.3, packaged: 2017-04-29 06:18:44 UTC)
  - Do not expect the default priors to remain the same in future rstanarm versions.
  Thus, R scripts should specify priors explicitly, even if they are just the defaults.
  - For execution on a local, multicore CPU with excess RAM we recommend calling
  options(mc.cores = parallel::detectCores())
  > Sys.unsetenv("R_TESTS")
  > example(example_model)
  
  exmpl_> example_model <- 
  exmpl_+   stan_glmer(cbind(incidence, size - incidence) ~ size + period + (1|herd),
  exmpl_+              data = lme4::cbpp, family = binomial,
  exmpl_+              # this next line is only to keep the example small in size!
  exmpl_+              chains = 2, cores = 1, seed = 12345, iter = 500)
  
  SAMPLING FOR MODEL 'binomial' NOW (CHAIN 1).
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  Iteration:   1 / 500 [  0%]  (Warmup)
  Iteration:  50 / 500 [ 10%]  (Warmup)
  Iteration: 100 / 500 [ 20%]  (Warmup)
  Iteration: 150 / 500 [ 30%]  (Warmup)
  Iteration: 200 / 500 [ 40%]  (Warmup)
  Iteration: 250 / 500 [ 50%]  (Warmup)
  Iteration: 251 / 500 [ 50%]  (Sampling)
  Iteration: 300 / 500 [ 60%]  (Sampling)
  Iteration: 350 / 500 [ 70%]  (Sampling)
  Iteration: 400 / 500 [ 80%]  (Sampling)
  Iteration: 450 / 500 [ 90%]  (Sampling)
  Iteration: 500 / 500 [100%]  (Sampling)
  
   Elapsed Time: 1.33 seconds (Warm-up)
                 0.48 seconds (Sampling)
                 1.81 seconds (Total)
  
  
  SAMPLING FOR MODEL 'binomial' NOW (CHAIN 2).
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  Iteration:   1 / 500 [  0%]  (Warmup)
  Iteration:  50 / 500 [ 10%]  (Warmup)
  Iteration: 100 / 500 [ 20%]  (Warmup)
  Iteration: 150 / 500 [ 30%]  (Warmup)
  Iteration: 200 / 500 [ 40%]  (Warmup)
  Iteration: 250 / 500 [ 50%]  (Warmup)
  Iteration: 251 / 500 [ 50%]  (Sampling)
  Iteration: 300 / 500 [ 60%]  (Sampling)
  Iteration: 350 / 500 [ 70%]  (Sampling)
  Iteration: 400 / 500 [ 80%]  (Sampling)
  Iteration: 450 / 500 [ 90%]  (Sampling)
  Iteration: 500 / 500 [100%]  (Sampling)
  
   Elapsed Time: 1.58 seconds (Warm-up)
                 0.49 seconds (Sampling)
                 2.07 seconds (Total)
  
  
  exmpl_> example_model
  stan_glmer
   family:  binomial [logit]
   formula: cbind(incidence, size - incidence) ~ size + period + (1 | herd)
  ------
  
  Estimates:
              Median MAD_SD
  (Intercept) -1.6    0.6  
  size         0.0    0.0  
  period2     -0.9    0.3  
  period3     -1.1    0.3  
  period4     -1.5    0.4  
  
  Error terms:
   Groups Name        Std.Dev.
   herd   (Intercept) 0.79    
  Num. levels: herd 15 
  
  Sample avg. posterior predictive 
  distribution of y (X = xbar):
           Median MAD_SD
  mean_PPD 1.8    0.2   
  
  ------
  For info on the priors used see help('prior_summary.stanreg').> if (!grepl("^sparc",  R.version$platform)) test_check("rstanarm")
  
   4-fold cross-validation
  
             Estimate  SE
  elpd_kfold    -77.8 3.3
  
   2-fold cross-validation
  
             Estimate   SE
  elpd_kfold   -107.5 11.8
  Loading required package: Matrix
  Setting 'QR' to TRUE can often be helpful when using one of the variational inference algorithms. See the documentation for the 'QR' argument.
  Setting 'QR' to TRUE can often be helpful when using one of the variational inference algorithms. See the documentation for the 'QR' argument.
  Setting 'QR' to TRUE can often be helpful when using one of the variational inference algorithms. See the documentation for the 'QR' argument.
  Initial log joint probability = -171.984
  Optimization terminated normally: 
    Convergence detected: relative gradient magnitude is below tolerance
  ------------------------------------------------------------
  EXPERIMENTAL ALGORITHM:
    This procedure has not been thoroughly tested and may be unstable
    or buggy. The interface is subject to change.
  ------------------------------------------------------------
  
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  Begin eta adaptation.
  Iteration:   1 / 250 [  0%]  (Adaptation)
  Iteration:  50 / 250 [ 20%]  (Adaptation)
  Iteration: 100 / 250 [ 40%]  (Adaptation)
  Iteration: 150 / 250 [ 60%]  (Adaptation)
  Iteration: 200 / 250 [ 80%]  (Adaptation)
  Success! Found best value [eta = 1] earlier than expected.
  
  Begin stochastic gradient ascent.
    iter       ELBO   delta_ELBO_mean   delta_ELBO_med   notes 
     100     -1e+02             1.000            1.000
     200     -1e+02             0.573            1.000
     300     -1e+02             0.453            0.214
     400     -1e+02             0.341            0.214
     500     -9e+01             0.276            0.147
     600     -1e+02             0.245            0.147
     700     -1e+02             0.218            0.086
     800     -9e+01             0.195            0.086
     900     -9e+01             0.173            0.059
    1000     -9e+01             0.157            0.059
    1100     -1e+02             0.061            0.045
    1200     -1e+02             0.049            0.031
    1300     -9e+01             0.031            0.029
    1400     -9e+01             0.031            0.029
    1500     -9e+01             0.030            0.029
    1600     -9e+01             0.022            0.024
    1700     -9e+01             0.016            0.009   MEDIAN ELBO CONVERGED
  
  Drawing a sample of size 1000 from the approximate posterior... 
  COMPLETED.
  ------------------------------------------------------------
  EXPERIMENTAL ALGORITHM:
    This procedure has not been thoroughly tested and may be unstable
    or buggy. The interface is subject to change.
  ------------------------------------------------------------
  
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  Begin eta adaptation.
  Iteration:   1 / 250 [  0%]  (Adaptation)
  Iteration:  50 / 250 [ 20%]  (Adaptation)
  Iteration: 100 / 250 [ 40%]  (Adaptation)
  Iteration: 150 / 250 [ 60%]  (Adaptation)
  Iteration: 200 / 250 [ 80%]  (Adaptation)
  Iteration: 250 / 250 [100%]  (Adaptation)
  Success! Found best value [eta = 0.1].
  
  Begin stochastic gradient ascent.
    iter       ELBO   delta_ELBO_mean   delta_ELBO_med   notes 
     100     -2e+02             1.000            1.000
     200     -1e+02             0.517            1.000
     300     -1e+02             0.349            0.034
     400     -1e+02             0.263            0.034
     500     -1e+02             0.212            0.013
     600     -1e+02             0.177            0.013
     700     -1e+02             0.153            0.009   MEDIAN ELBO CONVERGED
  
  Drawing a sample of size 1000 from the approximate posterior... 
  COMPLETED.
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  
   Elapsed Time: 1.36 seconds (Warm-up)
                 0.84 seconds (Sampling)
                 2.2 seconds (Total)
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  
   Elapsed Time: 1.85 seconds (Warm-up)
                 0.81 seconds (Sampling)
                 2.66 seconds (Total)
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  WARNING: There aren't enough warmup iterations to fit the
           three stages of adaptation as currently configured.
           Reducing each adaptation stage to 15%/75%/10% of
           the given number of warmup iterations:
             init_buffer = 7
             adapt_window = 38
             term_buffer = 5
  
  
   Elapsed Time: 0.02 seconds (Warm-up)
                 0.03 seconds (Sampling)
                 0.05 seconds (Total)
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  WARNING: There aren't enough warmup iterations to fit the
           three stages of adaptation as currently configured.
           Reducing each adaptation stage to 15%/75%/10% of
           the given number of warmup iterations:
             init_buffer = 7
             adapt_window = 38
             term_buffer = 5
  
  
   Elapsed Time: 0.04 seconds (Warm-up)
                 0.02 seconds (Sampling)
                 0.06 seconds (Total)
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  WARNING: There aren't enough warmup iterations to fit the
           three stages of adaptation as currently configured.
           Reducing each adaptation stage to 15%/75%/10% of
           the given number of warmup iterations:
             init_buffer = 3
             adapt_window = 20
             term_buffer = 2
  
  
   Elapsed Time: 0.04 seconds (Warm-up)
                 0.21 seconds (Sampling)
                 0.25 seconds (Total)
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  WARNING: There aren't enough warmup iterations to fit the
           three stages of adaptation as currently configured.
           Reducing each adaptation stage to 15%/75%/10% of
           the given number of warmup iterations:
             init_buffer = 3
             adapt_window = 20
             term_buffer = 2
  
  
   Elapsed Time: 0.17 seconds (Warm-up)
                 0.23 seconds (Sampling)
                 0.4 seconds (Total)
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  WARNING: There aren't enough warmup iterations to fit the
           three stages of adaptation as currently configured.
           Reducing each adaptation stage to 15%/75%/10% of
           the given number of warmup iterations:
             init_buffer = 3
             adapt_window = 20
             term_buffer = 2
  
  
   Elapsed Time: 0.18 seconds (Warm-up)
                 0.15 seconds (Sampling)
                 0.33 seconds (Total)
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  WARNING: There aren't enough warmup iterations to fit the
           three stages of adaptation as currently configured.
           Reducing each adaptation stage to 15%/75%/10% of
           the given number of warmup iterations:
             init_buffer = 3
             adapt_window = 20
             term_buffer = 2
  
  
   Elapsed Time: 0.17 seconds (Warm-up)
                 0.25 seconds (Sampling)
                 0.42 seconds (Total)
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  WARNING: No variance estimation is
           performed for num_warmup < 20
  
  
   Elapsed Time: 0 seconds (Warm-up)
                 0 seconds (Sampling)
                 0 seconds (Total)
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  WARNING: No variance estimation is
           performed for num_warmup < 20
  
  
   Elapsed Time: 0 seconds (Warm-up)
                 0 seconds (Sampling)
                 0 seconds (Total)
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  WARNING: There aren't enough warmup iterations to fit the
           three stages of adaptation as currently configured.
           Reducing each adaptation stage to 15%/75%/10% of
           the given number of warmup iterations:
             init_buffer = 3
             adapt_window = 20
             term_buffer = 2
  
  
   Elapsed Time: 0.03 seconds (Warm-up)
                 0.04 seconds (Sampling)
                 0.07 seconds (Total)
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  WARNING: There aren't enough warmup iterations to fit the
           three stages of adaptation as currently configured.
           Reducing each adaptation stage to 15%/75%/10% of
           the given number of warmup iterations:
             init_buffer = 3
             adapt_window = 20
             term_buffer = 2
  
  
   Elapsed Time: 0.03 seconds (Warm-up)
                 0.04 seconds (Sampling)
                 0.07 seconds (Total)
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  WARNING: There aren't enough warmup iterations to fit the
           three stages of adaptation as currently configured.
           Reducing each adaptation stage to 15%/75%/10% of
           the given number of warmup iterations:
             init_buffer = 3
             adapt_window = 20
             term_buffer = 2
  
  
   Elapsed Time: 0.03 seconds (Warm-up)
                 0.04 seconds (Sampling)
                 0.07 seconds (Total)
  
  
  Gradient evaluation took 0 seconds
  1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
  Adjust your expectations accordingly!
  
  
  WARNING: There aren't enough warmup iterations to fit the
           three stages of adaptation as currently configured.
           Reducing each adaptation stage to 15%/75%/10% of
           the given number of warmup iterations:
             init_buffer = 3
             adapt_window = 20
             term_buffer = 2
  
  
   Elapsed Time: 0.03 seconds (Warm-up)
                 0.04 seconds (Sampling)
                 0.07 seconds (Total)
  
  Loading required package: ggplot2
  Loading required package: StanHeaders
  rstan (Version 2.15.1, packaged: 2017-04-19 05:03:57 UTC, GitRev: 2e1f913d3ca3)
  For execution on a local, multicore CPU with excess RAM we recommend calling
  rstan_options(auto_write = TRUE)
  options(mc.cores = parallel::detectCores())
  "/home/ripley/R/Lib32/Rcpp/include/Rcpp/internal/r_coerce.h", line 219: Error: The function "snprintf" must have a prototype.
  "/home/ripley/R/Lib32/Rcpp/include/Rcpp/internal/r_coerce.h", line 220: Error: The function "snprintf" must have a prototype.
  "/home/ripley/R/Lib32/Rcpp/include/Rcpp/internal/r_coerce.h", line 221: Error: The function "snprintf" must have a prototype.
  "/home/ripley/R/Lib32/Rcpp/include/Rcpp/internal/r_coerce.h", line 241: Error: The function "snprintf" must have a prototype.
  "/home/ripley/R/Lib32/Rcpp/include/Rcpp/internal/r_coerce.h", line 249: Error: The function "snprintf" must have a prototype.
  "/home/ripley/R/Lib32/Rcpp/include/Rcpp/date_datetime/Datetime.h", line 83: Error: snprintf is not defined.
  "/tmp/RtmpgMaWG6/RLIBS_75064a92a21/BH/include/boost/config/compiler/sunpro_cc.hpp", line 117: Warning (Anachronism): Attempt to redefine BOOST_NO_CXX11_RVALUE_REFERENCES without using #undef.
  "/tmp/RtmpgMaWG6/RLIBS_75064a92a21/BH/include/boost/numeric/odeint/stepper/dense_output_runge_kutta.hpp", line 40: Warning: Last line in file "/tmp/RtmpgMaWG6/RLIBS_75064a92a21/BH/include/boost/numeric/odeint/integrate/max_step_checker.hpp" is not terminated with a newline.
  "/tmp/RtmpgMaWG6/RLIBS_75064a92a21/BH/include/boost/numeric/odeint/integrate/integrate_const.hpp", line 26: Warning: Last line in file "/tmp/RtmpgMaWG6/RLIBS_75064a92a21/BH/include/boost/numeric/odeint/integrate/check_adapter.hpp" is not terminated with a newline.
  "file72b151f1675a.cpp", line 726: Error: The name minus is ambiguous, stan::math::minus<T>(const T&) and std::minus<_Tp>.
  "file72b151f1675a.cpp", line 727: Error: The name minus is ambiguous, stan::math::minus<T>(const T&) and std::minus<_Tp>.
  "file72b151f1675a.cpp", line 1467: Error: The name minus is ambiguous, stan::math::minus<T>(const T&) and std::minus<_Tp>.
  9 Error(s) and 3 Warning(s) detected.
  make: Fatal error: Command failed for target `file72b151f1675a.o'
  Current working directory /tmp/RtmpJEaiw5/sourceCpp-i386-pc-solaris2.10-0.12.10/sourcecpp_72b1ca4f1a
  CC -library=stlport4 -I/home/ripley/R/cc/include -DNDEBUG   -I"/home/ripley/R/Lib32/Rcpp/include/"  -I"/tmp/RtmpgMaWG6/RLIBS_75064a92a21/RcppEigen/include/"  -I"/tmp/RtmpgMaWG6/RLIBS_75064a92a21/RcppEigen/include/unsupported"  -I"/home/ripley/R/Lib32/rstan/include/boost_not_in_BH" -I"/tmp/RtmpgMaWG6/RLIBS_75064a92a21/BH/include" -I"/home/ripley/R/Lib32/StanHeaders/include/src/"  -I"/home/ripley/R/Lib32/StanHeaders/include/"  -I"/home/ripley/R/Lib32/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DBOOST_NO_CXX11_RVALUE_REFERENCES  -I"/home/ripley/R/Lib32/Rcpp/include" -I"/home/ripley/R/Lib32/rstan/include" -I"/tmp/RtmpJEaiw5/sourceCpp-i386-pc-solaris2.10-0.12.10" -I/usr/local/include   -KPIC  -O -xlibmil -xtarget=native -nofstore  -c file72b151f1675a.cpp -o file72b151f1675a.o
  *** Error code 2
  Error in Rcpp::sourceCpp(code = paste(lines, collapse = "\n"), env = env) : 
    Error 1 occurred building shared library.
  Calls: test_check ... eval -> eval -> expose_stan_functions -> <Anonymous>
  Here is the C++ code that does not compile. Please report bug.
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "// [[Rcpp::depends(rstan)]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "#include <Rcpp.h>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                    "#include <RcppEigen.h>" 
                                                                                                                                                                                                                                                                                                                                            /home/ripley/R/Lib32/rstan/include/boost_not_in_BH/boost/exception/exception.hpp 
                                                                                                                                                                                                                                                                                                                                "#include</home/ripley/R/Lib32/rstan/include/boost_not_in_BH/boost/exception/exception.hpp>" 
                                                                                                                                                                                                                                                                                                                                          /home/ripley/R/Lib32/rstan/include/boost_not_in_BH/boost/fusion/support/unused.hpp 
                                                                                                                                                                                                                                                                                                                              "#include</home/ripley/R/Lib32/rstan/include/boost_not_in_BH/boost/fusion/support/unused.hpp>" 
                                                                                                                                                                                                                                                                                                                                   /home/ripley/R/Lib32/rstan/include/boost_not_in_BH/boost/math/policies/error_handling.hpp 
                                                                                                                                                                                                                                                                                                                       "#include</home/ripley/R/Lib32/rstan/include/boost_not_in_BH/boost/math/policies/error_handling.hpp>" 
                                                                                                                                                                                                                                                                                                                                             /home/ripley/R/Lib32/rstan/include/boost_not_in_BH/boost/phoenix/core/actor.hpp 
                                                                                                                                                                                                                                                                                                                                 "#include</home/ripley/R/Lib32/rstan/include/boost_not_in_BH/boost/phoenix/core/actor.hpp>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "#include <stan/math.hpp>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                              "#include <src/stan/lang/rethrow_located.hpp>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                    "#include <src/stan/model/indexing.hpp>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "#include <boost/exception/all.hpp>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                           "#include <boost/random/linear_congruential.hpp>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "#include <cmath>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "#include <cstddef>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "#include <fstream>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "#include <iostream>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "#include <sstream>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "#include <stdexcept>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "#include <utility>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "#include <vector>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                "#include <boost/date_time/posix_time/posix_time_types.hpp>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                    "#include <boost/math/special_functions/fpclassify.hpp>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                              "#include <boost/random/additive_combine.hpp>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                     "#include <boost/random/uniform_real_distribution.hpp>" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                  "// Code generated by Stan version 2.15.0" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                          "" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using stan::math::vector_d;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "using stan::math::row_vector_d;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using stan::math::matrix_d;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                      "make_theta_L(const int& len_theta_L," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "                 const std::vector<int>& p," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "                 const double& dispersion," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                     "                 const vector_d& tau," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "                 const vector_d& scale," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                    "                 const vector_d& zeta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                     "                 const vector_d& rho," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "                 const vector_d& z_T) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                       "            validate_non_negative_index(\"theta_L\", \"len_theta_L\", len_theta_L);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                          "            vector_d  theta_L(static_cast<Eigen::VectorXd::Index>(len_theta_L));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                      "            (void) theta_L;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                    "            stan::math::initialize(theta_L, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                        "            stan::math::fill(theta_L,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                             "            int zeta_mark(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                    "            (void) zeta_mark;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                 "            stan::math::fill(zeta_mark, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                              "            stan::math::assign(zeta_mark,1);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                              "            int rho_mark(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                     "            (void) rho_mark;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                  "            stan::math::fill(rho_mark, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "            stan::math::assign(rho_mark,1);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                              "            int z_T_mark(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                     "            (void) z_T_mark;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                  "            stan::math::fill(z_T_mark, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "            stan::math::assign(z_T_mark,1);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                          "            int theta_L_mark(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                 "            (void) theta_L_mark;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                              "            stan::math::fill(theta_L_mark, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                           "            stan::math::assign(theta_L_mark,1);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "            for (int i = 1; i <= size(p); ++i) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                            "                    int nc(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                   "                    (void) nc;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                "                    stan::math::fill(nc, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                        "                    stan::math::assign(nc,get_base1(p,i,\"p\",1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                      "                    if (as_bool(logical_eq(nc,1))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                              "                        stan::math::assign(get_base1_lhs(theta_L,theta_L_mark,\"theta_L\",1), ((get_base1(tau,i,\"tau\",1) * get_base1(scale,i,\"scale\",1)) * dispersion));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "                        stan::math::assign(theta_L_mark, (theta_L_mark + 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                              "                    } else {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "                        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "                            validate_non_negative_index(\"T_i\", \"nc\", nc);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "                            validate_non_negative_index(\"T_i\", \"nc\", nc);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                               "                            matrix_d  T_i(static_cast<Eigen::VectorXd::Index>(nc),static_cast<Eigen::VectorXd::Index>(nc));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                          "                            (void) T_i;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                        "                            stan::math::initialize(T_i, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "                            stan::math::fill(T_i,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                       "                            fun_scalar_t__ std_dev;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                      "                            (void) std_dev;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                    "                            stan::math::initialize(std_dev, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                        "                            stan::math::fill(std_dev,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                           "                            fun_scalar_t__ T21;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                          "                            (void) T21;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                        "                            stan::math::initialize(T21, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "                            stan::math::fill(T21,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                     "                            fun_scalar_t__ trace_T_i;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                    "                            (void) trace_T_i;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                  "                            stan::math::initialize(trace_T_i, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                      "                            stan::math::fill(trace_T_i,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                    "                            stan::math::assign(trace_T_i,(square(((get_base1(tau,i,\"tau\",1) * get_base1(scale,i,\"scale\",1)) * dispersion)) * nc));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                              "                            validate_non_negative_index(\"pi\", \"nc\", nc);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                        "                            vector_d  pi(static_cast<Eigen::VectorXd::Index>(nc));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                           "                            (void) pi;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                         "                            stan::math::initialize(pi, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                             "                            stan::math::fill(pi,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                            "                            stan::math::assign(pi,segment(zeta,zeta_mark,nc));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                   "                            stan::math::assign(pi, divide(pi,sum(pi)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                              "                            stan::math::assign(zeta_mark, (zeta_mark + nc));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                    "                            stan::math::assign(std_dev, sqrt((get_base1(pi,1,\"pi\",1) * trace_T_i)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                "                            stan::math::assign(get_base1_lhs(T_i,1,1,\"T_i\",1), std_dev);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                    "                            stan::math::assign(std_dev, sqrt((get_base1(pi,2,\"pi\",1) * trace_T_i)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                   "                            stan::math::assign(T21, ((2.0 * get_base1(rho,rho_mark,\"rho\",1)) - 1.0));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                 "                            stan::math::assign(rho_mark, (rho_mark + 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                  "                            stan::math::assign(get_base1_lhs(T_i,2,2,\"T_i\",1), (std_dev * sqrt((1.0 - square(T21)))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                        "                            stan::math::assign(get_base1_lhs(T_i,2,1,\"T_i\",1), (std_dev * T21));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                         "                            for (int r = 2; r <= (nc - 1); ++r) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "                                {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                           "                                    int rp1(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                  "                                    (void) rp1;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                               "                                    stan::math::fill(rp1, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                      "                                    stan::math::assign(rp1,(r + 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                     "                                    validate_non_negative_index(\"T_row\", \"r\", r);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                              "                                    vector_d  T_row(static_cast<Eigen::VectorXd::Index>(r));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                "                                    (void) T_row;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                              "                                    stan::math::initialize(T_row, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                  "                                    stan::math::fill(T_row,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                    "                                    stan::math::assign(T_row,segment(z_T,z_T_mark,r));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                          "                                    fun_scalar_t__ scale_factor;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                         "                                    (void) scale_factor;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                       "                                    stan::math::initialize(scale_factor, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                           "                                    stan::math::fill(scale_factor,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                             "                                    stan::math::assign(scale_factor,(sqrt((get_base1(rho,rho_mark,\"rho\",1) / dot_self(T_row))) * std_dev));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                         "                                    stan::math::assign(z_T_mark, (z_T_mark + r));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                          "                                    stan::math::assign(std_dev, sqrt((get_base1(pi,rp1,\"pi\",1) * trace_T_i)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                        "                                    for (int c = 1; c <= r; ++c) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                          "                                        stan::math::assign(get_base1_lhs(T_i,rp1,c,\"T_i\",1), (get_base1(T_row,c,\"T_row\",1) * scale_factor));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                     "                                    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                "                                    stan::math::assign(get_base1_lhs(T_i,rp1,rp1,\"T_i\",1), (sqrt((1.0 - get_base1(rho,rho_mark,\"rho\",1))) * std_dev));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                         "                                    stan::math::assign(rho_mark, (rho_mark + 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "                                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                             "                            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "                            for (int c = 1; c <= nc; ++c) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "                                for (int r = c; r <= nc; ++r) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                  "                                    stan::math::assign(get_base1_lhs(theta_L,theta_L_mark,\"theta_L\",1), get_base1(T_i,r,c,\"T_i\",1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                 "                                    stan::math::assign(theta_L_mark, (theta_L_mark + 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "                                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                             "                            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "                        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                     "                    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                            "            return stan::math::promote_scalar<fun_return_scalar_t__>(theta_L);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "struct make_theta_L_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                    "    operator()(const int& len_theta_L," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "                 const std::vector<int>& p," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "                 const double& dispersion," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                     "                 const vector_d& tau," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "                 const vector_d& scale," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                    "                 const vector_d& zeta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                     "                 const vector_d& rho," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                     "                 const vector_d& z_T, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                      "        return make_theta_L(len_theta_L, p, dispersion, tau, scale, zeta, rho, z_T);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "make_b(const vector_d& z_b," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                       "           const vector_d& theta_L," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                     "           const std::vector<int>& p," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "           const std::vector<int>& l) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                 "            validate_non_negative_index(\"b\", \"rows(z_b)\", rows(z_b));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                  "            vector_d  b(static_cast<Eigen::VectorXd::Index>(rows(z_b)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "            (void) b;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                          "            stan::math::initialize(b, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                              "            stan::math::fill(b,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                "            int b_mark(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                       "            (void) b_mark;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                    "            stan::math::fill(b_mark, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                 "            stan::math::assign(b_mark,1);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                          "            int theta_L_mark(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                 "            (void) theta_L_mark;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                              "            stan::math::fill(theta_L_mark, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                           "            stan::math::assign(theta_L_mark,1);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "            for (int i = 1; i <= size(p); ++i) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                            "                    int nc(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                   "                    (void) nc;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                "                    stan::math::fill(nc, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                        "                    stan::math::assign(nc,get_base1(p,i,\"p\",1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                      "                    if (as_bool(logical_eq(nc,1))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "                        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                 "                            fun_scalar_t__ theta_L_start;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                "                            (void) theta_L_start;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                              "                            stan::math::initialize(theta_L_start, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                  "                            stan::math::fill(theta_L_start,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                              "                            stan::math::assign(theta_L_start,get_base1(theta_L,theta_L_mark,\"theta_L\",1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                     "                            for (int s = b_mark; s <= ((b_mark + get_base1(l,i,\"l\",1)) - 1); ++s) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                             "                                stan::math::assign(get_base1_lhs(b,s,\"b\",1), (theta_L_start * get_base1(z_b,s,\"z_b\",1)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                             "                            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                "                            stan::math::assign(b_mark, (b_mark + get_base1(l,i,\"l\",1)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                         "                            stan::math::assign(theta_L_mark, (theta_L_mark + 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "                        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                              "                    } else {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "                        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "                            validate_non_negative_index(\"T_i\", \"nc\", nc);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "                            validate_non_negative_index(\"T_i\", \"nc\", nc);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                               "                            matrix_d  T_i(static_cast<Eigen::VectorXd::Index>(nc),static_cast<Eigen::VectorXd::Index>(nc));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                          "                            (void) T_i;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                        "                            stan::math::initialize(T_i, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "                            stan::math::fill(T_i,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                  "                            stan::math::assign(T_i,rep_matrix(0,nc,nc));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "                            for (int c = 1; c <= nc; ++c) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                      "                                stan::math::assign(get_base1_lhs(T_i,c,c,\"T_i\",1), get_base1(theta_L,theta_L_mark,\"theta_L\",1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                     "                                stan::math::assign(theta_L_mark, (theta_L_mark + 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                     "                                for (int r = (c + 1); r <= nc; ++r) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                  "                                    stan::math::assign(get_base1_lhs(T_i,r,c,\"T_i\",1), get_base1(theta_L,theta_L_mark,\"theta_L\",1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                 "                                    stan::math::assign(theta_L_mark, (theta_L_mark + 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "                                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                             "                            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                           "                            for (int j = 1; j <= get_base1(l,i,\"l\",1); ++j) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "                                {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                    "                                    validate_non_negative_index(\"temp\", \"nc\", nc);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                              "                                    vector_d  temp(static_cast<Eigen::VectorXd::Index>(nc));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                 "                                    (void) temp;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                               "                                    stan::math::initialize(temp, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                   "                                    stan::math::fill(temp,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                        "                                    stan::math::assign(temp,multiply(T_i,segment(z_b,b_mark,nc)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "                                    stan::math::assign(b_mark, (b_mark - 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                       "                                    for (int s = 1; s <= nc; ++s) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                          "                                        stan::math::assign(get_base1_lhs(b,(b_mark + s),\"b\",1), get_base1(temp,s,\"temp\",1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                     "                                    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                      "                                    stan::math::assign(b_mark, ((b_mark + nc) + 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "                                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                             "                            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "                        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                     "                    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                  "            return stan::math::promote_scalar<fun_return_scalar_t__>(b);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "struct make_b_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                       "    operator()(const vector_d& z_b," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                       "           const vector_d& theta_L," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                     "           const std::vector<int>& p," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                     "           const std::vector<int>& l, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "        return make_b(z_b, theta_L, p, l);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                      "void" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                             "decov_lp(const vector_d& z_b," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& z_T," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& rho," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "             const vector_d& zeta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& tau," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                   "             const std::vector<double>& regularization," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "             const std::vector<double>& delta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                       "             const vector_d& shape," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                "             const int& t," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                              "             const std::vector<int>& p, double lp__ = 0.0) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "stan::math::accumulator<double> lp_accum__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "            int pos_reg(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                      "            (void) pos_reg;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                   "            stan::math::fill(pos_reg, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "            stan::math::assign(pos_reg,1);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "            int pos_rho(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                      "            (void) pos_rho;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                   "            stan::math::fill(pos_rho, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "            stan::math::assign(pos_rho,1);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "            lp_accum__.add(normal_log(z_b,0,1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "            lp_accum__.add(normal_log(z_T,0,1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "            for (int i = 1; i <= t; ++i) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                      "                if (as_bool(logical_gt(get_base1(p,i,\"p\",1),1))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                     "                    {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                      "                        validate_non_negative_index(\"shape1\", \"(get_base1(p,i,\\\"p\\\",1) - 1)\", (get_base1(p,i,\"p\",1) - 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                              "                        vector_d  shape1(static_cast<Eigen::VectorXd::Index>((get_base1(p,i,\"p\",1) - 1)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                           "                        (void) shape1;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                         "                        stan::math::initialize(shape1, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                             "                        stan::math::fill(shape1,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                      "                        validate_non_negative_index(\"shape2\", \"(get_base1(p,i,\\\"p\\\",1) - 1)\", (get_base1(p,i,\"p\",1) - 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                              "                        vector_d  shape2(static_cast<Eigen::VectorXd::Index>((get_base1(p,i,\"p\",1) - 1)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                           "                        (void) shape2;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                         "                        stan::math::initialize(shape2, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                             "                        stan::math::fill(shape2,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "                        fun_scalar_t__ nu;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                               "                        (void) nu;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                             "                        stan::math::initialize(nu, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                 "                        stan::math::fill(nu,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                           "                        stan::math::assign(nu,(get_base1(regularization,pos_reg,\"regularization\",1) + (0.5 * (get_base1(p,i,\"p\",1) - 2))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                       "                        stan::math::assign(pos_reg, (pos_reg + 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                     "                        stan::math::assign(get_base1_lhs(shape1,1,\"shape1\",1), nu);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                     "                        stan::math::assign(get_base1_lhs(shape2,1,\"shape2\",1), nu);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                         "                        for (int j = 2; j <= (get_base1(p,i,\"p\",1) - 1); ++j) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "                            stan::math::assign(nu, (nu - 0.5));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                          "                            stan::math::assign(get_base1_lhs(shape1,j,\"shape1\",1), (0.5 * j));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                 "                            stan::math::assign(get_base1_lhs(shape2,j,\"shape2\",1), nu);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "                        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                  "                        lp_accum__.add(beta_log(stan::model::rvalue(rho, stan::model::cons_list(stan::model::index_min_max(pos_rho, ((pos_rho + get_base1(p,i,\"p\",1)) - 2)), stan::model::nil_index_list()), \"rho\"),shape1,shape2));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                            "                        stan::math::assign(pos_rho, ((pos_rho + get_base1(p,i,\"p\",1)) - 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                     "                    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                      "            lp_accum__.add(gamma_log(zeta,delta,1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                       "            lp_accum__.add(gamma_log(tau,shape,1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "struct decov_lp_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                              "        void" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                       "    operator()(const vector_d& z_b," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& z_T," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& rho," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "             const vector_d& zeta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& tau," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                   "             const std::vector<double>& regularization," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "             const std::vector<double>& delta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                       "             const vector_d& shape," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                "             const int& t," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                "             const std::vector<int>& p, double lp__ = 0.0, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                              "        return decov_lp(z_b, z_T, rho, zeta, tau, regularization, delta, shape, t, p, lp__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                          "hs_prior(const vector_d& z_beta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                           "             const std::vector<double>& global," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "             const std::vector<vector_d>& local," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "             const double& global_prior_scale," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                 "             const double& error_scale) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                      "            validate_non_negative_index(\"lambda\", \"rows(z_beta)\", rows(z_beta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                          "            vector_d  lambda(static_cast<Eigen::VectorXd::Index>(rows(z_beta)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                       "            (void) lambda;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                     "            stan::math::initialize(lambda, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "            stan::math::fill(lambda,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                     "            int K(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "            (void) K;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                         "            stan::math::fill(K, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "            stan::math::assign(K, rows(z_beta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "            for (int k = 1; k <= K; ++k) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                      "                stan::math::assign(get_base1_lhs(lambda,k,\"lambda\",1), (get_base1(get_base1(local,1,\"local\",1),k,\"local\",2) * sqrt(get_base1(get_base1(local,2,\"local\",1),k,\"local\",2))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                         "            return stan::math::promote_scalar<fun_return_scalar_t__>(multiply(multiply(multiply(multiply(elt_multiply(z_beta,lambda),get_base1(global,1,\"global\",1)),sqrt(get_base1(global,2,\"global\",1))),global_prior_scale),error_scale));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "struct hs_prior_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                    "    operator()(const vector_d& z_beta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                           "             const std::vector<double>& global," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "             const std::vector<vector_d>& local," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "             const double& global_prior_scale," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                   "             const double& error_scale, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                          "        return hs_prior(z_beta, global, local, global_prior_scale, error_scale);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                      "hsplus_prior(const vector_d& z_beta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                       "                 const std::vector<double>& global," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                      "                 const std::vector<vector_d>& local," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                        "                 const double& global_prior_scale," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "                 const double& error_scale) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
  "        return stan::math::promote_scalar<fun_return_scalar_t__>(multiply(multiply(multiply(multiply(elt_multiply(elt_multiply(z_beta,elt_multiply(get_base1(local,1,\"local\",1),sqrt(get_base1(local,2,\"local\",1)))),elt_multiply(get_base1(local,3,\"local\",1),sqrt(get_base1(local,4,\"local\",1)))),get_base1(global,1,\"global\",1)),sqrt(get_base1(global,2,\"global\",1))),global_prior_scale),error_scale));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "struct hsplus_prior_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                    "    operator()(const vector_d& z_beta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                       "                 const std::vector<double>& global," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                      "                 const std::vector<vector_d>& local," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                        "                 const double& global_prior_scale," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                               "                 const double& error_scale, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                      "        return hsplus_prior(z_beta, global, local, global_prior_scale, error_scale);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                    "divide_real_by_vector(const double& x," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "                          const vector_d& y) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                     "            int K(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "            (void) K;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                         "            stan::math::fill(K, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "            stan::math::assign(K,rows(y));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "            validate_non_negative_index(\"ret\", \"K\", K);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                        "            vector_d  ret(static_cast<Eigen::VectorXd::Index>(K));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                          "            (void) ret;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                        "            stan::math::initialize(ret, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            stan::math::fill(ret,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "            for (int k = 1; k <= K; ++k) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                         "                stan::math::assign(get_base1_lhs(ret,k,\"ret\",1), (x / get_base1(y,k,\"y\",1)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                "            return stan::math::promote_scalar<fun_return_scalar_t__>(ret);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                  "struct divide_real_by_vector_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "    operator()(const double& x," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                              "                          const vector_d& y, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        return divide_real_by_vector(x, y);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                    "double" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "CFt(const double& z," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "        const double& df) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                            "            fun_scalar_t__ z2;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "            (void) z2;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                         "            stan::math::initialize(z2, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "            stan::math::fill(z2,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "            stan::math::assign(z2,square(z));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                            "            fun_scalar_t__ z3;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "            (void) z3;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                         "            stan::math::initialize(z3, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "            stan::math::fill(z3,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                              "            stan::math::assign(z3,(z2 * z));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                            "            fun_scalar_t__ z5;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "            (void) z5;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                         "            stan::math::initialize(z5, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "            stan::math::fill(z5,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "            stan::math::assign(z5,(z2 * z3));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                            "            fun_scalar_t__ z7;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "            (void) z7;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                         "            stan::math::initialize(z7, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "            stan::math::fill(z7,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "            stan::math::assign(z7,(z2 * z5));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                            "            fun_scalar_t__ z9;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "            (void) z9;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                         "            stan::math::initialize(z9, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "            stan::math::fill(z9,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "            stan::math::assign(z9,(z2 * z7));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "            fun_scalar_t__ df2;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                          "            (void) df2;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                        "            stan::math::initialize(df2, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            stan::math::fill(df2,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                           "            stan::math::assign(df2,square(df));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "            fun_scalar_t__ df3;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                          "            (void) df3;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                        "            stan::math::initialize(df3, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            stan::math::fill(df3,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                           "            stan::math::assign(df3,(df2 * df));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "            fun_scalar_t__ df4;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                          "            (void) df4;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                        "            stan::math::initialize(df4, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            stan::math::fill(df4,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "            stan::math::assign(df4,(df2 * df2));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                               "            return stan::math::promote_scalar<fun_return_scalar_t__>(((((z + ((z3 + z) / (4 * df))) + ((((5 * z5) + (16 * z3)) + (3 * z)) / (96 * df2))) + (((((3 * z7) + (19 * z5)) + (17 * z3)) - (15 * z)) / (384 * df3))) + ((((((79 * z9) + (776 * z7)) + (1482 * z5)) - (1920 * z3)) - (945 * z)) / (92160 * df4))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                    "struct CFt_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                            "        double" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "    operator()(const double& z," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                 "        const double& df, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                "        return CFt(z, df);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                            "std::vector<std::vector<int> >" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "make_V(const int& N," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "           const int& t," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "           const std::vector<int>& v) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                    "    typedef int fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                 "            validate_non_negative_index(\"V\", \"t\", t);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                 "            validate_non_negative_index(\"V\", \"N\", N);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "            vector<vector<int> > V(t, (vector<int>(N, 0)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                         "            stan::math::fill(V, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                   "            int pos(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                          "            (void) pos;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                       "            stan::math::fill(pos, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                    "            stan::math::assign(pos,1);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "            if (as_bool(logical_gt(t,0))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "                for (int j = 1; j <= N; ++j) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                        "                    for (int i = 1; i <= t; ++i) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                "                        stan::math::assign(get_base1_lhs(get_base1_lhs(V,i,\"V\",1),j,\"V\",2), get_base1(v,pos,\"v\",1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "                        stan::math::assign(pos, (pos + 1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                     "                    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                  "            return stan::math::promote_scalar<fun_return_scalar_t__>(V);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "struct make_V_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "            std::vector<std::vector<int> >" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                              "    operator()(const int& N," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "           const int& t," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                     "           const std::vector<int>& v, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "        return make_V(N, t, v);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "linkinv_bern(const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                       "                 const int& link) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "        if (as_bool(logical_eq(link,1))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                     "            return stan::math::promote_scalar<fun_return_scalar_t__>(inv_logit(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,2))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                           "            return stan::math::promote_scalar<fun_return_scalar_t__>(Phi(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,3))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                        "            return stan::math::promote_scalar<fun_return_scalar_t__>(add(divide(atan(eta),stan::math::pi()),0.5));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,4))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                           "            return stan::math::promote_scalar<fun_return_scalar_t__>(exp(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,5))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                   "            return stan::math::promote_scalar<fun_return_scalar_t__>(inv_cloglog(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        } else {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            std::stringstream errmsg_stream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "            errmsg_stream__ << \"Invalid link\";" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "            throw std::domain_error(errmsg_stream__.str());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                    "        return stan::math::promote_scalar<fun_return_scalar_t__>(eta);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "struct linkinv_bern_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                       "    operator()(const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                         "                 const int& link, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "        return linkinv_bern(eta, link);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                    "double" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                          "ll_bern_lp(const vector_d& eta0," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                      "               const vector_d& eta1," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "               const int& link," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "               const std::vector<int>& N, double lp__ = 0.0) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "stan::math::accumulator<double> lp_accum__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                      "        if (as_bool((primitive_value(logical_lt(link,1)) || primitive_value(logical_gt(link,5))))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            std::stringstream errmsg_stream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "            errmsg_stream__ << \"Invalid link\";" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "            throw std::domain_error(errmsg_stream__.str());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "        if (as_bool(logical_eq(link,1))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                  "            lp_accum__.add(logistic_ccdf_log(eta0,0,1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                   "            lp_accum__.add(logistic_cdf_log(eta1,0,1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,2))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                    "            lp_accum__.add(normal_ccdf_log(eta0,0,1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                     "            lp_accum__.add(normal_cdf_log(eta1,0,1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,3))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                    "            lp_accum__.add(cauchy_ccdf_log(eta0,0,1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                     "            lp_accum__.add(cauchy_cdf_log(eta1,0,1));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,4))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                              "            lp_accum__.add(log1m_exp(eta0));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "            lp_accum__.add(eta1);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,5))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                  "            lp_accum__.add(log1m_exp(minus(exp(eta1))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "            lp_accum__.add(minus(exp(eta0)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                               "        return stan::math::promote_scalar<fun_return_scalar_t__>(get_lp(lp__, lp_accum__));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                             "struct ll_bern_lp_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                            "        double" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                      "    operator()(const vector_d& eta0," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                      "               const vector_d& eta1," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "               const int& link," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                              "               const std::vector<int>& N, double lp__ = 0.0, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                     "        return ll_bern_lp(eta0, eta1, link, N, lp__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                     "pw_bern(const int& y," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                          "            const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                            "            const int& link) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                     "            int N(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "            (void) N;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                         "            stan::math::fill(N, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                              "            stan::math::assign(N,rows(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                "            validate_non_negative_index(\"ll\", \"N\", N);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                         "            vector_d  ll(static_cast<Eigen::VectorXd::Index>(N));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "            (void) ll;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                         "            stan::math::initialize(ll, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "            stan::math::fill(ll,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                  "            if (as_bool((primitive_value(logical_lt(link,1)) || primitive_value(logical_gt(link,5))))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                        "                std::stringstream errmsg_stream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                      "                errmsg_stream__ << \"Invalid link\";" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "                throw std::domain_error(errmsg_stream__.str());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            if (as_bool(logical_eq(link,1))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "                for (int n = 1; n <= N; ++n) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                  "                    stan::math::assign(get_base1_lhs(ll,n,\"ll\",1), bernoulli_logit_log(y,get_base1(eta,n,\"eta\",1)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "            } else {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                        "                    validate_non_negative_index(\"pi\", \"N\", N);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                 "                    vector_d  pi(static_cast<Eigen::VectorXd::Index>(N));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                   "                    (void) pi;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                 "                    stan::math::initialize(pi, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                     "                    stan::math::fill(pi,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                       "                    stan::math::assign(pi, linkinv_bern(eta,link));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                        "                    for (int n = 1; n <= N; ++n) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                      "                        stan::math::assign(get_base1_lhs(ll,n,\"ll\",1), bernoulli_log(y,get_base1(pi,n,\"pi\",1)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                     "                    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                 "            return stan::math::promote_scalar<fun_return_scalar_t__>(ll);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                "struct pw_bern_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                              "    operator()(const int& y," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                          "            const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                              "            const int& link, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                     "        return pw_bern(y, eta, link);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "linkinv_binom(const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                      "                  const int& link) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "        if (as_bool(logical_eq(link,1))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                     "            return stan::math::promote_scalar<fun_return_scalar_t__>(inv_logit(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,2))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                           "            return stan::math::promote_scalar<fun_return_scalar_t__>(Phi(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,3))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                        "            return stan::math::promote_scalar<fun_return_scalar_t__>(add(divide(atan(eta),stan::math::pi()),0.5));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,4))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                           "            return stan::math::promote_scalar<fun_return_scalar_t__>(exp(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,5))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                   "            return stan::math::promote_scalar<fun_return_scalar_t__>(inv_cloglog(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        } else {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            std::stringstream errmsg_stream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "            errmsg_stream__ << \"Invalid link\";" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "            throw std::domain_error(errmsg_stream__.str());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                    "        return stan::math::promote_scalar<fun_return_scalar_t__>(eta);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                          "struct linkinv_binom_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                       "    operator()(const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                        "                  const int& link, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                  "        return linkinv_binom(eta, link);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                    "double" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                    "ll_binom_lp(const std::vector<int>& y," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                           "                const std::vector<int>& trials," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                      "                const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                     "                const int& link, double lp__ = 0.0) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "stan::math::accumulator<double> lp_accum__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                      "        if (as_bool((primitive_value(logical_lt(link,1)) || primitive_value(logical_gt(link,5))))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            std::stringstream errmsg_stream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "            errmsg_stream__ << \"Invalid link\";" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "            throw std::domain_error(errmsg_stream__.str());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "        if (as_bool(logical_eq(link,1))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                             "            lp_accum__.add(binomial_logit_log(y,trials,eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_lt(link,4))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                               "            lp_accum__.add(binomial_log(y,trials,linkinv_binom(eta,link)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,4))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                  "            for (int n = 1; n <= num_elements(y); ++n) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                    "                lp_accum__.add((get_base1(y,n,\"y\",1) * get_base1(eta,n,\"eta\",1)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                    "                lp_accum__.add(((get_base1(trials,n,\"trials\",1) - get_base1(y,n,\"y\",1)) * log1m_exp(get_base1(eta,n,\"eta\",1))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,5))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                  "            for (int n = 1; n <= num_elements(y); ++n) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                           "                    fun_scalar_t__ neg_exp_eta;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                          "                    (void) neg_exp_eta;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                        "                    stan::math::initialize(neg_exp_eta, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "                    stan::math::fill(neg_exp_eta,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                   "                    stan::math::assign(neg_exp_eta,-(exp(get_base1(eta,n,\"eta\",1))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                    "                    lp_accum__.add((get_base1(y,n,\"y\",1) * log1m_exp(neg_exp_eta)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                          "                    lp_accum__.add(((get_base1(trials,n,\"trials\",1) - get_base1(y,n,\"y\",1)) * neg_exp_eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                               "        return stan::math::promote_scalar<fun_return_scalar_t__>(get_lp(lp__, lp_accum__));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                            "struct ll_binom_lp_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                            "        double" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                 "    operator()(const std::vector<int>& y," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                           "                const std::vector<int>& trials," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                      "                const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                       "                const int& link, double lp__ = 0.0, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                   "        return ll_binom_lp(y, trials, eta, link, lp__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                       "pw_binom(const std::vector<int>& y," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                              "             const std::vector<int>& trials," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "             const int& link) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                     "            int N(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "            (void) N;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                         "            stan::math::fill(N, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                              "            stan::math::assign(N,rows(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                "            validate_non_negative_index(\"ll\", \"N\", N);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                         "            vector_d  ll(static_cast<Eigen::VectorXd::Index>(N));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "            (void) ll;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                         "            stan::math::initialize(ll, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "            stan::math::fill(ll,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                  "            if (as_bool((primitive_value(logical_lt(link,1)) || primitive_value(logical_gt(link,5))))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                        "                std::stringstream errmsg_stream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                      "                errmsg_stream__ << \"Invalid link\";" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "                throw std::domain_error(errmsg_stream__.str());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            if (as_bool(logical_eq(link,1))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "                for (int n = 1; n <= N; ++n) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                             "                    stan::math::assign(get_base1_lhs(ll,n,\"ll\",1), binomial_logit_log(get_base1(y,n,\"y\",1),get_base1(trials,n,\"trials\",1),get_base1(eta,n,\"eta\",1)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "            } else {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                        "                    validate_non_negative_index(\"pi\", \"N\", N);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                 "                    vector_d  pi(static_cast<Eigen::VectorXd::Index>(N));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                   "                    (void) pi;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                 "                    stan::math::initialize(pi, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                     "                    stan::math::fill(pi,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                      "                    stan::math::assign(pi, linkinv_binom(eta,link));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                        "                    for (int n = 1; n <= N; ++n) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                 "                        stan::math::assign(get_base1_lhs(ll,n,\"ll\",1), binomial_log(get_base1(y,n,\"y\",1),get_base1(trials,n,\"trials\",1),get_base1(pi,n,\"pi\",1)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                     "                    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                 "            return stan::math::promote_scalar<fun_return_scalar_t__>(ll);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "struct pw_binom_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                 "    operator()(const std::vector<int>& y," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                              "             const std::vector<int>& trials," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "             const int& link, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "        return pw_binom(y, trials, eta, link);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "linkinv_gauss(const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                      "                  const int& link) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "        if (as_bool(logical_eq(link,1))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                "            return stan::math::promote_scalar<fun_return_scalar_t__>(eta);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,2))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                           "            return stan::math::promote_scalar<fun_return_scalar_t__>(exp(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,3))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                           "            return stan::math::promote_scalar<fun_return_scalar_t__>(inv(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        } else {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            std::stringstream errmsg_stream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "            errmsg_stream__ << \"Invalid link\";" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "            throw std::domain_error(errmsg_stream__.str());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                    "        return stan::math::promote_scalar<fun_return_scalar_t__>(eta);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                          "struct linkinv_gauss_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                       "    operator()(const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                        "                  const int& link, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                  "        return linkinv_gauss(eta, link);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "pw_gauss(const vector_d& y," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const double& sigma," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "             const int& link) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                         "        return stan::math::promote_scalar<fun_return_scalar_t__>(subtract((-(0.5) * log((6.2831853071795862 * sigma))),multiply(0.5,square(divide(subtract(y,linkinv_gauss(eta,link)),sigma)))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "struct pw_gauss_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "    operator()(const vector_d& y," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const double& sigma," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "             const int& link, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "        return pw_gauss(y, eta, sigma, link);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "linkinv_gamma(const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                      "                  const int& link) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                "        if (as_bool(logical_eq(link,1))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                "            return stan::math::promote_scalar<fun_return_scalar_t__>(eta);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,2))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                           "            return stan::math::promote_scalar<fun_return_scalar_t__>(exp(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "        } else if (as_bool(logical_eq(link,3))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                           "            return stan::math::promote_scalar<fun_return_scalar_t__>(inv(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        } else {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            std::stringstream errmsg_stream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                          "            errmsg_stream__ << \"Invalid link\";" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "            throw std::domain_error(errmsg_stream__.str());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                    "        return stan::math::promote_scalar<fun_return_scalar_t__>(eta);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                          "struct linkinv_gamma_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                       "    operator()(const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                        "                  const int& link, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                  "        return linkinv_gamma(eta, link);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                    "double" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "GammaReg(const vector_d& y," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const double& shape," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                             "             const int& link," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "             const double& sum_log_y) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "            fun_scalar_t__ ret;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                          "            (void) ret;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                        "            stan::math::initialize(ret, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            stan::math::fill(ret,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                  "            if (as_bool((primitive_value(logical_lt(link,1)) || primitive_value(logical_gt(link,3))))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                        "                std::stringstream errmsg_stream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                      "                errmsg_stream__ << \"Invalid link\";" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "                throw std::domain_error(errmsg_stream__.str());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                        "            stan::math::assign(ret, ((rows(y) * ((shape * log(shape)) - stan::math::lgamma(shape))) + ((shape - 1) * sum_log_y)));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            if (as_bool(logical_eq(link,2))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                            "                stan::math::assign(ret, ((ret - (shape * sum(eta))) - (shape * sum(elt_divide(y,exp(eta))))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                     "            } else if (as_bool(logical_eq(link,1))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                            "                stan::math::assign(ret, ((ret - (shape * sum(log(eta)))) - (shape * sum(elt_divide(y,eta)))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "            } else {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                "                stan::math::assign(ret, ((ret + (shape * sum(log(eta)))) - (shape * dot_product(eta,y))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                "            return stan::math::promote_scalar<fun_return_scalar_t__>(ret);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "struct GammaReg_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                            "        double" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "    operator()(const vector_d& y," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const double& shape," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                             "             const int& link," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                     "             const double& sum_log_y, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                  "        return GammaReg(y, eta, shape, link, sum_log_y);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "pw_gamma(const vector_d& y," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const double& shape," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                           "             const int& link) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "std::ostream* pstream__ = &Rcpp::Rcout;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "(void) pstream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                        "    typedef double fun_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                         "    typedef fun_scalar_t__ fun_return_scalar_t__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    const static bool propto__ = false;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "    (void) propto__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "        fun_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                               "        (void) DUMMY_VAR__;  // suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "    try {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                     "            int N(0);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "            (void) N;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                         "            stan::math::fill(N, std::numeric_limits<int>::min());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                              "            stan::math::assign(N,rows(eta));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                "            validate_non_negative_index(\"ll\", \"N\", N);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                         "            vector_d  ll(static_cast<Eigen::VectorXd::Index>(N));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "            (void) ll;  // dummy to suppress unused var warning" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                         "            stan::math::initialize(ll, std::numeric_limits<double>::quiet_NaN());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "            stan::math::fill(ll,DUMMY_VAR__);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "            if (as_bool(logical_eq(link,3))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "                for (int n = 1; n <= N; ++n) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                       "                    stan::math::assign(get_base1_lhs(ll,n,\"ll\",1), gamma_log(get_base1(y,n,\"y\",1),shape,(shape * get_base1(eta,n,\"eta\",1))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                     "            } else if (as_bool(logical_eq(link,2))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "                for (int n = 1; n <= N; ++n) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                  "                    stan::math::assign(get_base1_lhs(ll,n,\"ll\",1), gamma_log(get_base1(y,n,\"y\",1),shape,(shape / exp(get_base1(eta,n,\"eta\",1)))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                     "            } else if (as_bool(logical_eq(link,1))) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                            "                for (int n = 1; n <= N; ++n) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                       "                    stan::math::assign(get_base1_lhs(ll,n,\"ll\",1), gamma_log(get_base1(y,n,\"y\",1),shape,(shape / get_base1(eta,n,\"eta\",1))));" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                         "                }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                      "            } else {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                        "                std::stringstream errmsg_stream__;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                      "                errmsg_stream__ << \"Invalid link\";" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                           "                throw std::domain_error(errmsg_stream__.str());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                             "            }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                 "            return stan::math::promote_scalar<fun_return_scalar_t__>(ll);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                 "        }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                   "    } catch (const std::exception& e) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                            "        // Next line prevents compiler griping about no return" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "        throw std::runtime_error(e.what());" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                         "}" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "struct pw_gamma_functor__ {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                          "        vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "    operator()(const vector_d& y," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                         "             const double& shape," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                             "             const int& link, std::ostream* pstream__ = &Rcpp::Rcout) const {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             "        return pw_gamma(y, eta, shape, link);" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                     "    }" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                        "};" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "// [[Rcpp::export]]" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                                  "vector_d" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                 "linkinv_inv_gaussian(const vector_d& eta," 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                               "                         const int& link) {" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                       "using std::istream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::string;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                  "using std::stringstream;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                        "using std::vector;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                                 "using stan::math::lgamma;" 
                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                               "using namespace stan::math;"