Non-linear brms model does not compile but others do

I’m fitting some non-linear models using brms. Both of the two parameter models compile (two_param_logistic and two_param_neg_exp) and sample fine, however when I get to the third (three_param_logistic), I get the message in the console “Compiling Stan program…” and immediately console control is returned. The model doesn’t sample and no object is created in the environment.

library(brms)
tree_pairs <- data.frame(
  stringsAsFactors = FALSE,
            tree_1 = c(1620,2771,2721,2941,1656,
                       3041,1627,3191,3241,3251,3311,3371,1688,1697,1701,
                       1711,1714,1720,1722,1725,1729,1733,1735,3781,
                       3851,3871,1624,1630,1638,1640,1648,1671,1679,1683,
                       3401,1693,1695,1700,1704,1706,3761,3801,1742,
                       3921,1749,1644,1750,1652),
            tree_2 = c(2701,2741,2841,2971,3011,
                       3051,3091,3181,3231,3271,3301,3381,3431,3491,3541,
                       3591,3621,3671,3691,3701,3721,3751,3771,3791,
                       3841,3881,1625,1629,1637,1639,1649,1670,1677,1684,
                       1687,1691,1696,1699,1703,1707,1734,1739,1743,
                       1747,1748,2881,3451,16511),
              dist = c(64.33827892,30.23678112,
                       69.23766649,35.97850118,43.61904268,17.00798913,
                       35.81240554,44.50588801,14.7997238,78.58832179,40.35913818,
                       12.0708208,25.1621334,42.30414175,12.5748969,47.53706013,
                       54.71089685,25.89412055,26.63270324,3.40345302,
                       16.42600458,27.68677016,74.46706555,6.689770052,
                       6.381369487,17.52735355,7.222490385,32.64119116,63.84283712,
                       25.90517169,35.31398408,93.77865033,61.55310589,
                       14.10139865,34.6800647,7.743641752,72.80399257,35.20990874,
                       51.10118726,6.090417692,73.84355288,22.78702326,
                       88.01739193,23.87868392,59.42019037,2.247860917,
                       90.40542894,84.81127497),
      catch_tree_1 = c(15,25,34,17,18,6,23,21,
                       8,33,34,27,12,24,4,23,10,40,31,3,5,26,15,9,
                       17,16,14,3,21,20,43,18,15,16,18,10,40,11,
                       14,2,20,37,23,23,19,4,28,27),
      catch_tree_2 = c(28,11,24,22,19,12,18,31,
                       11,19,32,1,29,0,32,19,12,27,9,8,6,11,19,
                       21,5,23,7,38,26,21,0,18,16,21,38,25,2,5,26,
                       34,27,6,24,16,4,24,55,13),
       total_catch = c(43,36,58,39,37,18,41,52,
                       19,52,66,28,41,24,36,42,22,67,40,11,11,37,
                       34,30,22,39,21,41,47,41,43,36,31,37,56,35,
                       42,16,40,36,47,43,47,39,23,28,83,40),
         tree_pair = c("1620_2701","2771_2741",
                       "2721_2841","2941_2971","1656_3011","3041_3051",
                       "1627_3091","3191_3181","3241_3231","3251_3271","3311_3301",
                       "3371_3381","1688_3431","1697_3491","1701_3541",
                       "1711_3591","1714_3621","1720_3671","1722_3691","1725_3701",
                       "1729_3721","1733_3751","1735_3771","3781_3791",
                       "3851_3841","3871_3881","1624_1625","1630_1629",
                       "1638_1637","1640_1639","1648_1649","1671_1670","1679_1677",
                       "1683_1684","3401_1687","1693_1691","1695_1696",
                       "1700_1699","1704_1703","1706_1707","3761_1734","3801_1739",
                       "1742_1743","3921_1747","1749_1748","1644_2881",
                       "1750_3451","1652_16511")
)

two_param_logistic <- bf(total_catch ~ a1 / (1 + exp(-a2 * dist)),
                         a1 + a2 ~ 1,
                         nl = TRUE)

two_param_neg_exp <- bf(total_catch ~ a1 - exp(-a2 * dist),
                        a1 + a2 ~ 1,
                        nl = TRUE)

three_param_logistic <- bf(total_catch ~ a1 / (1 + exp(-a2 * dist - a3)),
                           a1 + a2 + a3 ~ 1,
                           nl = TRUE)

seed <- 314
prior_check <- brm(two_param_logistic,
                   data = tree_pairs,
                   family = poisson(link = "identity"),
                   prior = c(prior(normal(0, 100), nlpar = "a1"),
                             prior(inv_gamma(1, 0.01), nlpar = "a2", lb = 0)),
                   cores = 3,
                   chains = 6,
                   control = list(adapt_delta = 0.9),
                   sample_prior = "only", 
                   iter = 10000,
                   seed = seed)

prior_check_neg_exp <- brm(two_param_neg_exp,
                           data = tree_pairs,
                           family = poisson(link = "identity"),
                           prior = c(prior(normal(0, 100), nlpar = "a1", lb = 0),
                                     prior(inv_gamma(1, 0.01), nlpar = "a2", lb = 0)),
                           cores = 3,
                           chains = 6,
                           control = list(adapt_delta = 0.9),
                           sample_prior = "only", 
                           iter = 10000,
                           seed = seed)

prior_check_three_param <- brm(three_param_logistic,
                   data = tree_pairs,
                   family = poisson(link = "identity"),
                   prior = c(prior(normal(0, 100), nlpar = "a1"),
                             prior(inv_gamma(1, 0.01), nlpar = "a2", lb = 0),
                             prior(inv_gamma(1, 1,), nlpar = "a3")),
                   cores = 3,
                   chains = 6,
                   control = list(adapt_delta = 0.9),
                   sample_prior = "only",
                   iter = 10000,
                   seed = seed)

  • Operating System: Windows 10
  • brms Version: 2.13.5

If it matters, I dealt with the known Windows/rstan issues but have resolved those (I think, unless that’s somehow contributing to this problem?)

That doesn’t look ok :) I use cmdstanr with brms and it pointed it out immediately :)

Here’s the error:

Syntax error in '/var/folders/5p/dlcj_kd94bx83r83k_d77j54pspdk5/T/RtmpdV5vGi/model-ca83249fa17f.stan', line 43, column 38 to column 39, parsing error:
   -------------------------------------------------
    41:    target += inv_gamma_lpdf(b_a2 | 1, 0.01)
    42:      - 1 * inv_gamma_lccdf(0 | 1, 0.01);
    43:    target += inv_gamma_lpdf(b_a3 | 1, 1, );
                                                ^

Ah jeez, of course it was a misplaced comma. Thanks for taking a look.

1 Like