# Migrating simple Poisson/Gamma model from Pymc3

**URL:** <https://discourse.julialang.org/t/migrating-simple-poisson-gamma-model-from-pymc3/52243>\
**Category:** General Usage\
**Tags:** turing\
**Created:** [December 22, 2020, 7:53pm UTC](https://discourse.julialang.org/t/migrating-simple-poisson-gamma-model-from-pymc3/52243 "2020-12-22T19:53:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lucca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucca/32/20460_2.png) [@Lucca](https://discourse.julialang.org/u/Lucca)\
**Post date:** [December 22, 2020, 7:53pm UTC](https://discourse.julialang.org/t/migrating-simple-poisson-gamma-model-from-pymc3/52243/1 "2020-12-22T19:53:41Z")

</div>

Hello!  
Following [this](https://github.com/pymc-devs/resources/blob/master/BDA3/chap_02.ipynb) Pymc3 notebook, I have been trying to migrate some of the models to Turing.

The _ **Estimating a rate from Poisson data: an idealized example** _ example is a simple bayesian model with a Gamma prior for a Poisson Distribution. On my turing implementation I get a theta with ~2.4 mean. On the notebook, the mean is around 0.8.

My code:

```julia
@model poisson_model(y) = begin
    theta_1 ~ Gamma(3, 5)
    y ~ Poisson(2*theta_1)
end
model_p = poisson_model(3)
chain2 = sample(model_p, NUTS(), 50000);

```

What could be wrong with my code? Sorry if it is simple, I am new to Julia and turing 🙂

Pymc3 code for reference:

```julia
with pm.Model() as poisson_model:
    theta = pm.Gamma('theta', alpha=3, beta=5)
    post = pm.Poisson('post', mu=2 * theta, observed=3)

```

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [December 22, 2020, 8:00pm UTC](https://discourse.julialang.org/t/migrating-simple-poisson-gamma-model-from-pymc3/52243/2 "2020-12-22T20:00:44Z")

</div>

Welcome. One possibility is that the Gamma distribution in Python and Julia are parameterized differently. What is the mean of your Gamma prior in PyMC3?

```julia
using Distributions
mean(Gamma(3 ,5))

```

Output:  
`15.0`

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [December 22, 2020, 8:06pm UTC](https://discourse.julialang.org/t/migrating-simple-poisson-gamma-model-from-pymc3/52243/3 "2020-12-22T20:06:29Z")

</div>

Indeed, that appears to be the case:

```julia
using Turing, Random

@model poisson_model(y) = begin
    theta_1 ~ Gamma(3, 1/5)
    y ~ Poisson(2*theta_1)
end
Random.seed!(58844)
model_p = poisson_model(3)
chain2 = sample(model_p, NUTS(), 50000);

```

Output:

```julia
Summary Statistics
  parameters mean std naive_se mcse ess rhat 
      Symbol Float64 Float64 Float64 Float64 Float64 Float64 

     theta_1 0.8557 0.3500 0.0016 0.0023 23968.1460 1.0000

Quantiles
  parameters 2.5% 25.0% 50.0% 75.0% 97.5% 
      Symbol Float64 Float64 Float64 Float64 Float64 

     theta_1 0.3098 0.6009 0.8094 1.0604 1.6653

```

---

<div class="post-metadata">

**Author:** ![Lucca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucca/32/20460_2.png) [@Lucca](https://discourse.julialang.org/u/Lucca)\
**Post date:** [December 22, 2020, 8:07pm UTC](https://discourse.julialang.org/t/migrating-simple-poisson-gamma-model-from-pymc3/52243/4 "2020-12-22T20:07:33Z")

</div>

Perfect! Thank you!!
