Basic question: what is lp_ in posterior samples of a brms regression?

It is the log posterior density, up to a normalizing constant.

The posterior density is defined as:

p(\theta|D) = \frac{p(D|\theta)p(\theta)}{p(D)}

The posterior density, defined up to a constant (i.e., the unnormalized posterior density):

p(\theta|D) \propto p(D|\theta)p(\theta)

The log unnormalized posterior density:

\log p(\theta|D) = \log (p(D|\theta)) + \log (p(\theta))

Stan only needs the unnormalized log posterior, up to any constants.

So when you say:

theta ~ normal(0,1)
x ~ normal(theta, 1)

This is, conceptually, translated to:

target = 0
target += log(normal_pdf(theta | 0, 1))
target += sum(log(normal_pdf(x | theta, 1)))

The “target” variable is the unnormalized, log posterior density.

In reality, using ~ statements in Stan also drops constants in the (log)density functions; like the 1/sqrt(2) in the normal density.

But Brms uses the target += syntax, so it maintains those constants.

The lp__ variable tracks the target variable. Therefore, the lp__ in brms is the unnormalized log posterior density.

In sum: lp__ in brms is equal to the unnormalized log posterior density; in general, it is equal to the ‘target’ variable, which represents the sum of the log density and mass contributions from the likelihoods and priors - Whether it is the unnormalized log posterior density depends on whether the constants are dropped (using ~ syntax) or not (using target += syntax).

10 Likes