# Request for average predictive comparisons in rstanarm and brms

**URL:** <https://discourse.mc-stan.org/t/request-for-average-predictive-comparisons-in-rstanarm-and-brms/12477>\
**Category:** brms\
**Created:** [January 1, 2020, 9:36pm UTC](https://discourse.mc-stan.org/t/request-for-average-predictive-comparisons-in-rstanarm-and-brms/12477 "2020-01-01T21:36:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewgelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrewgelman/32/1577_2.png) [@andrewgelman](https://discourse.mc-stan.org/u/andrewgelman)\
**Post date:** [January 1, 2020, 9:36pm UTC](https://discourse.mc-stan.org/t/request-for-average-predictive-comparisons-in-rstanarm-and-brms/12477/1 "2020-01-01T21:36:22Z")

</div>

Dear rstanarm and brms developers:

There is a request for average predictive comparisons; see this comment: [https://statmodeling.stat.columbia.edu/2019/12/29/do-we-still-recommend-average-predictive-comparisons-click-here-to-find-the-surprising-answer/#comment-1216517](https://statmodeling.stat.columbia.edu/2019/12/29/do-we-still-recommend-average-predictive-comparisons-click-here-to-find-the-surprising-answer/#comment-1216517)  
Key quote: “There are many variations of this, and is quite useful for non-linear (e.g. logit) models. It appears to have become very very popular and many of us would be giddy if rstanarm or brms would support a full-featured ‘margins’ like command. Many researchers use Stata largely because of this feature.”

The method is described in this paper from awhile ago:  
[http://www.stat.columbia.edu/~gelman/research/published/ape17.pdf](http://www.stat.columbia.edu/~gelman/research/published/ape17.pdf)  
David Chudzicki wrote a related R package a few years back:  
[https://statmodeling.stat.columbia.edu/2014/06/17/average-predictive-comparisons-r-david-chudzicki-writes-package/](https://statmodeling.stat.columbia.edu/2014/06/17/average-predictive-comparisons-r-david-chudzicki-writes-package/)

---

<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:** [January 2, 2020, 7:49pm UTC](https://discourse.mc-stan.org/t/request-for-average-predictive-comparisons-in-rstanarm-and-brms/12477/2 "2020-01-02T19:49:43Z")

</div>

Is this something similar as discussed in the brms issue [https://github.com/paul-buerkner/brms/issues/552](https://github.com/paul-buerkner/brms/issues/552)?

---

<div class="post-metadata">

**Author:** ![andrewgelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrewgelman/32/1577_2.png) [@andrewgelman](https://discourse.mc-stan.org/u/andrewgelman)\
**Post date:** [January 2, 2020, 10:15pm UTC](https://discourse.mc-stan.org/t/request-for-average-predictive-comparisons-in-rstanarm-and-brms/12477/3 "2020-01-02T22:15:15Z")

</div>

Hi, yes, it’s the same sort of thing. There are lots of options regarding details (as discussed in our paper), but I figure that any implementation is better than nothing!

---

<div class="post-metadata">

**Author:** ![legault](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@legault](https://discourse.mc-stan.org/u/legault)\
**Post date:** [January 14, 2020, 5:53pm UTC](https://discourse.mc-stan.org/t/request-for-average-predictive-comparisons-in-rstanarm-and-brms/12477/4 "2020-01-14T17:53:49Z")

</div>

As others have discussed, the need to marginalize over continuous predictors makes implementation challenging. Estimating the joint distribution of the predictors is also a big problem:

1. The Mahalanobis distance is appropriate when the joint distribution is multivariate normal, but such a distribution is unlikely for many predictors (perhaps this is arguable).

2. The joint distribution of the predictors in the experiment may not reflect the joint distribution of the predictors in the “real world”. For example, an experiment might pair certain temperature treatments with different humidity treatments, but those temperature-humidity pairings may be unlikely in the real world. Hence, conclusions based on the joint distribution in the experiment may not be meaningful outside the context of the experiment.

---

<div class="post-metadata">

**Author:** ![dilsherdhillon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dilsherdhillon/32/4464_2.png) [@dilsherdhillon](https://discourse.mc-stan.org/u/dilsherdhillon)\
**Post date:** [January 22, 2020, 2:40pm UTC](https://discourse.mc-stan.org/t/request-for-average-predictive-comparisons-in-rstanarm-and-brms/12477/5 "2020-01-22T14:40:29Z")

</div>

I found a gist with an implementation of Average marginal effects

> <https://gist.github.com/jackobailey/0982c89326c36b12d6fa6d6f182189be>

---

<div class="post-metadata">

**Author:** ![belay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/belay/32/4288_2.png) [@belay](https://discourse.mc-stan.org/u/belay)\
**Post date:** [August 22, 2020, 9:55pm UTC](https://discourse.mc-stan.org/t/request-for-average-predictive-comparisons-in-rstanarm-and-brms/12477/6 "2020-08-22T21:55:39Z")

</div>

Hi all,

Sorry to bring this topic back. Is there any update specially for random effect models.

B
