# Priors for Dirichlet distribution

**URL:** https://discourse.pymc.io/t/priors-for-dirichlet-distribution/3210
**Category:** Questions
**Created:** [May 6, 2019, 11:21am UTC](https://discourse.pymc.io/t/priors-for-dirichlet-distribution/3210 "2019-05-06T11:21:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![manhnguyen48](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/manhnguyen48/32/1829_2.png) [@manhnguyen48](https://discourse.pymc.io/u/manhnguyen48)
#### Post date: [May 6, 2019, 11:21am UTC](https://discourse.pymc.io/t/priors-for-dirichlet-distribution/3210/1 "2019-05-06T11:21:14Z")

</div>

I’ve got some binary questions that asked some respondents in an area. My goal is to estimate the average proportion of saying yes to binary questions for all areas.  
My data frame has the shape of (N, 5) with N being the number of areas, 4 columns responding to the total number of people saying yes in each area and the 5th column (named sizes) for the total number of people asked per area.

some data processing:

```
var_list = (y1,y2,y3,y4)
vals = data.loc[:,var_list]
id_array = data.index.to_list()

```

I’ve had success modelling one binary outcome with hierarchical partial pooling as follows:

```
 with pm.Model() as model:
        u = pm.Uniform('global_p',lower=0.0, upper=1.0)
        v = pm.Gamma('v', alpha=1, beta=20)

        alpha = u*v
        beta = v*(1-u)
        p_observed = pm.Beta("p_observed", alpha=alpha, beta=beta)
        
        
        observed_data = pm.Binomial("observed_data",
                             n = data.sizes.values,
                             p = p_observed, 
                             observed = vals.values)

```

However, now that I want to model 4 binary variables at a time (y1, y2, y3,y4) as they are mutually exclusive (sum(p1,p2,p3,p4) = 1). I’ve tried the Dirichlet-Multinomial as follows but I can’t find the priors for the Dirichlet distribution to perform partial pooling as in the case of one binary variable:

```
        with pm.Model() as model:
            p_observed = pm.Dirichlet('p_observed', a=np.ones(4), 
                                     shape=(data.shape[0],4))
        
            observed_data = pm.Multinomial('observed_data', p=p_observed[id_array], 
                                    n=data.sizes.values,
                                    observed=vals.values) `     

```

Any comments would be much appreciated!  
Many thanks,

---

<div class="post-metadata">

### Author: ![chartl](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/chartl/32/1515_2.png) [@chartl](https://discourse.pymc.io/u/chartl)
#### Post date: [May 6, 2019, 6:01pm UTC](https://discourse.pymc.io/t/priors-for-dirichlet-distribution/3210/2 "2019-05-06T18:01:36Z")

</div>

The direct generalization of your previous prior would be something like

```auto
u = pm.Dirichlet('dprior_p', np.ones(4, dtype=np.float32), shape=(4,))
v = pm.Gamma('dprior_v', alpha=1, beta=20, shape=(4,))
p_observed = pm.Dirichlet('proportions', a=u*v, shape=(4,))

```

It may be more effective to constrain the prior a little bit and let the shape of `v` be `(1,)`.

There are certainly other things to do as well, but this should give you something to go on. Let me know how these work.

---

<div class="post-metadata">

### Author: ![manhnguyen48](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/manhnguyen48/32/1829_2.png) [@manhnguyen48](https://discourse.pymc.io/u/manhnguyen48)
#### Post date: [May 6, 2019, 8:02pm UTC](https://discourse.pymc.io/t/priors-for-dirichlet-distribution/3210/3 "2019-05-06T20:02:41Z")

</div>

It does work indeed! Thank you!
