R2D2 prior and divergences under specific circumstances

I’m using R2D2 priors for a complicated model and I’ve noticed that under certain circumstances I’m getting divergences using the prior. I’ve managed to make s simple reprex:

library(brms)
library(bayesplot)

# set pairs plot colours
color_scheme_set("brightblue")

set.seed(1234)
dat <- mgcv::gamSim(1, n = 100, scale = 2)
dat$rand <- runif(nrow(dat))/1000

# fit some GP models
fit1 <- brm(y ~ x1 + rand, dat, chains = 2,
            prior = set_prior(R2D2(mean_R2 = 0.7, prec_R2 = 5), class = "b"))

posterior1 <- as.array(fit1)
np1 <- nuts_params(fit1)
mcmc_pairs(posterior1, pars = c("b_x1", "sdb_x1", "b_rand", "sdb_rand"), np = np)

The pairs plot:

As can be seen there is a funnel like behaviour between b_rand and sdb_rand when beta has the value of 0. Any suggestions on fixing/avoiding this funnel?
I guess one reply might be - just don’t include a variable with 0 value for beta. But, In my real data this came about by including a variable I thought would be important but it turns out seemingly is not. This was unexpected and looking into it led me to make the reprex here, since including unimportant variables could happen often.

In this you have quite many observations compared to the number of parameters and thus likelihood is strong compared to the prior and the default non-centered parameterization has funnel shape. Currently, you can’t change the centered vs. non-centered parameterization in brms, but would need to edit the Stan code yourself if your real data has similarly strong likelihood.

1 Like

Thanks @avehtari. Yes I have actually experimented with this in my own code and found that switching to a centered parameterisation helped but didn’t fully solve the problem.

It is possible that partial non-centering would be even better. There are also other reasons why R2D2 type priors have difficult posterior geometries, and there is some research going on trying to find better parameterizations

1 Like