# How to put prior knowledge in to student-t model

**URL:** <https://discourse.pymc.io/t/how-to-put-prior-knowledge-in-to-student-t-model/5060>\
**Category:** Questions\
**Created:** [May 11, 2020, 1:56am UTC](https://discourse.pymc.io/t/how-to-put-prior-knowledge-in-to-student-t-model/5060 "2020-05-11T01:56:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![huwendi2006](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/huwendi2006/32/2151_2.png) [@huwendi2006](https://discourse.pymc.io/u/huwendi2006)\
**Post date:** [May 11, 2020, 1:56am UTC](https://discourse.pymc.io/t/how-to-put-prior-knowledge-in-to-student-t-model/5060/1 "2020-05-11T01:56:48Z")

</div>

the model is like this:

with pm.Model() as model\_t:  
mu = pm.Uniform(‘mu’, 0, 1)  
sigma = pm.HalfNormal(‘sigma’, sd = 10)  
nu = pm.Exponential(‘nu’, 1/30)  
y = pm.StudentT(‘y’, mu=mu, sd=sigma, nu=nu, observed=data)  
trace\_t = pm.sample(1100)  
chain\_t = trace\_t[100:]

Now I know the prior mu-3\*sigma should less than 0.001, how should I put this knowledge in to this model?

Thanks!

---

<div class="post-metadata">

**Author:** ![sammosummo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/sammosummo/32/96_2.png) [@sammosummo](https://discourse.pymc.io/u/sammosummo)\
**Post date:** [May 18, 2020, 3:44pm UTC](https://discourse.pymc.io/t/how-to-put-prior-knowledge-in-to-student-t-model/5060/2 "2020-05-18T15:44:31Z")

</div>

You could use a `Potential` to set the likelihood to `-inf` whenever the constraint is not satisfied.

---

<div class="post-metadata">

**Author:** ![huwendi2006](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/huwendi2006/32/2151_2.png) [@huwendi2006](https://discourse.pymc.io/u/huwendi2006)\
**Post date:** [May 19, 2020, 2:15am UTC](https://discourse.pymc.io/t/how-to-put-prior-knowledge-in-to-student-t-model/5060/3 "2020-05-19T02:15:59Z")

</div>

Hi sammosummo:  
I’m sorry I didn’t get your word, could you be more specific? thanks

---

<div class="post-metadata">

**Author:** ![nkaimcaudle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/nkaimcaudle/32/2142_2.png) [@nkaimcaudle](https://discourse.pymc.io/u/nkaimcaudle)\
**Post date:** [May 19, 2020, 6:42am UTC](https://discourse.pymc.io/t/how-to-put-prior-knowledge-in-to-student-t-model/5060/4 "2020-05-19T06:42:30Z")

</div>

If you want a hard constraint then you can use `Potential` like @sammosummo suggested

example code:

> ```
> with pm.Model() as model_t:
> mu = pm.Uniform('mu', 0, 1)
> sigma = pm.HalfNormal('sigma', sd = 10)
> nu = pm.Exponential('nu', 1/30)
> y = pm.StudentT('y', mu=mu, sd=sigma, nu=nu, observed=data)
> constraint = pm.Potential('constraint', tt.switch(mu - 3*sigma > 0.001, -np.inf, 0))
> trace_t = pm.sample(1000)
> 
> ```

In general such hard constraints are not recommended as they have no derivative and jump either side of the boundary.

You don’t need to drop the first 100 samples from trace\_t. `pm.sample()` will already run 1000 burnin steps followed by 1000 samples. What is returned is just the 1000 samples.
