Multilevel models

Hi,

I have recently been reading up on the amortized bayesian inference litterature and find it an interesting fit to my nonlinear mixed effects model.

I was reading your paper “amortized bayesian multilevel models“ and thought it very interesting and relevant for me, but was saddened to find out that the implementation is not available in BayesFlow 2.0 (which I otherwise thing is an awesome software)

My question in therefore what the status is on bringing this into BayesFlow 2.0?
The question is not meant to stress you out, just interested in a status update, because if it is far away then I may try to implement a rudimentary version myself.

For a little bit of context: I am trying to fit a nonlinear mixed effects model on some chemical data where I have multiple batches and would like to predict the long-term behaviour from short-term observations. I would then like to answer questions such as, how many batches and observations per batch do I need (and potentially other design variables) for reliable predictions.

I could do this is Stan, but find that it is cumbersome to fit my model in many design configurations and do SBC after.

Thank you

Hello and welcome to Bayesflow discourse!

Good timing. We are only few weeks (or even less) away from a PR that brings multilevel models into the dev version of Bayesflow 2.0. :slight_smile:

Hi Paul,

Thank you. I await the implementation with great anticipation :slight_smile:

Best Regards

1 Like

Hi @Username1, in the meantime, you can always “simulate” the approach by training two networks sequentially from a two-level model with hyperparameters, parameters_i, and data_i.

  1. Train a standard posterior network that can estimate p(hyperparameters | all data).
  2. Train a standard posterior network that can estimate p(parameters_i | data_i, hyperparameters)

During inference, use ancestral sampling in a custom loop:

  1. Sample hyperparameters from the first network given all data
  2. Sample parameters for each data unit given the hyperparameters

The interface will provide a general way to do that, including compositional inference ([2505.14429] Compositional amortized inference for large-scale hierarchical Bayesian models), which will be available on the dev branch soon.