# Errors; Hurdle model in brms

**URL:** https://discourse.mc-stan.org/t/errors-hurdle-model-in-brms/25341
**Category:** Modeling
**Created:** [November 18, 2021, 6:10am UTC](https://discourse.mc-stan.org/t/errors-hurdle-model-in-brms/25341 "2021-11-18T06:10:13Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![marie\_stan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/marie_stan/32/12450_2.png) [@marie\_stan](https://discourse.mc-stan.org/u/marie_stan)
#### Post date: [November 18, 2021, 6:10am UTC](https://discourse.mc-stan.org/t/errors-hurdle-model-in-brms/25341/1 "2021-11-18T06:10:13Z")

</div>

I would like to hurdle model for fish catch with brms packages.

```
ff <- read.csv(file.choose())
ff <- merge(f, n[,1:7], by = "code", all.x = TRUE) %>%
  filter(!is.na(sigma.BTM_rcp26_2005.5YS) & !is.na(sigma.S100_rcp26_2005.5Y.1) & !is.na(to.BTM_rcp26_2005.5YAVE.) & !is.na(to.S100_rcp26_2005.5YAVE))

```

[ff.csv](https://discourse.mc-stan.org/uploads/short-url/n62B4TZFUSBnCK1U99sDmRl3W7w.csv) (66.5 KB)

```
fbmodel <- brm(total_2005 ~ Thickness.average + Depth.range + Depth.average + 
                                sigma.BTM_rcp26_2005.5YS + sigma.S100_rcp26_2005.5Y.1 +
                                to.BTM_rcp26_2005.5YAVE. + to.S100_rcp26_2005.5YAVE, 
                                offset(totalnet_2005) , 
                   data = ff,
                   family = hurdle_negbinomial(link = "log", link_shape = "log", link_hu = "logit"),
                   prior = c(set_prior("normal(0,10)", class = "b")),
                   warmup = 300,
                   iter = 1000,
                   chains = 4,
                   save_all_pars = TRUE,
                   backend = "cmdstanr",
                   control = list(adapt_delta = 0.99, max_treedepth = 15),
                   save_model = "fish_stanscript",
                   file = "fish")

```

but it returned the error;

```
 Chain 4 Rejecting initial value:
    Chain 4 Log probability evaluates to log(0), i.e. negative infinity.
    Chain 4 Stan can't start sampling from this initial value.
    Chain 4 Initialization between (-2, 2) failed after 100 attempts. 
    Chain 4 Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.

```

hurdle\_negbionomial was not suitable for this data?

---

<div class="post-metadata">

### Author: ![AWoodward](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/awoodward/32/13015_2.png) [@AWoodward](https://discourse.mc-stan.org/u/AWoodward)
#### Post date: [November 18, 2021, 11:07am UTC](https://discourse.mc-stan.org/t/errors-hurdle-model-in-brms/25341/2 "2021-11-18T11:07:09Z")

</div>

@marie_stan looks like a reasonable selection based on the data. Did you try making a simpler version of this model first (say with fewer predictors or some simulated data)? Also it looks like you don’t have any predictors of the hurdle component?

---

<div class="post-metadata">

### Author: ![marie\_stan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/marie_stan/32/12450_2.png) [@marie\_stan](https://discourse.mc-stan.org/u/marie_stan)
#### Post date: [November 19, 2021, 1:04am UTC](https://discourse.mc-stan.org/t/errors-hurdle-model-in-brms/25341/3 "2021-11-19T01:04:11Z")

</div>

Thank you very much for the comment.

I changed into a simple setting (one variable considered) and added “hu ~” components.  
It successfully seemed to work, but increasing any variables, again the same error came up.

```
fbmodel <- brm(bf(total_2005 ~ Depth.average,
                  hu ~ Depth.average), # give 1 instead, it works
                   data = ff,
                   family = hurdle_negbinomial(link = "log", link_shape = "log", link_hu = "logit"),
                   prior = c(set_prior("normal(0,10)", class = "b")),
                   warmup = 500,
                   iter = 1000,
                   chains = 4,
                   save_all_pars = TRUE,
                   backend = "cmdstanr",
                   control = list(adapt_delta = 0.99, max_treedepth = 15),
                   save_model = "fish_stanscript",
                   file = "fish")

```

Thanks,

---

<div class="post-metadata">

### Author: ![marie\_stan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/marie_stan/32/12450_2.png) [@marie\_stan](https://discourse.mc-stan.org/u/marie_stan)
#### Post date: [November 19, 2021, 3:58am UTC](https://discourse.mc-stan.org/t/errors-hurdle-model-in-brms/25341/4 "2021-11-19T03:58:10Z")

</div>

I fount it successfully worked.

```
fbmodel <- brm(bf(total_2005 ~ 
                   Thickness.average + Depth.range + 
                    Depth.average +
                    sigma.BTM_rcp26_2005.5YS + sigma.S100_rcp26_2005.5Y.1 +
                    to.BTM_rcp26_2005.5YAVE. + to.S100_rcp26_2005.5YAVE + 
                    offset(log(totalnet_2005)), 
                  hu ~
                    Thickness.average + Depth.range + 
                    Depth.average + 
                    sigma.BTM_rcp26_2005.5YS + sigma.S100_rcp26_2005.5Y.1 +
                    to.BTM_rcp26_2005.5YAVE. + to.S100_rcp26_2005.5YAVE ),  
                   data = ff,
                   family = hurdle_negbinomial(link = "log", link_shape = "log", link_hu = "logit"),
                   prior = c(set_prior("normal(0,10)", class = "b")),
                   warmup = 500,
                   iter = 1000,
                   chains = 4,
                   cores = 4,
                   inits = 0, 
                   save_all_pars = TRUE,
                   backend = "cmdstanr",
                   control = list(adapt_delta = 0.99, max_treedepth = 15),
                   save_model = "fish_stanscript",
                   file = "fish")

```

---

<div class="post-metadata">

### Author: ![AWoodward](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/awoodward/32/13015_2.png) [@AWoodward](https://discourse.mc-stan.org/u/AWoodward)
#### Post date: [November 19, 2021, 6:36am UTC](https://discourse.mc-stan.org/t/errors-hurdle-model-in-brms/25341/5 "2021-11-19T06:36:10Z")

</div>

Great, is it the `offset(log(totalnet_2005))` that resolved the error? That variable has a lot of zeros in the data. Wouldn’t that cause those rows to be dropped?
