# Ordering using rstan

**URL:** <https://discourse.mc-stan.org/t/ordering-using-rstan/1273>\
**Category:** General\
**Created:** [July 18, 2017, 9:51pm UTC](https://discourse.mc-stan.org/t/ordering-using-rstan/1273 "2017-07-18T21:51:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shy](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@Shy](https://discourse.mc-stan.org/u/Shy)\
**Post date:** [July 18, 2017, 9:51pm UTC](https://discourse.mc-stan.org/t/ordering-using-rstan/1273/1 "2017-07-18T21:51:31Z")

</div>

Hi all,

I am running a Baynesian model with rstan. It runs fine, but how do I interpret my “input.to.stan$data”?  
For example: In my $Site region, my n is 35, and my sites are 7, but my sites are not ordered alphabetically. Instead they are ordered:  
77777 55555 44444 11111 33333 22222 66666

Does this mean that 7 listed is actually Site 7, 5 is Site 5, etc from my data? or is 7 actually alpha 7, and 5 is alpha 5 from my printed rstan results summary?

Thank you for your help and time!

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [July 18, 2017, 10:28pm UTC](https://discourse.mc-stan.org/t/ordering-using-rstan/1273/2 "2017-07-18T22:28:20Z")

</div>

What model are you using? Care to post it here in a code block? Hard to tell without this information – with Stan it all comes down to how the model is written.

Or are you using Stan as part of a larger package?

---

<div class="post-metadata">

**Author:** ![Shy](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@Shy](https://discourse.mc-stan.org/u/Shy)\
**Post date:** [July 19, 2017, 7:30pm UTC](https://discourse.mc-stan.org/t/ordering-using-rstan/1273/3 "2017-07-19T19:30:14Z")

</div>

Hi bbbales2,

I am using a Bayesian Hierarchical model, and my code work up to my input.to.stan ← stan.input(), fit1 and fit2.

However, when I run my input.to.stan$data to make sure my inputs are correct, my data shows that my response variable is not listed alphabetically in the original order. Instead it is listed:

> $site  
> [1] 7 7 7 7 7 7 5 5 5 5 5 5 4 4 4 4 4 4 4 1 1 1 1 1 1 3 3 3 3 3 3 3 2 2 2 2 2 2 6 6 6 6 6 [33] 6 6

I am unsure if this list means that from my print (fit2), is alpha [7] my first site, alpha [5] is my second site, etc, or is \> $site 7 my 7th site, \> $site 5 my 5th site, etc.

Hope this helps, thanks again.

---

<div class="post-metadata">

**Author:** ![bbbales2](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bbbales2/32/77_2.png) [@bbbales2](https://discourse.mc-stan.org/u/bbbales2)\
**Post date:** [July 19, 2017, 10:02pm UTC](https://discourse.mc-stan.org/t/ordering-using-rstan/1273/4 "2017-07-19T22:02:46Z")

</div>

Is `input.to.stan` the variable where you’re storing your input you want to pass to Stan? If so, then if input.to.stan$data is out of order, it’s some other bit of non-Stan code that’s causing this. Stan shouldn’t write over its input data.

Does that help? It’s still not totally clear what’s going on here. Posting your model + code etc would make it easier to answer.

---

<div class="post-metadata">

**Author:** ![Shy](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@Shy](https://discourse.mc-stan.org/u/Shy)\
**Post date:** [July 21, 2017, 4:53pm UTC](https://discourse.mc-stan.org/t/ordering-using-rstan/1273/5 "2017-07-21T16:53:54Z")

</div>

Yes! that does help, I did input my data in the wrong part of the code, which was giving a different order of data. I was able to rectify the problem :)

Thanks!
