Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full support for Bayesian models when backend = "marginaleffects" #302

Open
Tracked by #289
DominiqueMakowski opened this issue Jan 9, 2025 · 7 comments
Open
Tracked by #289
Labels
Enhancement 💥 Implemented features can be improved or revised
Milestone

Comments

@DominiqueMakowski
Copy link
Member

This issue might be related to parameters(). Sometimes we get indices like pd, sometimes not.

df <- iris
df$Condition <- rep(c("A", "B", "C"), length.out=150)

m1 <- brms::brm(Sepal.Width ~ Species * Sepal.Length, data=df, refresh=0)


# pd is present
modelbased::estimate_slopes(m1, trend="Sepal.Length", by="Species")
#> Estimated Marginal Effects
#> 
#> Species    | Coefficient |       95% CI |     pd
#> ------------------------------------------------
#> setosa     |        0.80 | [0.57, 1.01] |   100%
#> versicolor |        0.32 | [0.17, 0.47] | 99.98%
#> virginica  |        0.23 | [0.11, 0.35] |   100%
#> Marginal effects estimated for Sepal.Length

# BUT, pd not present here
trends <- modelbased::get_marginaltrends(m1, trend="Sepal.Length", by="Species")
parameters::parameters(trends)
#> # Fixed Effects
#> 
#> Parameter    |    Species | Coefficient |       95% CI
#> ------------------------------------------------------
#> Sepal.Length |     setosa |        0.80 | [0.57, 1.01]
#> Sepal.Length | versicolor |        0.32 | [0.17, 0.47]
#> Sepal.Length |  virginica |        0.23 | [0.11, 0.35]


m2 <- brms::brm(Condition ~ Species, data=df, family=brms::categorical(refcat="A"), refresh=0)

# pd not present
modelbased::estimate_slopes(m2, trend="Species", backend="marginaleffects")
#> Estimated Marginal Effects
#> 
#> Response |          Comparison | Coefficient |        95% CI
#> ------------------------------------------------------------
#> A        | versicolor - setosa |    1.25e-03 | [-0.19, 0.18]
#> A        |  virginica - setosa |       -0.02 | [-0.20, 0.17]
#> B        | versicolor - setosa |       -0.02 | [-0.21, 0.16]
#> B        |  virginica - setosa |   -4.60e-04 | [-0.19, 0.19]
#> C        | versicolor - setosa |        0.02 | [-0.16, 0.20]
#> C        |  virginica - setosa |        0.02 | [-0.17, 0.20]
#> Marginal effects estimated for Species

Created on 2025-01-09 with reprex v2.1.1

@strengejacke
Copy link
Member

I think in the .format_marginaleffects_*() internals, we only call parameters::parameters(). For emmeans, we call bayestestR::describe_posterior() for Bayesian models, which we should also do for marginaleffects.

The implementation is not feature complete yet, we still have to put some work into the .format_marginaleffects_*() internals.

@DominiqueMakowski
Copy link
Member Author

It could be done at parameters()' level though no? I would have expected parameters() to return these indices

@strengejacke
Copy link
Member

Yes, for Bayesian models. But not for marginaleffects object yet (I think @vincentarelbundock implemented the marginaleffects methods in parameters, and currently, they're calling tidy(), which does not return those indices - in bayestestR, @mattansb implemented methods for marginaleffects objects that processed Bayesian models).

@mattansb
Copy link
Member

mattansb commented Jan 9, 2025

Yes, I think Bayesian emmeans and Bayesian marginaleffects objects should be processes the same through bayestestR.

@DominiqueMakowski
Copy link
Member Author

DominiqueMakowski commented Jan 11, 2025

Bayesian emmeans and Bayesian marginaleffects objects should be processes the same through bayestestR.

Why not through parameters (which relies on bayestestR)?

@mattansb
Copy link
Member

Should be, but is sounds like {parameters} is not using {bayestestR}?

@strengejacke
Copy link
Member

Should be, but is sounds like {parameters} is not using {bayestestR}?

#302 (comment)

@strengejacke strengejacke changed the title parameters(marginal trends) does not (always) return Bayesian sig indices Full support for Bayesian models when backend = "marginaleffects" Jan 13, 2025
@strengejacke strengejacke added the Enhancement 💥 Implemented features can be improved or revised label Jan 13, 2025
@strengejacke strengejacke added this to the 1.0.0 milestone Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement 💥 Implemented features can be improved or revised
Projects
None yet
Development

No branches or pull requests

3 participants