# Imposing order constraint

**URL:** <https://discourse.pymc.io/t/imposing-order-constraint/3067>\
**Category:** Questions\
**Created:** [April 7, 2019, 9:20am UTC](https://discourse.pymc.io/t/imposing-order-constraint/3067 "2019-04-07T09:20:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/adamh/32/1684_2.png) [@adamh](https://discourse.pymc.io/u/adamh)\
**Post date:** [April 7, 2019, 9:20am UTC](https://discourse.pymc.io/t/imposing-order-constraint/3067/1 "2019-04-07T09:20:22Z")

</div>

I’m trying to understand how can I impose an order constraint on two different RVs. Specifically, I have RVs `x_1` and `x_2` which are the results of two different GLMs (with shapes ~ (100,)), and I know that “in the real world”, `x_1 > x_2`. I’ve tried the following ideas:

1. Use `pm.Potential`. This caused some convergence issues, and @junpenglao also suggested this is not the best approach [here](https://discourse.pymc.io/t/dependence-of-convergence-on-random-seed/3031/4).
2. Use `transform.Order` - again, following @junpenglao’s advice. Didn’t understand how to apply it for the case of two different RVs (and not different entries in the same multivariate distribution).
3. Model `x_2` using the GLM, and model `delta` instead of `x_1`, such that `x_1 = x_2 + delta`. This makes sure `x_1 > x_2`, but then I’m not sure how to interpret the distributions over the coefficients of the GLMs.

Is there any recommended approach? Or something different altogether?

---

<div class="post-metadata">

**Author:** ![aakhmetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/aakhmetz/32/1500_2.png) [@aakhmetz](https://discourse.pymc.io/u/aakhmetz)\
**Post date:** [April 7, 2019, 1:41pm UTC](https://discourse.pymc.io/t/imposing-order-constraint/3067/2 "2019-04-07T13:41:30Z")

</div>

I remember the last paragraph of [https://colindcarroll.com/2018/07/20/why-im-excited-about-pymc3-v3.5.0/](https://colindcarroll.com/2018/07/20/why-im-excited-about-pymc3-v3.5.0/) was quite helpful

---

<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:** [April 7, 2019, 2:40pm UTC](https://discourse.pymc.io/t/imposing-order-constraint/3067/3 "2019-04-07T14:40:21Z")

</div>

> [@adamh](#):
>
> Model `x_2` using the GLM, and model `delta` instead of `x_1` , such that `x_1 = x_2 + delta` . This makes sure `x_1 > x_2` , but then I’m not sure how to interpret the distributions over the coefficients of the GLMs.

I would try with this. For interpretation of the coefficient you can always add the delta to x\_1 and avoid interpreting the delta directly.

---

<div class="post-metadata">

**Author:** ![adamh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/adamh/32/1684_2.png) [@adamh](https://discourse.pymc.io/u/adamh)\
**Post date:** [April 9, 2019, 6:54am UTC](https://discourse.pymc.io/t/imposing-order-constraint/3067/4 "2019-04-09T06:54:42Z")

</div>

Thanks! Introducing the “delta probability” variable indeed gives me what I want, at the cost of the lesser interpretability (since now I don’t have a “explicit” GLM for `x_1`) and longer sampling times (perhaps the `pm.math.minimum(x_2+delta,1)` is giving the sampler a hard time?).
