I've fit a model using brms
that looks like this:
brm(y ~ x + (x | subject), data = dat, family = lognormal())
Now I would like to describe my results using the marginaleffects
package. When I use avg_comparisons(m, variables = "x", type = "response", re_formula = NULL)
, am I calculating the average marginal effect? Similarly, if I create a line plot (e.g. plot(x, estimate)
) using predictions(m, newdata = datagrid(x = unique, subject = unique), by = voi, re_formula = NULL, type = "response")
am I plotting the marginal effect?
I am still very new in the marginal effects and I don't want to make a mistake in the description of my methods.
Yes avg_comparisons(m, variables = "x", type = "response", re_formula = NULL)
is producing the average marginal effect. That is, given the model, if all observations in the data set were to shift from x = 0
to x = 1
what would be the expected difference in y
on the response scale. This correctly averages over the random intercepts/slopes as re_formula = NULL
.
predictions(m, newdata = datagrid(x = unique, subject = unique), by = voi, re_formula = NULL, type = "response")
is producing conditional, not marginal, predictions. That is, a prediction for each combination of unique values of x
and subject
. I'm not sure that this line would run given that voi
is not in the model or in newdata.
If you haven't come across it, highly recommend this book by the package author https://marginaleffects.com/