// generated with brms 2.16.0
functions {
}
data {
  int<lower=1> N;  // total number of observations
  vector[N] Y;  // response variable
  int<lower=1> K_mu1;  // number of population-level effects
  matrix[N, K_mu1] X_mu1;  // population-level design matrix
  int<lower=1> K_mu2;  // number of population-level effects
  matrix[N, K_mu2] X_mu2;  // population-level design matrix
  vector[2] con_theta;  // prior concentration
  // data for group-level effects of ID 1
  int<lower=1> N_1;  // number of grouping levels
  int<lower=1> M_1;  // number of coefficients per level
  int<lower=1> J_1[N];  // grouping indicator per observation
  // group-level predictor values
  vector[N] Z_1_mu1_1;
  int prior_only;  // should the likelihood be ignored?
}
transformed data {
  int Kc_mu1 = K_mu1 - 1;
  matrix[N, Kc_mu1] Xc_mu1;  // centered version of X_mu1 without an intercept
  vector[Kc_mu1] means_X_mu1;  // column means of X_mu1 before centering
  int Kc_mu2 = K_mu2 - 1;
  matrix[N, Kc_mu2] Xc_mu2;  // centered version of X_mu2 without an intercept
  vector[Kc_mu2] means_X_mu2;  // column means of X_mu2 before centering
  for (i in 2:K_mu1) {
    means_X_mu1[i - 1] = mean(X_mu1[, i]);
    Xc_mu1[, i - 1] = X_mu1[, i] - means_X_mu1[i - 1];
  }
  for (i in 2:K_mu2) {
    means_X_mu2[i - 1] = mean(X_mu2[, i]);
    Xc_mu2[, i - 1] = X_mu2[, i] - means_X_mu2[i - 1];
  }
}
parameters {
  vector[Kc_mu1] b_mu1;  // population-level effects
  real Intercept_mu1;  // temporary intercept for centered predictors
  real<lower=0> sigma1;  // dispersion parameter
  vector[Kc_mu2] b_mu2;  // population-level effects
  real Intercept_mu2;  // temporary intercept for centered predictors
  simplex[2] theta;  // mixing proportions
  vector<lower=0>[M_1] sd_1;  // group-level standard deviations
  vector[N_1] z_1[M_1];  // standardized group-level effects
}
transformed parameters {
  // mixing proportions
  real<lower=0,upper=1> theta1;
  real<lower=0,upper=1> theta2;
  vector[N_1] r_1_mu1_1;  // actual group-level effects
  theta1 = theta[1];
  theta2 = theta[2];
  r_1_mu1_1 = (sd_1[1] * (z_1[1]));
}
model {
  // likelihood including constants
  if (!prior_only) {
    // initialize linear predictor term
    vector[N] mu1 = Intercept_mu1 + Xc_mu1 * b_mu1;
    // initialize linear predictor term
    vector[N] mu2 = Intercept_mu2 + Xc_mu2 * b_mu2;
    for (n in 1:N) {
      // add more terms to the linear predictor
      mu1[n] += r_1_mu1_1[J_1[n]] * Z_1_mu1_1[n];
    }
    for (n in 1:N) {
      // apply the inverse link function
      mu2[n] = exp(-(mu2[n]));
    }
    // likelihood of the mixture model
    for (n in 1:N) {
      real ps[2];
      ps[1] = log(theta1) + normal_lpdf(Y[n] | mu1[n], sigma1);
      ps[2] = log(theta2) + exponential_lpdf(Y[n] | mu2[n]);
      target += log_sum_exp(ps);
    }
  }
  // priors including constants
  target += normal_lpdf(Intercept_mu1 | 0, 10);
  target += student_t_lpdf(sigma1 | 3, 0, 4.4);
  target += normal_lpdf(b_mu2 | 0, 1);
  target += normal_lpdf(Intercept_mu2 | 0, 1);
  target += dirichlet_lpdf(theta | con_theta);
  target += student_t_lpdf(sd_1 | 3, 0, 4.4)
    - 1 * student_t_lccdf(0 | 3, 0, 4.4);
  target += std_normal_lpdf(z_1[1]);
}
generated quantities {
  // actual population-level intercept
  real b_mu1_Intercept = Intercept_mu1 - dot_product(means_X_mu1, b_mu1);
  // actual population-level intercept
  real b_mu2_Intercept = Intercept_mu2 - dot_product(means_X_mu2, b_mu2);
}