# Sensible prior for logistic regression with one or no input variable

**URL:** <https://discourse.pymc.io/t/sensible-prior-for-logistic-regression-with-one-or-no-input-variable/8394>\
**Category:** Questions\
**Created:** [December 2, 2021, 2:02pm UTC](https://discourse.pymc.io/t/sensible-prior-for-logistic-regression-with-one-or-no-input-variable/8394 "2021-12-02T14:02:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leomein](https://avatars.discourse-cdn.com/v4/letter/l/87869e/32.png) [@leomein](https://discourse.pymc.io/u/leomein)\
**Post date:** [December 2, 2021, 2:02pm UTC](https://discourse.pymc.io/t/sensible-prior-for-logistic-regression-with-one-or-no-input-variable/8394/1 "2021-12-02T14:02:47Z")

</div>

Hi all,

I have what feels like a very basic question. I am trying to get the HPD interval for the mean of a binary outcome (i.e. the interval for a probability value). I am currently running a logistic regression with just one input variable (which is used for stratifying the data). So essentially I just want to model probability values for different subgroups within the data. Currently I am using bambi and it uses a Normal prior. I was wondering if this is how one would normally go about this or if there’s another way (maybe another prior) to do this better? Also, if I just have the outcome values and no input variable (so just want to estimate the overall HPD interval for the probability for the whole dataset), how would I do that ideally? I used a Beta prior with alpha=beta=1 to do this for now but don’t know if this is sensible.

Thank you!

---

<div class="post-metadata">

**Author:** ![vb690](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/vb690/32/3432_2.png) [@vb690](https://discourse.pymc.io/u/vb690)\
**Post date:** [December 3, 2021, 10:28am UTC](https://discourse.pymc.io/t/sensible-prior-for-logistic-regression-with-one-or-no-input-variable/8394/2 "2021-12-03T10:28:57Z")

</div>

Hello 🙂

if I understood this correctly, maybe this is what you are looking for

```auto
# simulate data
import numpy as np

import pymc3 as pm

groups = {
    0: 0.3,
    1: 0.1,
    2: 0.7
}
n = 100

groups_idx = []
observed = []

for group, p in groups.items():
    
    groups_idx.extend([group] * n)
    observed.extend([np.random.binomial(1, p) for sample in range(n)])
    
groups_idx = np.array(groups_idx)
observed = np.array(observed)

# build the model and sample from it
with pm.Model() as bernoulli_model:
    
    groups_data = pm.Data(
        'Groups Indices',
        groups_idx
    )
    observed_data = pm.Data(
        'Observed Data',
        observed
    )
    
    # weakly informative prior centred on 0.5
    p = pm.Beta(
        'p',
        2,
        2,
        shape=(len(groups))
    )
    
    observed = pm.Bernoulli(
        'Observed',
        p=p[groups_data],
        observed=observed_data
    )
    
with bernoulli_model:
    
    trace_bernoulli = pm.sample()

```

 ![Capture](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/c/c5773ec41798b01e986d305b7d099a01d29a00fa.jpeg)  
 ![index](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/8/832b500a25ce362daf72d59d06a456bb959c1574.png)

If what I illustrated reflects your case, you could also model this as a binomial model summing the outcomes of the bernoulli trials over groups.

---

<div class="post-metadata">

**Author:** ![leomein](https://avatars.discourse-cdn.com/v4/letter/l/87869e/32.png) [@leomein](https://discourse.pymc.io/u/leomein)\
**Post date:** [December 5, 2021, 7:01pm UTC](https://discourse.pymc.io/t/sensible-prior-for-logistic-regression-with-one-or-no-input-variable/8394/3 "2021-12-05T19:01:53Z")

</div>

Great, thanks a lot! That’s exactly what I was looking for 🙂
