I would like to calculate credible intervals for the slopes of a model with continuous by categorical interactions. However, in R output, I get a measure of slope for the baseline for one factor and the differences for the remaining factors. E.g. in the below model using the iris data I would like to build a credible interval around the slope for versicolor and virginica.

I asked on the stats stackexchange if this is possible and it seems to be. “If you have posterior draws of the parameters a and b, then merely adding them together c=a+b serves as a posterior draw from the sum distribution. With these posterior draws of c, a credible interval is calculated as usual in the Bayesian setting.”

You can use one of the as_draws() helper functions (I like as_draws_df()) to extract the posterior draws for the parameters in your model. Then you can manually compute the slopes you desire by using the model formula. E.g.,

@Solomon - in a similar vein to this, if I have random effects of a categorical variable, are the coefficients labelled as ‘r_whatevereffect’ in the draws data frame the deviation from the overall/average estimated effect of that variable? So for example, if I wanted to know the estimate of some specific level of a random effect, I could simply do something like?:

as_draws_df(ref_model) %>%
mutate(average_effect = b_Intercept + b_Overalleffect,
specific_randomeffectv1 = b_Intercept + b_Overalleffect + r_Specificsubeffect, # random effect is deviation from overall effect
specific_randomeffectv2 = b_Intercept + r_Specificsubeffect # random effect is self-standing estimate
)

So the key question here for judging how to add the effects is whether the r_effect components of the posterior are deviations from the average effect or rather represent a direct estimate for that sub effect, which are averaged to make the overall effect?

Regardless of whether you have a categorical predictor, “the coefficients labelled as ‘r_whatevereffect’ in the draws data frame [ARE] the deviation from the overall/average estimated effect of that variable.”

Say you have a simple intercepts-only multilevel model using the Gaussian likelihood

where your criterion y varies across i people and j measurement occasions. The grand mean intercept is \alpha and the person-level deviations are captured in the u_i term. When you pull your posterior samples with as_draws_df(), those u_i deviations are in the ‘r_whatevereffect’ columns.

Thanks Solomon! To avoid making mistakes when adding stuff together like this, is there a simpler way of getting some fitted estimates? I recall the function add_fitted_draws, but now that is deprecated and there are many variations of it that start to get rather confusing to follow. For example, is there a way to get the full posterior distribution just for specified levels e.g., feed it a data dataframe that indicates the Gender, Age, and specific item in the multilevel model that you want an estimate for, and it returns the fitted estimates for that combination of features without having to calculate them by adding the different posterior segments up?

Depending on what you’re looking for, spend some time looking through the ranef(), coef(), and fitted() functions. You’re probably interested in coef() and fitted().

Look at the brms documentation for posterior_epred() (to which add_epred_draws() corresponds to) and the documentation for posterior_predict() (to which add_predicted_draws() corresponds to). posterior_epred() provides the expected value with uncertainty only in the mean incorporated, where as posterior_predict() provides predictive distribution with residual error. The means should be similar but the variance higher for posterior_predict()