Description
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.