# Estimated Marginal Means of Non-Linear Custom Models

**URL:** <https://discourse.mc-stan.org/t/estimated-marginal-means-of-non-linear-custom-models/28928>\
**Category:** General\
**Tags:** emmeans, brms\
**Created:** [September 25, 2022, 4:13am UTC](https://discourse.mc-stan.org/t/estimated-marginal-means-of-non-linear-custom-models/28928 "2022-09-25T04:13:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Zelko](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/matt_zelko/32/10218_2.png) [@Matt\_Zelko](https://discourse.mc-stan.org/u/Matt_Zelko)\
**Post date:** [September 25, 2022, 4:13am UTC](https://discourse.mc-stan.org/t/estimated-marginal-means-of-non-linear-custom-models/28928/1 "2022-09-25T04:13:29Z")

</div>

Hi all,

I have a non-linear model specified similarly to Markus’ “real-world” example in:  
[https://cran.r-project.org/web/packages/brms/vignettes/brms\_nonlinear.html](https://cran.r-project.org/web/packages/brms/vignettes/brms_nonlinear.html)

Using Markus’ example, is there a package or code recommendation that would allow for marginal effects to be expressed on “AY”? The emmeans package does not support such models, and whilst the “conditional\_effects” function in brms shows the years separately, I am trying to estimate the differences between them over time.

Cheers,

Matt

---

<div class="post-metadata">

**Author:** ![AWoodward](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/awoodward/32/13015_2.png) [@AWoodward](https://discourse.mc-stan.org/u/AWoodward)\
**Post date:** [September 25, 2022, 1:43pm UTC](https://discourse.mc-stan.org/t/estimated-marginal-means-of-non-linear-custom-models/28928/2 "2022-09-25T13:43:11Z")

</div>

I think it will be easiest to implement this yourself via `fitted()` or `posterior_epred()`. You can obtain estimates conditional on the group effects by specifying `re.formula`. If you want to obtain posterior estimates of functions of the parameters, then you can do this from the samples.

---

<div class="post-metadata">

**Author:** ![Matt\_Zelko](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/matt_zelko/32/10218_2.png) [@Matt\_Zelko](https://discourse.mc-stan.org/u/Matt_Zelko)\
**Post date:** [September 26, 2022, 3:59am UTC](https://discourse.mc-stan.org/t/estimated-marginal-means-of-non-linear-custom-models/28928/3 "2022-09-26T03:59:15Z")

</div>

Hey Andrew,

Thanks for your thoughts regarding my issue. In lieu of any other input, I will implement this approach myself.

Cheers,

Matt
