# LogitNormal vs. Beta vs. Logistic

**URL:** <https://discourse.pymc.io/t/logitnormal-vs-beta-vs-logistic/1727>\
**Category:** Questions\
**Created:** [August 14, 2018, 5:53pm UTC](https://discourse.pymc.io/t/logitnormal-vs-beta-vs-logistic/1727 "2018-08-14T17:53:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![samslusher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/samslusher/32/2301_2.png) [@samslusher](https://discourse.pymc.io/u/samslusher)\
**Post date:** [August 14, 2018, 5:53pm UTC](https://discourse.pymc.io/t/logitnormal-vs-beta-vs-logistic/1727/1 "2018-08-14T17:53:32Z")

</div>

Hi -

I am attempting to predict a percentage variable (bounded by 0 and 1, with no instances of 0 or 1 occurring), using a continuous normal variable and a bounded normal variable. Here is my code:

```
from theano import shared

homespread = shared(data.HomeSpread.values)
homeodds = shared(data.ImpliedHomeOdds.values)
y=data.MidML_Home.values

with pm.Model() as model: 

    # Define priors
    intercept = pm.Normal('Intercept', 0, sd=10)
    x0 = pm.Normal('x0', mu=0, sd=20)
    x1 = pm.Normal('x1', mu=0.5, sd=.1)
    
    y_est = pm.math.sigmoid(intercept+x0*homespread+x1*homeodds)
    model_err = pm.Normal('model_err',mu=0.5,sd=.1)

    # Data likelihood
    y_like = pm.LogitNormal('y_like',mu=y_est,sd=model_err,observed=y)

    trace = pm.sample(20000,tune=5000)

```

Using the LogitNormal does not seem to (1) appropriately handle independent values above 0 and (2) predicts a tighter posterior than occurs in reality, as tested via:

```
homespread.set_value(np.array([-7.]))
homeodds.set_value(np.array([.5]))

ppc = pm.sample_ppc(trace, model=model, samples=10000)
_, ax = plt.subplots(figsize=(12, 6))
ax.hist([n.mean() for n in ppc['y_like']], bins=19, alpha=0.5)
ax.axvline(data[data['HomeSpread']==-7.].MidML_Home.mean())
ax.set(title='Posterior predictive of the mean', xlabel='mean(x)', ylabel='Frequency');

```

Any suggestions for how to best go about modelling this problem in PyMC3 would be much appreciated. Of note, I have tried using a Beta distribution in place of the LogitNormal as well, but struggled identifying the appropriate alpha/beta priors and ended up with a posterior far too tight around .5.

Thanks!

---

<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:** [August 15, 2018, 4:32am UTC](https://discourse.pymc.io/t/logitnormal-vs-beta-vs-logistic/1727/2 "2018-08-15T04:32:52Z")

</div>

Since there is no data and figure it is a bit difficult to say what is the problem, so just FYI you can parameterize the Beta distribution with mean and sd, as long as the sd satisfy that sd \< (1-mu)\*mu
