Ordering using rstan

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!

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?

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:

[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.

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.

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 :)


1 Like