-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
Marginalize over varying effects #489
Comments
Just for clarification. Would this feature as it is now proposed here make the marginal_effects estimate a literal average marginal effect as discussed on discourse.mc-stan.org (as in the packages margins and Modmarg)? If not, should I open a new issue or these aspects I am suggesting can be incorporated under the current issue? Also, any idea when we will have this feature fully implemented in brms? |
I don't have the time to look at this right now. You can open a new issue explaining in detail what you want to have implemented. Then we will see if it's the same as in this issue. |
I will do that. Thanks |
You could adapt the code I submitted (and that you reposted in the issue above) to do this quite easily without having to rely on Monte Carlo integration. It would still be computationally expensive where the varying effects have a lot of levels and/or the data are large, but probably less so than Monte Carlo integration and easier to implement. |
This has been implemented via emmeans support in PR #1177. One can now choose the varying effects to marginalize over by specifying the |
In
predict
and related functions, we currently have the option to either condition on varying effects (i.e. include them in the predictions) or to simply ignore them (i.e. conditioning on zero). Instead of ignoring, we should actually marginalize over them, which is something different in models with non-identity links. In the past, this distinction has (understandably) let to confusion not only for brms users.I argue we should add the possibility of marginalizing over varying effects via monte-carlo integration, which is the only technique that seems feasible to me for brms models of arbitrary multilevel structure.
Suppose we have a logistic regression with a varying intercept and a constant slope of
x
, then we need to computemu = integral g(b0 + u + b1 * x) f(u) du
where g is the response function (logistic function in this case) and f is the density of the varying intercepts u.Monte-carlo integration to approximate mu could be done via
This is computationally demanding since we have to do this marginalization for each posterior draw, but one may be able to vectorize most of the computation at the expense of increased RAM requirements.
The text was updated successfully, but these errors were encountered: