6.1 One syntax to rule them all
PyMC has a very simple and expressive syntax that allows us to build arbitrary models. That’s usually a blessing, but it can be a burden too. Bambi instead focuses on regression models, and this restriction leads to a more focused syntax and features, as we will see.
Bambi uses a Wilkinson-formula syntax similar to the one used by many R packages like nlme, lme4, and brms. Let’s assume data
is a pandas DataFrame like the one shown in Table 6.1.
y | x | z | g | |
0 | -0.633494 | -0.196436 | -0.355148 | Group A |
1 | 2.32684 | 0.0163941 | -1.22847 | Group B |
2 | 0.999604 | 0.107602 | -0.391528 | Group C |
3 | -0.119111 | 0.804268 | 0.967253 | Group A |
4 | 2.07504 | 0.991417 | 0.590832 | Group B |
5 | -0.412135 | 0.691132 | -2.13044 | Group C |
Table 6.1: A dummy pandas DataFrame
Using this data, we want to build a linear model that predicts y
from x
. Using PyMC, we would do something like the model in the following code block:
Code 6.1
with pm.Model() as lm:Â
  ...