# Brms marginal\_effects plots not reflecting model estimates

**URL:** <https://discourse.mc-stan.org/t/brms-marginal-effects-plots-not-reflecting-model-estimates/27836>\
**Category:** brms\
**Tags:** brms\
**Created:** [June 15, 2022, 2:04pm UTC](https://discourse.mc-stan.org/t/brms-marginal-effects-plots-not-reflecting-model-estimates/27836 "2022-06-15T14:04:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomH](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@TomH](https://discourse.mc-stan.org/u/TomH)\
**Post date:** [June 15, 2022, 2:04pm UTC](https://discourse.mc-stan.org/t/brms-marginal-effects-plots-not-reflecting-model-estimates/27836/1 "2022-06-15T14:04:34Z")

</div>

Hi All,

I’m hoping that somebody can help me with an issue. I’m running a lognormal model in brms to measure the population level effects of covariates on my response variable, which is ‘detection delay’. Among the covariates in the model is ‘endemicity’, which refers to one of two datasets that I’m trying to compare through the model estimates (low vs. high).

The estimates of the posterior mean and diagnostics all check out, and I exponentiate the estimates to give the relative differences for each covariate. However, when I generate two and three way effect plots using the marginal\_effects function, the output doesn’t match the model estimates (see estimates and plots below), i.e. the detection delay estimates in the ‘high endemicity’ dataset are lower than the ‘low endemicity’ dataset, which is the opposite of what I would expect from the model estimates (this is using the default method: posterior\_epred, but is also the case with method = posterior\_linpred).

Interestingly, I have only experienced this issue since incorporating heterogeneous variances  
for the two data sets in the model, i.e. including sigma ~ 0 + endemicity. Without specifying sigma, the differences in expected mean response values of the PPD in the effect plots reflect the model estimates, with ‘high endemicity’ showing higher detection delay overall regardless of the other covariates shown in the effect plot.

Could anyone help me explain why this is happening?

@paul.buerkner @LucC

```nohighlight
mod_brmslognorm_final <- brm(detection delay ~ age +
                                     endemicity +
                                     sex +
                                     who_subtype,
                                     sigma ~ 0 + endemicity),
                                     iter = 10000,
                                     warmup = 1000,
                                     init = 0,
                                     prior <- c(set_prior("normal(0,1e+06)", class = "b")),
                                     data = mydata_full, 
                                     family = "lognormal")

```

 ![R_estimates_brms](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/4/473c235ee78514a76bad3b2fde23abacf2e2cee6.jpeg)

 ![R_plot_brms](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/b/b34bf00a7df896fe645e5c81a8b0e3551280bf60.jpeg)

Operating System: Windows 10 Pro  
brms Version: 2.17.0

---

<div class="post-metadata">

**Author:** ![LucC](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/lucc/32/4475_2.png) [@LucC](https://discourse.mc-stan.org/u/LucC)\
**Post date:** [June 17, 2022, 7:34am UTC](https://discourse.mc-stan.org/t/brms-marginal-effects-plots-not-reflecting-model-estimates/27836/2 "2022-06-17T07:34:27Z")

</div>

Hi @TomH,

Recap of the live discussion we had about this:

The exponent of coefficients in a log-normal regression model (with linear predictor on the log scale) represent the expected relative change in the outcome for every unit change in a predictor. For this type of model, the expectation, when based on the model.coefficients only, is the **geometric mean**. In other words, your model indicates that the expected detection delay in terms geometric mean is higher in highly endemic areas.

We hypothesised that the marginal effects plot is plotting the expectation of the log-normal distribution in terms of the arithmetic mean, which is exp(log(\mu\_{geom}) + \sigma^2\_2 / 2). Because \sigma^2\_2 varies by value of the endemicitt predictor, we thought that the marginal effects plot took this into account when plotting the expectations. But then the plot on the log scale (“method = posterior\_linpred”) should not account for this, presumably. But the latter plot also showed this unexpected opposite pattern compared to the model coefficients.

@paul.buerkner any idea what might be going on? What is the marginal effects function plotting exactly when it comes to expectations of log-normal models?

---

<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:** [June 20, 2022, 7:45am UTC](https://discourse.mc-stan.org/t/brms-marginal-effects-plots-not-reflecting-model-estimates/27836/3 "2022-06-20T07:45:21Z")

</div>

By default, we will use method = posterior\_epred which is indeed the (arithmetic) mean of the response distribution, that also takes into account sigma, as you say. If method = posterior\_linpred we should see predictions of the main parameter “mu” by default, which is \log(\mu\_{\rm geom}) in your notation. If you think this is not the case, I would need to see a reprex that demonstrates this.

---

<div class="post-metadata">

**Author:** ![TomH](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@TomH](https://discourse.mc-stan.org/u/TomH)\
**Post date:** [June 22, 2022, 4:21pm UTC](https://discourse.mc-stan.org/t/brms-marginal-effects-plots-not-reflecting-model-estimates/27836/4 "2022-06-22T16:21:35Z")

</div>

Thanks very much for clarifying @paul.buerkner, we’ve figured it out now. Using method = posterior\_linpred indeed gives us the geometric mean of the response distribution, the exponent of which gives an expected detection delay that is higher in highly endemic areas as indicated by the model coefficients.
