# Re-coding a partial pooling from pymc to pymc3

**URL:** <https://discourse.pymc.io/t/re-coding-a-partial-pooling-from-pymc-to-pymc3/2137>\
**Category:** Questions\
**Created:** [November 2, 2018, 5:06pm UTC](https://discourse.pymc.io/t/re-coding-a-partial-pooling-from-pymc-to-pymc3/2137 "2018-11-02T17:06:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hwassner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hwassner/32/527_2.png) [@hwassner](https://discourse.pymc.io/u/hwassner)\
**Post date:** [November 2, 2018, 5:06pm UTC](https://discourse.pymc.io/t/re-coding-a-partial-pooling-from-pymc-to-pymc3/2137/1 "2018-11-02T17:06:56Z")

</div>

I’d like to recode an old pymc partial pooling model in pymc3 :

Here is the model an explanations :  
[http://sl8r000.github.io/ab\_testing\_statistics/use\_a\_hierarchical\_model/](http://sl8r000.github.io/ab_testing_statistics/use_a_hierarchical_model/)

I have a very hard time to understand this old pymc syntax :

```auto
@pymc.stochastic(dtype=np.float64)
def hyperpriors(value=[1.0, 1.0]):
    a, b = value[0], value[1]
    if a <= 0 or b <= 0:
        return -np.inf
    else:
        return np.log(np.power((a + b), -2.5))

a = hyperpriors[0]
b = hyperpriors[1]

```

I think I understand the function (It’s a logp for a pair of a & b parameters), so I guess that I’ll have to translate that in a ‘Deterministic’…

But I totally don’t understant the last 2 lines : It look like a function call but I where are the function parameters ? And what does means the [0] and [1] there?

Any help will be appreciated.

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [November 2, 2018, 5:41pm UTC](https://discourse.pymc.io/t/re-coding-a-partial-pooling-from-pymc-to-pymc3/2137/2 "2018-11-02T17:41:21Z")

</div>

> [@hwassner](#):
>
> But I totally don’t understant the last 2 lines : It look like a function call but I where are the function parameters ? And what does means the [0] and [1] there?

Dont know about pymc2 that much, but I think it generate a 2d random variable, and unpack it with the last two lines.

To rewrite it in PyMC3 I guess the most straightforward way is to write it as a Potential, something like:

```python
with pm.Model() as m:
    a = pm.HalfFlat('a')
    b = pm.HalfFlat('b')
    true_rates = pm.Beta('true_rates', a, b, shape=10)
    observed_values = pm.Binomial('observed_values', n=trials, p=true_rates, observed=successes)
    pm.Potential('hyperprior', tt.log(tt.power((a + b), -2.5)))
    trace = pm.sample()

```
