# Plot stacked / averaged models

**URL:** <https://discourse.mc-stan.org/t/plot-stacked-averaged-models/10869>\
**Category:** brms\
**Created:** [September 6, 2019, 7:15pm UTC](https://discourse.mc-stan.org/t/plot-stacked-averaged-models/10869 "2019-09-06T19:15:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zachary\_Horne](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zachary_horne/32/5830_2.png) [@Zachary\_Horne](https://discourse.mc-stan.org/u/Zachary_Horne)\
**Post date:** [September 6, 2019, 7:15pm UTC](https://discourse.mc-stan.org/t/plot-stacked-averaged-models/10869/1 "2019-09-06T19:15:57Z")

</div>

Please also provide the following information in addition to your question:

- Operating System: Win 10
- brms Version: 2.10

Hi,

I’m looking to plot / predict from stacked or averaged models in brms. I’ve computed model weights and two models have approximately similar model weights. My understanding is that in this situation, I should stack these models to take into account the uncertainty about the “preferred” model. The problem I’m having is, how do I go from getting the model weights (e.g., m1 = .54, m2, .46) to plotting / prediction of the stacked model. Any help on this would be super helpful; I’m new to stacking / model averaging so apologies if my questions don’t quite make sense.

Zach

---

<div class="post-metadata">

**Author:** ![erognli](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/erognli/32/5181_2.png) [@erognli](https://discourse.mc-stan.org/u/erognli)\
**Post date:** [September 7, 2019, 7:30am UTC](https://discourse.mc-stan.org/t/plot-stacked-averaged-models/10869/2 "2019-09-07T07:30:50Z")

</div>

Hi! Question makes perfect sense. I looked into this some time ago, and it’s surprisingly straightforward.

Sample predictions from the models in proportion to the model weights (set the number of samples equal to some number multiplied by the model weight), and simply combine the draws to get the predictive distribution of the stacked models.

---

<div class="post-metadata">

**Author:** ![Zachary\_Horne](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zachary_horne/32/5830_2.png) [@Zachary\_Horne](https://discourse.mc-stan.org/u/Zachary_Horne)\
**Post date:** [September 7, 2019, 7:32am UTC](https://discourse.mc-stan.org/t/plot-stacked-averaged-models/10869/3 "2019-09-07T07:32:32Z")

</div>

I see. I was thinking I could do something like this but wasn’t totally sure.

---

<div class="post-metadata">

**Author:** ![paul.buerkner](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/paul.buerkner/32/3303_2.png) [@paul.buerkner](https://discourse.mc-stan.org/u/paul.buerkner)\
**Post date:** [September 7, 2019, 7:34am UTC](https://discourse.mc-stan.org/t/plot-stacked-averaged-models/10869/4 "2019-09-07T07:34:04Z")

</div>

Brms has a method for this task already. I think it is called pp\_average.

---

<div class="post-metadata">

**Author:** ![erognli](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/erognli/32/5181_2.png) [@erognli](https://discourse.mc-stan.org/u/erognli)\
**Post date:** [September 7, 2019, 7:34am UTC](https://discourse.mc-stan.org/t/plot-stacked-averaged-models/10869/5 "2019-09-07T07:34:23Z")

</div>

I know what you mean - it kind of feels too simple.

---

<div class="post-metadata">

**Author:** ![Zachary\_Horne](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zachary_horne/32/5830_2.png) [@Zachary\_Horne](https://discourse.mc-stan.org/u/Zachary_Horne)\
**Post date:** [September 7, 2019, 7:37am UTC](https://discourse.mc-stan.org/t/plot-stacked-averaged-models/10869/6 "2019-09-07T07:37:21Z")

</div>

I was playing with ppaverage today but wasn’t fully understanding the samples (?) it was returning.

---

<div class="post-metadata">

**Author:** ![Zachary\_Horne](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zachary_horne/32/5830_2.png) [@Zachary\_Horne](https://discourse.mc-stan.org/u/Zachary_Horne)\
**Post date:** [September 8, 2019, 2:50pm UTC](https://discourse.mc-stan.org/t/plot-stacked-averaged-models/10869/7 "2019-09-08T14:50:14Z")

</div>

Is it accurate to assume that if you use pp\_average you doing Bayesian Model Averaging or does it just depend on if you specify weights yourself after, for example, using loo\_model\_weights (method = “stacking”)?

---

<div class="post-metadata">

**Author:** ![Zachary\_Horne](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zachary_horne/32/5830_2.png) [@Zachary\_Horne](https://discourse.mc-stan.org/u/Zachary_Horne)\
**Post date:** [September 8, 2019, 3:42pm UTC](https://discourse.mc-stan.org/t/plot-stacked-averaged-models/10869/8 "2019-09-08T15:42:30Z")

</div>

Or maybe you can use control in pp\_average to do stacking, pseudobma etc?

---

<div class="post-metadata">

**Author:** ![paul.buerkner](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/paul.buerkner/32/3303_2.png) [@paul.buerkner](https://discourse.mc-stan.org/u/paul.buerkner)\
**Post date:** [September 16, 2019, 7:21pm UTC](https://discourse.mc-stan.org/t/plot-stacked-averaged-models/10869/9 "2019-09-16T19:21:23Z")

</div>

This depends on the type of weights you use. For standard BMA you need to use weights = “marglik” but I don’t actually recommend using it. Rather go for the default `loo2`.
