question about re_formula in marginal_effects.brmsfit

588 views
Skip to first unread message

John David Coppin

unread,
Feb 13, 2018, 10:07:01 AM2/13/18
to brms-users
First of all, I love the brms package! This package has allowed me to fit some models for my data that I have not been able to adequately fit before. As an applied statistician who has been teaching himself Bayesian methods, I really appreciate this package.

I am having a little trouble understanding exactly what the "re_formula" command in the "marginal_effects.brmsfit" means. The default is NA, which means predictions are based only on fixed effects and the estimated error of those parameter estimates, correct?
When setting the option to NULL, it includes all random effects. What does this exactly mean? If I have a random intercept, how exactly is this changing the predictions? Does it use the intercept for each random effect individually?
When I compare the two options in marginal effects plots for the fixed effects I am interested in (a 4 category predictor), the plots are pretty different both in terms of means and error.

I am sure that this is a very basic question, but I am having trouble finding the answer. Thanks for your help!

Paul Buerkner

unread,
Feb 13, 2018, 11:33:10 AM2/13/18
to John David Coppin, brms-users
Your intuition about re_formula = NA is correct.

When we write re_formula = NULL, without using the conditions argument, we include the *uncertainty* in the random effects in the predictions.
Basically, we increase the variance of the predictions. If we have a model with a non-identity link this may change the mean by some degree as well.

Where re_formula = NULL is primarily useful is when you want to plot predictions of separate levels of a random effects. Consider the following example:

library(brms)
data("sleepstudy", package = "lme4")

fit <- brm(Reaction ~ 1 + Days + (1 + Days | Subject), data = sleepstudy)
summary(fit)

conditions <- data.frame(Subject = unique(sleepstudy$Subject))
rownames(conditions) <- unique(sleepstudy$Subject)
me <- marginal_effects(fit, conditions = conditions, re_formula = NULL)
plot(me, ncol = 6, points = TRUE)


--
You received this message because you are subscribed to the Google Groups "brms-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brms-users+unsubscribe@googlegroups.com.
To post to this group, send email to brms-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brms-users/9fb20f68-156b-45f9-aa07-02cbf11ef51f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John David Coppin

unread,
Feb 13, 2018, 12:48:47 PM2/13/18
to brms-users

Thank you for your quick response!

Just to make sure that I understand – when re_formula = NULL and no conditions are specified, then for a model with a random intercept, the uncertainty in the random effects included in the predictions is the average uncertainty of all the random intercepts? And when re_formula = NULL and a particular subject is specified in the conditions, then the random intercept for that specific subject is included in the predictions? Is this correct?

Thanks a bunch!



On Tuesday, February 13, 2018 at 10:33:10 AM UTC-6, Paul Buerkner wrote:
Your intuition about re_formula = NA is correct.

When we write re_formula = NULL, without using the conditions argument, we include the *uncertainty* in the random effects in the predictions.
Basically, we increase the variance of the predictions. If we have a model with a non-identity link this may change the mean by some degree as well.

Where re_formula = NULL is primarily useful is when you want to plot predictions of separate levels of a random effects. Consider the following example:

library(brms)
data("sleepstudy", package = "lme4")

fit <- brm(Reaction ~ 1 + Days + (1 + Days | Subject), data = sleepstudy)
summary(fit)

conditions <- data.frame(Subject = unique(sleepstudy$Subject))
rownames(conditions) <- unique(sleepstudy$Subject)
me <- marginal_effects(fit, conditions = conditions, re_formula = NULL)
plot(me, ncol = 6, points = TRUE)

2018-02-13 16:07 GMT+01:00 John David Coppin <jdco...@gmail.com>:
First of all, I love the brms package! This package has allowed me to fit some models for my data that I have not been able to adequately fit before. As an applied statistician who has been teaching himself Bayesian methods, I really appreciate this package.

I am having a little trouble understanding exactly what the "re_formula" command in the "marginal_effects.brmsfit" means. The default is NA, which means predictions are based only on fixed effects and the estimated error of those parameter estimates, correct?
When setting the option to NULL, it includes all random effects. What does this exactly mean? If I have a random intercept, how exactly is this changing the predictions? Does it use the intercept for each random effect individually?
When I compare the two options in marginal effects plots for the fixed effects I am interested in (a 4 category predictor), the plots are pretty different both in terms of means and error.

I am sure that this is a very basic question, but I am having trouble finding the answer. Thanks for your help!

--
You received this message because you are subscribed to the Google Groups "brms-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brms-users+...@googlegroups.com.

Paul Buerkner

unread,
Feb 13, 2018, 12:53:40 PM2/13/18
to John David Coppin, brms-users
This sounds correct to me! :-)

To unsubscribe from this group and stop receiving emails from it, send an email to brms-users+unsubscribe@googlegroups.com.

To post to this group, send email to brms-...@googlegroups.com.

John David Coppin

unread,
Feb 13, 2018, 12:56:11 PM2/13/18
to brms-users
Awesome! Thanks so much for your help! And for a great R package! I really appreciate it.
Reply all
Reply to author
Forward
0 new messages