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

Marginalize over varying effects #489

Closed
paul-buerkner opened this issue Aug 7, 2018 · 5 comments
Closed

Marginalize over varying effects #489

paul-buerkner opened this issue Aug 7, 2018 · 5 comments

Comments

@paul-buerkner
Copy link
Owner

paul-buerkner commented Aug 7, 2018

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 compute mu = 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

u <- rnorm(<large number>, 0, sd_u)
# or some other way to sample values of u
mu = mean(g(b0 + u + b1 * x))

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.

@realkrantz
Copy link

realkrantz commented Nov 14, 2018

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?

@paul-buerkner
Copy link
Owner Author

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.

@realkrantz
Copy link

I will do that. Thanks

@jackobailey
Copy link

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.

@paul-buerkner
Copy link
Owner Author

This has been implemented via emmeans support in PR #1177. One can now choose the varying effects to marginalize over by specifying the re_formula argument in emmeans(brmsfit, ...) accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants