Brms default priors?

This isn’t a problem with my code, but a question of how brms specifies default priors… most of the documentation I’ve read states brms uses flat priors when priors are not specified via set_prior(). But what is not clear to me, is what is meant by a “flat prior”? Surely there’s some distribution being implemented, even if it is a very wide interval (e.g. normal(-10, 10)).

So, say I’ve constructed a model:

odhe.m1 <- brm(noct ~ HOMO.n.day  ,
               family=gaussian,
               save_pars = save_pars(all = TRUE),
               iter=10000,
               warmup=5000,
               cores=detectCores(),
               data=ODHE)

Where “noct” and “HOMO.n.day” are both continuous numeric variables, normally distributed, etc. When I run the following, since I’m not specifying any prior distributions for the variable “HOMO.n.day”, I see the distribution is “flat” :

get_prior(noct ~ HOMO.n.day, data=ODHE)

                        prior     class       coef group resp dpar nlpar bound       source
                       (flat)         b                                             default
                       (flat)         b HOMO.n.day                             (vectorized)
 student_t(3, 20527, 11672.5) Intercept                                             default
     student_t(3, 0, 11672.5)     sigma                                             default

I’d just like to know if there’s a way to identify the prior which is actually being used in constructing this model. What is “flat” here? Is there a way to explain this numerically?

Any feedback on this would be much appreciated.

Cheers!

You can extract the generated Stan code from the brmsfit object with the stancode() command. The “flat” prior is a (sometimes improper) uniform distribution over the declared bounds of the parameters. Informally, p(\theta) = 1, -\infty<\theta<\infty.

Hi Michael,

Under-the-hood in Stan, all of the sampling statements, including the prior statements, just serve to increment something that we call the “target density” with an appropriate function. So if we write, for example, x ~ std_normal() what we are doing is multiplying the target density by the standard normal PDF. Stan doesn’t actually work with the target density directly, but rather with its logarithm. Thus, instead of multiplying the target density by the standard normal PDF, what really happens is that we add logarithm of the standard normal PDF to the logarithm of the target density. The target density in Stan is something that is proportional to the posterior probability density at any point in parameter space, and this is what Stan needs in order to work its magic and return posterior samples.

The reason this is relevant is because Stan can therefore work readily enough with improper priors, like a flat line of infinitesimal probability density stretching all the way from negative infinity to infinity. It doesn’t matter than we can’t sample from this distribution in the sense of generating random numbers. All Stan needs to do is avoid multiplying the target density by a prior term that isn’t constant over the entire real line. So you can think of the “improper flat prior” as omitting a prior statement, or you can think of it as multiplying the target by a constant, which then drops out since we just need a target density that is proportional to the posterior, or as multiplying by a constant 1, which doesn’t change anything numerically.

brms uses “flat priors” of this sort for some (but not all) classes of parameter in some (but not all) models.

1 Like

Thanks! Very helpful to see the Stan code

This is a great explanation of priors, and really helps me wrap my head around this concept. Thanks so much for taking the time to respond!

1 Like