# Simple Dirichlet model with partial pooling

**URL:** https://discourse.pymc.io/t/simple-dirichlet-model-with-partial-pooling/2769
**Category:** Questions
**Created:** [February 21, 2019, 6:21am UTC](https://discourse.pymc.io/t/simple-dirichlet-model-with-partial-pooling/2769 "2019-02-21T06:21:02Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![lmann](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@lmann](https://discourse.pymc.io/u/lmann)
#### Post date: [February 21, 2019, 6:21am UTC](https://discourse.pymc.io/t/simple-dirichlet-model-with-partial-pooling/2769/1 "2019-02-21T06:21:02Z")

</div>

I am trying to implement a simple Dirichlet model with partial pooling to estimate changes to preferences between two samples of count data (think vote intentions between two polls as an example). I can estimate the preferences for candidates A,B and C in two polls using the simple models describe below. I try to implement a hierarchical model and I was expecting that it would show the means for a candidate in each poll would shrink towards the mean for the candidate in both polls… However in my case, there is no change to the means. I am assuming I have incorrectly setup the model.

I was following similar ideas as to what is described here: [https://stats.stackexchange.com/questions/44144/multinomial-dirichlet-model-with-hyperprior-distribution-on-the-concentration-pa](https://stats.stackexchange.com/questions/44144/multinomial-dirichlet-model-with-hyperprior-distribution-on-the-concentration-pa)

A reproducible example is:

```python
#data, row = "poll", candidate = column
counts=np.array([[317,120,563],[308,85,607]])

shape=counts.shape
totals=np.sum(counts,axis=1)

#Non-pooled model
with pm.Model() as simple_model:
    
    theta = pm.Dirichlet("theta", a=np.ones(shape),shape=shape)
    results = pm.Multinomial("results", n=totals, p=theta, observed=counts)
    
with simple_model:
    simple_model = pm.sample(draws=1000)

#check means:
#pm.summary(simple_model)

#Hierarchical model
with pm.Model() as hierarchical_model:
 
    beta = pm.Dirichlet("beta", a=np.ones(shape[1]),shape=shape[1])
    lambd = pm.Exponential('lambd',np.ones(shape[1]),shape=shape[1])
    
    theta = pm.Dirichlet("theta", beta*lambd,shape=shape)
    results = pm.Multinomial("results", n=totals, p=theta, observed=counts)
    
with hierarchical_model:
    hierarchical_model_trace = pm.sample(draws=10000)
    
#check means:
#pm.summary(hierarchical_model_trace)

```

---

<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: [February 22, 2019, 7:32am UTC](https://discourse.pymc.io/t/simple-dirichlet-model-with-partial-pooling/2769/2 "2019-02-22T07:32:42Z")

</div>

The estimation of `theta` in both model should be nearly identical based on the way you model it (essentially, you have one free parameter for one observation). However, if you look at `beta` and `lambd`, you should see some partial pooling property like shrinkage (wont be too obvious as well as there is not a lot of data).
