This is an attempt to implement a brms-like library in Python.
It allows Bayesian regression models to be specified using (a subset of) the lme4 syntax. Given such a description and a pandas data frame, the library generates model code and design matrices, targeting either Pyro or NumPyro.
Here are some example formulae that the system can handle:
Formula | Description |
---|---|
y ~ x |
Population-level effects |
y ~ 1 + x |
|
y ~ x1:x2 |
Interaction between variables |
y ~ 1 + x0 + (x1 \| z) |
Group-level effects |
y ~ 1 + x0 + (1 + x1 \| z) |
|
y ~ 1 + x0 + (1 + x1 \|\| z) |
No correlation between group coefficients |
y ~ 1 + x0 + (1 + x1 \| z1:z2) |
Grouping by multiple factors (untested) |
y ~ 1 + x0 + (x1 \| z0) + (1 + x2 \|\| z1) |
Combinations of the above |
Custom priors can be specified at various levels of granularity. For example, users can specify:
Users can give multiple such specifications and they combine in a sensible way.
The library supports models with either (uni-variate) Gaussian or Binomial (inc. Bernoulli) distributed responses.
The Pyro back end supports both NUTS and SVI for inference. The NumPyro backend supports only NUTS.
The library includes the following functions for working with posteriors:
marginals(...)
: This produces a model summary similar to that
obtained by doing fit <- brm(...) ; fit$fit
in brms.fitted(...)
: This implements some of the functionality available
in brms through
the fitted
and predict
methods.sin(x1)
or I(x1*x2)
are not supported.*
operator is not supported. (Though the model y ~ 1 + x1*x2
can be specified with the formula y ~ 1 + x1 + x2 + x1:x2
.)/
operator is not supported. (Though the model y ~ ... | g1/g2
can be specified with the formula y ~ (... | g1) + (... | g1:g2)
.)y ~ x - 1
fitted
function does not implement all of the functionality of
its analogue in brms.