Parameter contrasts in Bayesian linear regression model using brms


Using brms, I have fitted 2 linear Bayesian regression models of a response variable A with each 4 binary and one real valued (standardized) parameters (i.e. A ~ b_1 + b_2 + b_3 + b_4 + r). One of the models includes a population level effect (1|user_id). The models are fitted each on a different data set, but both using a log-normal distribution family. I haven’t specified priors, i.e. non-informative default priors were used. Using brms::pp_check, the models seem to (optically) fit well to the data.

My objective is now to quantify for each of the models, how the response A changes when a certain binary variable is true/false. An example is presented here: (from page 29), where contrasts between corpora are estimated from MCMC samples. I basically want to do the same but for each of my parameters, i.e. “What change can be expected in A when p_1 is true/false”.

My idea was to use the MCMC samples, i.e. the posterior distribution, from brms::posterior_samples. For each sample, I get estimates of the log-normal distribution parameters for intercept and the binary variable I am interested in. However, I am interested in the real value of A, which could be the mean/median/mode of the log-normal distribution, calculated from the distribution parameters. What I tried at first is to estimate the median of the log-normal distribution, i.e. med = exp(mu), for the certain binary parameter at every MCMC sample, and then plot a histogram of all the values. The distribution looks reasonable but I am not sure if taking the median of each sample is valid, or taking mean/mode would be a better choice.

How would you recommend to do that? Does this sound like a common procedure that I am not yet aware of?

I noticed a similar output when using brms::pp_check with stat type “_grouped”, and specifying the binary variable which I want to show the contrast for. The resulting plot shows what I am trying to reconstruct, however, for fitted/predicted samples.

  • Operating System: Ubuntu 16.04 LTS
  • brms Version: 2.6.0


The methods posterior_linpred and posterior_predict should help you automating what you want to do. Specifically, I would recommend looking at the newdata argument to specify the conditions that should be contrasted.


Thanks for the suggestions, I am looking into those.

Was I on the right track using the pp_check function together with the stat_grouped argument to derive the contrasts (setting the group to the factor to be contrasted)? It seems to be more straight forward for me to do it this way instead of defining the newdata argument myself. I can directly get a distribution of the contrast by removing the values from one outcome of the factor from the other outcome.