Non-linear model with integrate_1d in Bmrs

Oh… you are hitting an issue in brms here, so tagging @paul.buerkner .

brms generates this partial sum function:

  // compute partial sums of the log-likelihood
  real partial_log_lik_lpmf(int[] seq, int start, int end, vector Y, matrix X_a, vector b_a, vector C_1, int[] C_2, real phi, real zoi, real coi, int[] J_1, vector Z_1_a_1, vector r_1_a_1) {
    real ptarget = 0;
    int N = end - start + 1;
    // initialize linear predictor term
    vector[N] nlp_a = X_a[start:end] * b_a;
    // initialize non-linear predictor term
    vector[N] mu;
    for (n in 1:N) {
      // add more terms to the linear predictor
      int nn = n + start - 1;
      nlp_a[n] += r_1_a_1[J_1[nn]] * Z_1_a_1[nn];
    }
    for (n in 1:N) {
      int nn = n + start - 1;
      // compute non-linear predictor values
      mu[n] = inv_logit(integralfun(C_1[nn] , nlp_a[n] , C_2[nn]));
    }
    for (n in 1:N) {
      int nn = n + start - 1;
      ptarget += zero_one_inflated_beta_lpdf(Y[nn] | mu[n], phi, zoi, coi);
    }
    return ptarget;
  }

but because you are using the covariate as an argument to the data x_r argument of integrate_1d the newer stanc3 compiler enforce that you have to declare C_1 as argument to the partial sum function also with a “data” qualifier. So this compiles:

  // compute partial sums of the log-likelihood
  real partial_log_lik_lpmf(int[] seq, int start, int end, vector Y, matrix X_a, vector b_a, data vector C_1, int[] C_2, real phi, real zoi, real coi, int[] J_1, vector Z_1_a_1, vector r_1_a_1) {
    real ptarget = 0;
    int N = end - start + 1;
    // initialize linear predictor term
    vector[N] nlp_a = X_a[start:end] * b_a;
    // initialize non-linear predictor term
    vector[N] mu;
    for (n in 1:N) {
      // add more terms to the linear predictor
      int nn = n + start - 1;
      nlp_a[n] += r_1_a_1[J_1[nn]] * Z_1_a_1[nn];
    }
    for (n in 1:N) {
      int nn = n + start - 1;
      // compute non-linear predictor values
      mu[n] = inv_logit(integralfun(C_1[nn] , nlp_a[n] , C_2[nn]));
    }
    for (n in 1:N) {
      int nn = n + start - 1;
      ptarget += zero_one_inflated_beta_lpdf(Y[nn] | mu[n], phi, zoi, coi);
    }
    return ptarget;
  }

note that only “vector C_1” is replaced with “data vector C_1”… the real issue is that this difficult to make consistent with old and new stan (aka stanc3 based vs old compiler).

Can you file an issue for this now? This is a legit problem to sort out.

1 Like