# Initialization problems using brms with Gamma distribution and identity link

**URL:** <https://discourse.mc-stan.org/t/initialization-problems-using-brms-with-gamma-distribution-and-identity-link/24621>\
**Category:** brms\
**Created:** [September 29, 2021, 2:48pm UTC](https://discourse.mc-stan.org/t/initialization-problems-using-brms-with-gamma-distribution-and-identity-link/24621 "2021-09-29T14:48:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthias56](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@matthias56](https://discourse.mc-stan.org/u/matthias56)\
**Post date:** [September 29, 2021, 2:48pm UTC](https://discourse.mc-stan.org/t/initialization-problems-using-brms-with-gamma-distribution-and-identity-link/24621/1 "2021-09-29T14:48:49Z")

</div>

Hi

Short summary of the problem :

I try to fit tree growth height as a function of tree growth circumference with a non-linear hierarchical model in brms.

acc\_h ~ exp(a)(1-exp(-exp(b)\*acc\_c) with :  
acc\_h = tree growth height  
acc\_c = tree growth circumference  
a and b the parameter to b estimate

I would like to use a Gamma distribution (growth can’t be negative) and an identity link in order to not change the form of the relation between height growth and circumference growth.

The expectation of mu should always be positive because acc\_c\>0.

The sampler has trouble finding initial values for the scale parameter and throws the following error multiple times:

Chain 1: Rejecting initial value:  
Chain 1: Error evaluating the log probability at the initial value.  
Chain 1: Exception: gamma\_lpdf: Inverse scale parameter[39] is inf, but must be finite! (in ‘model1eff7e31495d\_93ef33a66d298bf1ece66700bd599138’ at line 85)

```
nlform_C <- bf(acc_h ~ exp(alpha)*(1-exp(-exp(beta)*acc_c)),
               alpha ~ 1+ (1|flib_placette/fperiode) , beta ~ 1+(1|flib_placette/fperiode) , nl = TRUE)

nlprior_C <- c(prior(normal(4, 2), nlpar = "alpha"),
               prior(normal(0, 2), nlpar = "beta"))

fit_C <- brm(formula = nlform_C, data = arbre_periode3_brassy, prior = nlprior_C, family = Gamma(link="identity"),
             warmup=1000,iter=1200,chains = 1)

```

Is there a way to fix this problem ?

thanx

Please also provide the following information in addition to your question:

- Operating System: Ubuntu 20
- brms Version: 2.16

---

<div class="post-metadata">

**Author:** ![scholz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/scholz/32/14298_2.png) [@scholz](https://discourse.mc-stan.org/u/scholz)\
**Post date:** [October 1, 2021, 9:32am UTC](https://discourse.mc-stan.org/t/initialization-problems-using-brms-with-gamma-distribution-and-identity-link/24621/2 "2021-10-01T09:32:01Z")

</div>

Hi @matthias56  
You can set init values using the `inits` option as described [here](https://www.rdocumentation.org/packages/brms/versions/2.16.1/topics/brm), maybe that helps.

---

<div class="post-metadata">

**Author:** ![matthias56](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@matthias56](https://discourse.mc-stan.org/u/matthias56)\
**Post date:** [October 1, 2021, 12:36pm UTC](https://discourse.mc-stan.org/t/initialization-problems-using-brms-with-gamma-distribution-and-identity-link/24621/3 "2021-10-01T12:36:25Z")

</div>

Hi @scholz

Thanks. I had already try with fixed init (ex inits = 0.1 or init\_r =0.1) but it doesn’t work. Maybe I should set init only for some parameter.

Du to my formula acc\_h ~ exp(a)(1-exp(-exp(b)\*acc\_c) :

- acc\_h = 0 for acc\_c=0
- acc\_h \<0 for acc\_c \<0

So i modified my formula by multiply it by step(acc\_c) and add a small constant :

```
nlform_C <- bf(acc_h ~ 0.0001+step(acc_c)*exp(alpha)*(1-exp(-exp(beta)*acc_c)),
               alpha ~ 1+ (1|flib_placette/fperiode) , beta ~ 1+(1|flib_placette/fperiode) , nl = TRUE)

```

With this new form acc\_h is always strictely positive and there is no more initialization issue. It work’s even without the step(acc\_c). I don’t understand why because without it acc\_h is \<0 for acc\_c \< 0.

Is this solution (add 0.0001+step(acc\_c)\* to my formula) correct ?  
Is there a more elegant solution ? like specify i want to model acc\_h only for acc\_c \> 0 ?

---

<div class="post-metadata">

**Author:** ![scholz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/scholz/32/14298_2.png) [@scholz](https://discourse.mc-stan.org/u/scholz)\
**Post date:** [October 6, 2021, 10:13am UTC](https://discourse.mc-stan.org/t/initialization-problems-using-brms-with-gamma-distribution-and-identity-link/24621/4 "2021-10-06T10:13:03Z")

</div>

I don’t think I can really help you with that as I have no experience with that kind of advanced formulas.
