Stancode in brms


I am learning Bayesian Regression Modeling with Statistical Rethinking.

I want to try to write stancode from now on to learn some basics there and I think it is better than e.g. using the formula as you can do in brms because you have to specify everything explicitly.

However, I love the brms package and have my workflow with that. Is there a way to give brms just the stan file instead of the formula and fit the model? I know that is possible with rstan but I think brms has some functions that do not work with rstan that were part of my workflow.

If you have alternative options about how I should learn stan, feel free to suggest. My idea was to just now write those models that I can understand in stan and use brms with that.

brms provides its extra functionality by controlling how the models are written, so I don’t think there’s any way to feed a plain Stan model to brms and get the features out.

But what were those functions? Maybe there’s another way to solve this.

1 Like

Hi bbales2,

ok, thanks for letting me know. Yes there are defnitively alternatives. I am talking about extracting posterior samples and creating summaries etc. I had written some functions that used brms functions to achieve this. I will look up the same functions for rstan. Because the (I assume) rstan is the best way to go. Please correct me if I am wrong or there are better/smarter ways in the long run.

You could also check out the posterior package which you can find on the stan-dev github page.


Thanks Paul and bbales2,

I found the posterior package and I found all kinds of new developments that I was unaware of. I assume that for me as an R user cmdstanR is the way to go to be future proof.

1 Like

@paul.buerkner and @bbbales2:

What is the easiest way to compute posterior means in “complicated” analysis with many interactions? Or other way to ask: Is there a similar function such as posterior_linpred for cmdstanr or that has been implemented in the posterior package?

For many analyses I could do it manually but it can become cumbersome quickly with increasing complexity.