# Ordered Simplex

**URL:** <https://discourse.mc-stan.org/t/ordered-simplex/1835>\
**Category:** Modeling\
**Created:** [September 8, 2017, 6:37pm UTC](https://discourse.mc-stan.org/t/ordered-simplex/1835 "2017-09-08T18:37:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![quebbs](https://avatars.discourse-cdn.com/v4/letter/q/d6d6ee/32.png) [@quebbs](https://discourse.mc-stan.org/u/quebbs)\
**Post date:** [September 8, 2017, 6:37pm UTC](https://discourse.mc-stan.org/t/ordered-simplex/1835/1 "2017-09-08T18:37:53Z")

</div>

I am interested in an ordered simplex - I have a mixture model, and am getting switching of parameters for different threads, but believe an ordered simplex would solve that issue. Is it possible to enforce this ordering? Is enforcing an ordering on a simplex a bad idea on a mixture model?

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [September 8, 2017, 6:49pm UTC](https://discourse.mc-stan.org/t/ordered-simplex/1835/2 "2017-09-08T18:49:32Z")

</div>

It is quite possible to use an ordered simplex if you do

```
data {
  int<lower=1> K;
  vector<lower=0>[K] alpha;
}
parameters {
  positive_ordered[K] lambda;
}
transformed parameters {
  simplex[K] pi = lambda / sum(lambda);
}
model {
  // implies pi ~ dirichlet(alpha)
  target += gamma_lpdf(lambda | alpha, 1);
  // use pi in your likelihood
}

```

Opinions differ as to whether this is a disaster or works perfectly fine.

---

<div class="post-metadata">

**Author:** ![quebbs](https://avatars.discourse-cdn.com/v4/letter/q/d6d6ee/32.png) [@quebbs](https://discourse.mc-stan.org/u/quebbs)\
**Post date:** [September 8, 2017, 7:14pm UTC](https://discourse.mc-stan.org/t/ordered-simplex/1835/3 "2017-09-08T19:14:54Z")

</div>

Thank you - this is a creative approach. I will give it a try to see if it leads to disaster ;)

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [September 10, 2017, 2:31pm UTC](https://discourse.mc-stan.org/t/ordered-simplex/1835/4 "2017-09-10T14:31:34Z")

</div>

> [@bgoodri](#):
>
> Opinions differ as to whether this is a disaster or works perfectly fine.

Why wouldn’t this work? It’s identified through the prior.

Of course, the prior will matter here for fitting.

A simpler alternative

```no-highlight
parameters {
  positive_ordered[K] pi_raw;
  ...
transformed parameters {
  ordered[K] pi = softmax(pi_raw);

```

won’t work because the `pi_raw` parameters won’t be identified. And you can’t just add a zero value to identify if you want to preserve orderedness. You can’t just put a prior on `pi` here without including the log Jacobian of the softmax transform, either.

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [September 10, 2017, 3:16pm UTC](https://discourse.mc-stan.org/t/ordered-simplex/1835/5 "2017-09-10T15:16:06Z")

</div>

> [@Bob\_Carpenter](#):
>
> Why wouldn’t this work? It’s identified through the prior.

Something about when you have so much data that the posterior distribution of `pi` has very little variance, then NUTS has to take many very small steps to navigate through the values of `lambda` that is consistent with both that value of `pi` and the gamma prior on `lambda`.
