Half-normal prior for categorical factor


sorry if this is a stupid question, but how do I specify a half-normal (or folded) prior in brms in order to test a directional hypothesis of a categorical variable on normally distributed data (in my case, effect of unexpected/expected stimulus on EEG data), with a regular linear mixed model? using ub or lb does not seem to give the right prior since it gives lower density near zero than a half-normal would, if I understand correctly, but that’s as close as I seem to get to anything directional.

priors <- c(set_prior(“normal(0,1)”, class = “Intercept”),
set_prior(“normal(0,.5)”, class = “b”, coef = “” , lb = 0))

Please also provide the following information in addition to your question:

  • Operating System: mac osx
  • brms Version: 2.4.0


You specified the prior correctly. Can you show me a comparison between the density you expect and the density brms returns?


Probably I am just misunderstanding. The prior with lb is plotted below. Apologies, I have no plot for ‘expected’ prior, but I expected it to be precisely half-normal (so no density dip between the point of highest density and the zero point estimate)

Mante S. Nieuwland

Senior Investigator

Neurobiology of Language Department

Max Planck Institute for Psycholinguistics



I believe this is an artifact of the smoothing done to get a density out of the posterior samples.


okay, i see, but won’t this distort the evidence ratio for BF/hypothesis testing then?


I don’t know. That depends on how the smoother works at the boundaries. I suggest comparing the estimated density at zero to the true density of the half-normal distribution in your case computed via dnorm(0, mean = 0, sd = 0.5) / 0.5


Thanks again for replying! Yeah this matters quite a bit, for half-normal it would be close to 1.5, but the lb-prior is below 1 (from the looks of the plot, 1.5 is indeed where the lb-prior would end up were it not dipping around zero. For BF purposes, maybe I should just stick with a normal prior, or is there a way to change the smoothing?


The thing is that the the smoothing done to create the plot might be different to the smoothing done internally when computing the Bayes factor. A principled way of comparing that would be to take a problem where we know the solution (i.e. the Bayes factor) analytically and compare it to the result returned by hypothesis. You may also compare the results of the bayes_factor method to the result of the hypothesis method. To be able to do both for the exact same fitted model you need to install the dev version of brms from github though.


thanks again for your reply! I followed your suggestions and seem to be getting similar BFs from the two methods, with or without lb, so that is comforting