# Help refining priors

**URL:** <https://discourse.pymc.io/t/help-refining-priors/5690>\
**Category:** Questions\
**Created:** [August 24, 2020, 10:38am UTC](https://discourse.pymc.io/t/help-refining-priors/5690 "2020-08-24T10:38:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattiasthalen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mattiasthalen/32/2362_2.png) [@mattiasthalen](https://discourse.pymc.io/u/mattiasthalen)\
**Post date:** [August 24, 2020, 10:38am UTC](https://discourse.pymc.io/t/help-refining-priors/5690/1 "2020-08-24T10:38:32Z")

</div>

I’ve defined a model where I currently have my two priors defined as such:

```
alpha = pm.Normal(‘alpha’, mu = 0.0, sigma = 100)
beta = pm.Normal(‘beta’, mu = 0.0, sigma = 100)

```

Now, there are two things I know for certain about the underlying data and that is that alpha is positive and beta is negative.

Shouldn’t I then be able to improve my priors with this knowledge?

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [August 24, 2020, 10:51am UTC](https://discourse.pymc.io/t/help-refining-priors/5690/2 "2020-08-24T10:51:02Z")

</div>

Hi Mattias,  
You certainly can, and I’m guessing you can also refine your priors on the standard deviations – right now, they are saying that 95% of the probability mass is expected between -200 and +200.  
Depending on what’s best appropriate for your problem, I think an exponential or a gamma will be useful.

Chapter 5 of [Richard McElreath’s _Rethinking 2_](http://xcelab.net/rm/statistical-rethinking/) has a very good portion about choice of priors – here is the [port to PyMC3](https://github.com/pymc-devs/resources/blob/master/Rethinking_2/Chp_05.ipynb) 😉  
Hope this helps 🖖

---

<div class="post-metadata">

**Author:** ![mattiasthalen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mattiasthalen/32/2362_2.png) [@mattiasthalen](https://discourse.pymc.io/u/mattiasthalen)\
**Post date:** [August 24, 2020, 8:16pm UTC](https://discourse.pymc.io/t/help-refining-priors/5690/3 "2020-08-24T20:16:52Z")

</div>

Hi Alex,

Had a look at gamma and it does seem to work for my alpha (intercept), but not sure if it’s right for my beta (slope) as it should be negative.

---

<div class="post-metadata">

**Author:** ![ckrapu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ckrapu/32/1366_2.png) [@ckrapu](https://discourse.pymc.io/u/ckrapu)\
**Post date:** [August 24, 2020, 10:17pm UTC](https://discourse.pymc.io/t/help-refining-priors/5690/4 "2020-08-24T22:17:04Z")

</div>

You can turn a positive prior over `x` into a negative prior by flipping the sign and creating a new deterministic variable, e.g. `x_negative = pm.Deterministic('x_negative', -x)`

---

<div class="post-metadata">

**Author:** ![mattiasthalen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mattiasthalen/32/2362_2.png) [@mattiasthalen](https://discourse.pymc.io/u/mattiasthalen)\
**Post date:** [August 25, 2020, 8:03am UTC](https://discourse.pymc.io/t/help-refining-priors/5690/5 "2020-08-25T08:03:30Z")

</div>

Oh, but wouldn’t that also flip y\_est?

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [August 25, 2020, 8:12am UTC](https://discourse.pymc.io/t/help-refining-priors/5690/6 "2020-08-25T08:12:27Z")

</div>

I don’t think so. I suppose `y = alpha + beta_negative * x`

---

<div class="post-metadata">

**Author:** ![mattiasthalen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mattiasthalen/32/2362_2.png) [@mattiasthalen](https://discourse.pymc.io/u/mattiasthalen)\
**Post date:** [August 25, 2020, 3:56pm UTC](https://discourse.pymc.io/t/help-refining-priors/5690/7 "2020-08-25T15:56:18Z")

</div>

Seems to be working quite well. Thanks a lot!

---

<div class="post-metadata">

**Author:** ![mattiasthalen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mattiasthalen/32/2362_2.png) [@mattiasthalen](https://discourse.pymc.io/u/mattiasthalen)\
**Post date:** [August 25, 2020, 7:58pm UTC](https://discourse.pymc.io/t/help-refining-priors/5690/8 "2020-08-25T19:58:09Z")

</div>

@ckrapu could you expand on why it’s defined as a deterministic var?

---

<div class="post-metadata">

**Author:** ![ckrapu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ckrapu/32/1366_2.png) [@ckrapu](https://discourse.pymc.io/u/ckrapu)\
**Post date:** [August 25, 2020, 8:32pm UTC](https://discourse.pymc.io/t/help-refining-priors/5690/9 "2020-08-25T20:32:05Z")

</div>

You wouldn’t have to use a Deterministic variable, but it would probably enable you to parse the results more quickly. If you are interested in the value of `beta_negative`, then it might be nice to be able to rapidly extract that from the trace using `trace['beta_negative']` rather than having to remember to do `-1*trace['beta']` every time you want to look at the posterior summaries of \beta.

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [August 27, 2020, 8:18am UTC](https://discourse.pymc.io/t/help-refining-priors/5690/10 "2020-08-27T08:18:15Z")

</div>

You’re welcome @mattiasthalen – welcome to Bayesian magical land 😉 🤩

---

<div class="post-metadata">

**Author:** ![mattiasthalen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mattiasthalen/32/2362_2.png) [@mattiasthalen](https://discourse.pymc.io/u/mattiasthalen)\
**Post date:** [August 27, 2020, 9:06am UTC](https://discourse.pymc.io/t/help-refining-priors/5690/11 "2020-08-27T09:06:50Z")

</div>

Thanks, love the podcast btw!

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [August 28, 2020, 11:49am UTC](https://discourse.pymc.io/t/help-refining-priors/5690/12 "2020-08-28T11:49:41Z")

</div>

Ah thanks! Nice to meet listeners here 😉
