How to recreate a model in Bambi in pymc

I came across the Bambi library and have been playing with it using the sleepstudy data.

Using a relatively simple mode: bmb.Model("Reaction ~ 0 + Days + (1 | Subject)", sleep), how might I recreate it using base pymc? The bambi model produces the following graph

which, I can’t seem to figure out how to reproduce in base pymc. In particular, I’m confused how the deterministic block functions in this case.

The deterministic block is implementing the “non-centered parameterization” of a hierarchical prior. There’s a nice discussion of this in the radon example notebook. McElreath also has a detailed discussion of why you want to do this in this video.


This is the source code of a talk I gave showing how to do the same model with both PyMC and Bambi

Let me know if that helps :slight_smile:

Edit: This may also help unfinished-ideas/sparse.ipynb at main · bambinos/unfinished-ideas · GitHub

Notice the goal there was to replace some indexing operation with a sparse dot product. But there you have how to reproduce the model with PyMC