# Multilevel models

**URL:** <https://discuss.bayesflow.org/t/multilevel-models/210>\
**Category:** General\
**Created:** [November 11, 2025, 9:04am UTC](https://discuss.bayesflow.org/t/multilevel-models/210 "2025-11-11T09:04:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Username1](https://avatars.discourse-cdn.com/v4/letter/u/ee59a6/32.png) [@Username1](https://discuss.bayesflow.org/u/Username1)\
**Post date:** [November 11, 2025, 9:04am UTC](https://discuss.bayesflow.org/t/multilevel-models/210/1 "2025-11-11T09:04:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul.buerkner](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@paul.buerkner](https://discuss.bayesflow.org/u/paul.buerkner)\
**Post date:** [November 12, 2025, 7:27am UTC](https://discuss.bayesflow.org/t/multilevel-models/210/2 "2025-11-12T07:27:47Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![Username1](https://avatars.discourse-cdn.com/v4/letter/u/ee59a6/32.png) [@Username1](https://discuss.bayesflow.org/u/Username1)\
**Post date:** [November 12, 2025, 10:29am UTC](https://discuss.bayesflow.org/t/multilevel-models/210/3 "2025-11-12T10:29:20Z")

</div>

Hi Paul,

Thank you. I await the implementation with great anticipation 🙂

Best Regards

---

<div class="post-metadata">

**Author:** ![KLDivergence](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/kldivergence/32/15_2.png) [@KLDivergence](https://discuss.bayesflow.org/u/KLDivergence)\
**Post date:** [November 21, 2025, 7:39pm UTC](https://discuss.bayesflow.org/t/multilevel-models/210/4 "2025-11-21T19:39:32Z")

</div>

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](https://arxiv.org/abs/2505.14429)), which will be available on the `dev` branch soon.
