Hi Luis,
I’m glad you were able to get it to work on the simpler case. I’d like to make a more general comment that may be helpful as you think about this going forward. You use a lot of terminology that jumps between ideas in the code that you are using such as ‘returns control to’ and your specific representation of the model ‘horizontal and vertical transitions,’ model representation, ‘model has a logic’ etc.
It might be helpful to separate but related steps such as:
- The underlying data generation process
- The statistical framework used to represent this
- The code that you are using to generate data from two
- The parameterization of the model (should be very similar to 2)
- The Stan code that you use to infer the model
If you use a particular framework to generate data from a model, you do not need to follow that exact framework in your Stan code in order to get the same posterior distribution, and often that won’t be the most efficient way to infer the parameters. The link for your data generation code actually seems quite complicated, as a bit of a benchmark, I have been working with a gaussian process model and I have a 30 line R program to generate data from the model, but the corresponding Stan code is over 300 lines (Bob Carpenter tells me this is on the extreme ends of things as far as Stan programs go), but the point is - don’t expect a 1-1 correspondence between the length of your R program to generate the data, and length of Stan program to infer the parameters.