Half-normal priors for sigma (sd) in hierarquical analysis

I am triying to use a half normal prior for the sd of each parameter in my model.

I was using this syntax to truncate the distribution real<lower=0> sigma_L. But as I understand it, this wont force the PDF to integrate over 1 for values above 0. To do so, I used this line of code:

target += normal_lpdf(sigma_L | 0, 0.531) - log(0.5).

Basically adding log(2) (same as -log(0.5)), to double the density for the positive half (multiplication becomes addition in log space). This approach makes sense?

Hi, @Fernando, and welcome to the Stan Forums!

That’s correct. It’ll integrate to something else. If it’s centered at 0 like your example, then it’ll integrate to 1/2.

It makes sense mathematically and will give you the normalized form of the normal (i.e., one that integrates to 1 over its support). But we don’t recommend it as it adds needless extra work for autodiff. The target in Stan is only required to be equal to the posterior up to an additive constant. Usually it’s equal to the joint density after dropping some constants that don’t depend on the parameters, like that log(0.5) term, which by Bayer’s rule, is also equal to the posterior up to an additive constant.

In general, distribution statements in Stan like

y ~ normal(0, sigma);

will drop the constant log(1 / sqrt(2 * pi)) terms automatically because they’re not necessary for sampling.

Got it, mathematically correct but superflous as the constant terms are not relevant to calculate the relative probabilities.

What is your recommendation for this case? just drop the log(0.5) and keep the lower bound statement (real<lower=0> sigma_L)?

Thank you for your help and for the welcoming!