# Turing fitting a Weibull model

**URL:** <https://discourse.julialang.org/t/turing-fitting-a-weibull-model/43693>\
**Category:** General Usage\
**Created:** [July 26, 2020, 1:46am UTC](https://discourse.julialang.org/t/turing-fitting-a-weibull-model/43693 "2020-07-26T01:46:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ekidando20](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ekidando20](https://discourse.julialang.org/u/ekidando20)\
**Post date:** [July 26, 2020, 1:46am UTC](https://discourse.julialang.org/t/turing-fitting-a-weibull-model/43693/1 "2020-07-26T01:46:26Z")

</div>

I am trying to fit a Weibull distribution in Turing. Sometimes when I rerun the model I get the following error.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/0/3051df5a4ccaca2f5507f954f4e3a7770f949f9d.png)

Any suggestions to avoid above error? I am also getting a similar error when I fit a regression model (see it below) with the explanatory variables.

scale = (intercept .+ XIncidenttype \* aIncidentType .+  
bDetectionMethod \* data[:, :Detection\_Method] .+  
Xseverity \* cseverity .+  
XAgency \* dAgency  
)

```
shape ~ truncated(Normal(0, 100), 0, Inf)
mu = exp.(scale)

y .~ Weibull.(shape, mu)

```

Thank you.

---

<div class="post-metadata">

**Author:** ![joshualeond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshualeond/32/230_2.png) [@joshualeond](https://discourse.julialang.org/u/joshualeond)\
**Post date:** [July 26, 2020, 1:57am UTC](https://discourse.julialang.org/t/turing-fitting-a-weibull-model/43693/2 "2020-07-26T01:57:52Z")

</div>

I think you need to make sure the parameters on the Weibull distribution can’t be zero. So set the priors slightly above zero.

---

<div class="post-metadata">

**Author:** ![ekidando20](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ekidando20](https://discourse.julialang.org/u/ekidando20)\
**Post date:** [July 26, 2020, 2:20am UTC](https://discourse.julialang.org/t/turing-fitting-a-weibull-model/43693/3 "2020-07-26T02:20:18Z")

</div>

Thank you. May I ask how? I am new to Turing.

---

<div class="post-metadata">

**Author:** ![joshualeond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshualeond/32/230_2.png) [@joshualeond](https://discourse.julialang.org/u/joshualeond)\
**Post date:** [July 26, 2020, 2:25am UTC](https://discourse.julialang.org/t/turing-fitting-a-weibull-model/43693/4 "2020-07-26T02:25:47Z")

</div>

Sure, so just modify the truncated bit from your code to something slightly higher than zero:

```julia
#priors
shape ~ truncated(Normal(0, 100), 0.01, Inf)
scale ~ truncated(Normal(0, 100), 0.01, Inf)

```

---

<div class="post-metadata">

**Author:** ![ekidando20](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ekidando20](https://discourse.julialang.org/u/ekidando20)\
**Post date:** [July 26, 2020, 2:42am UTC](https://discourse.julialang.org/t/turing-fitting-a-weibull-model/43693/5 "2020-07-26T02:42:03Z")

</div>

Thank you very much. It works on fitting the simulated data (distribution). But, on the regression, I am still getting the same error. Any suggestion?

scale = (  
intercept .+  
XIncidenttype \* aIncidentType .+  
bDetectionMethod \* data[:, :Detection\_Method] .+  
Xseverity \* cseverity  
)

```
shape ~ truncated(Normal(0.5, 100), 0.01, Inf)
mu = exp.(scale)

y .~ Weibull.(shape, m)

```

---

<div class="post-metadata">

**Author:** ![joshualeond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshualeond/32/230_2.png) [@joshualeond](https://discourse.julialang.org/u/joshualeond)\
**Post date:** [July 26, 2020, 3:02am UTC](https://discourse.julialang.org/t/turing-fitting-a-weibull-model/43693/6 "2020-07-26T03:02:34Z")

</div>

It’s a little hard to say because I don’t think the whole model is shown here. I’d recommend checking out the linear regression example on the Turing site though:  
[https://turing.ml/dev/tutorials/5-linearregression/](https://turing.ml/dev/tutorials/5-linearregression/)

Specifically, I’d look at the model specification section.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [July 26, 2020, 3:05am UTC](https://discourse.julialang.org/t/turing-fitting-a-weibull-model/43693/7 "2020-07-26T03:05:25Z")

</div>

> [@ekidando20](#):
>
> `mu = exp.(scale)`

Try

```julia
m = exp.(scale) .+ 0.01

```

---

<div class="post-metadata">

**Author:** ![ekidando20](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ekidando20](https://discourse.julialang.org/u/ekidando20)\
**Post date:** [July 26, 2020, 2:52pm UTC](https://discourse.julialang.org/t/turing-fitting-a-weibull-model/43693/8 "2020-07-26T14:52:06Z")

</div>

Thank you very much. It works.
