I come across two methods of specifying Bayesian hierarchical model in the book "Bayesian methods: a social and behavioural approach" (2015), third edition by Jeff Gill.
The three examples from the book (as below) are about Bayesian hierarchical models. Key differences in the models have been circled in red:
In Example 1, the nesting structure is expressed through the nested indexing alpha[state.id[i]]. The two for loops are specified separately. However, in Example 2 and 3, the hierarchical structures are specified through nested for loop rather than nested indexing. Besides, there are i and j appearing within the same square brackets (Q[i,j] in Example 2 and mu[i,j] in Example 3), as contrast to Example 1 where only one index (either i or j) appears in the square brackets.
MY QUESTION: What are the differences between nested indexing VS. nested for loop when specifying the Bayesian hierarchical model? Can Example 1 be modelled in a way similar to Example 2 and 3 or vice versa? How can I choose between the two methods?
I will provide you the full example if you feel more comfortable knowing details of the examples.
Thank you!


