# Setting priors in brms using shifted_lognormal family

I’m trying to analyze response times (RTs) collected in a speech perception experiment, using the shifted_lognormal family. The first batch of code produces a a model which converges and which has no divergent chains, but which produces posterior predictions that deviate modestly from the data for individual participants and which produced posterior distributions of the standard deviations which deviate substantially from the observed standard deviation for many participants. The second batch of code tries to follow the recommended remedy found here, 5.2 A hierarchical model with a normal likelihood: The N400 effect | An Introduction to Bayesian Data Analysis for Cognitive Science, but doing so produces versions of this error, usually for all chains:

Chain 4 Rejecting initial value:
Chain 4 Error evaluating the log probability at the initial value.
Chain 4 Exception: lognormal_lpdf: Scale parameter is -1.4789, but must be positive finite! (in ‘/var/folders/_2/27km6kjs38d49s497vbt7g7x888y_h/T/RtmpmvVLSO/model-11de818a8aec.stan’, line 116, column 4 to column 50)

``````Code that works:

rtPriorSLNa <- c(set_prior("normal(7, 2.5)", class = "Intercept"),
set_prior("normal(6, 1)", class = "Intercept", dpar = "ndt"),
set_prior("normal(0, 0.25)", class = "b"),
set_prior("normal(0, 0.25)", class = "sd"),
set_prior("normal(0, 0.25)", class = "Intercept", dpar = "sigma"),
set_prior("lkj(2)", class = "cor"))

dgRTSLN0a <- brm(formula = bf(rspTime ~ scDgRsp +
poly(scStep, 2) +
scContext +
scEnvelope +
scNative +
(1 + scDgRsp + poly(scStep, 2) + scContext + scEnvelope |p| participant),
ndt ~ 1 +
(1 |p| participant)),
data = dgRT,
prior = rtPriorSLNa,
iter = 2500, chains = 4, warmup = 500,
max_treedepth = 15))

Codes that produces the error:

rtPriorSLNb <- c(set_prior("normal(7, 2.5)", class = "Intercept"),
set_prior("normal(6, 1)", class = "Intercept", dpar = "ndt"),
set_prior("normal(0, 0.25)", class = "b"),
set_prior("normal(0, 0.25)", class = "sd"),
set_prior("normal(0, log(10))", class = "Intercept", dpar = "sigma"),
set_prior("normal(0, 1)", class = "sd", group = "participant", dpar = "sigma"),
set_prior("lkj(2)", class = "cor"))

dgRTSLN0b <- brm(formula = bf(rspTime ~ scDgRsp +
poly(scStep, 2) +
scContext +
scEnvelope +
scNative +
(1 + scDgRsp + poly(scStep, 2) + scContext + scEnvelope |p| participant),
ndt ~ 1 +
(1 |p| participant),
sigma ~ 1 +
(1 |p| participant)),
data = dgRT,
prior = rtPriorSLNb,
iter = 2500, chains = 4, warmup = 500,
max_treedepth = 15))
``````

Any advice would be greatly appreciated.

• Operating System: Mac OS X Monterey
• brms Version: 2.17.0

Within the `brm()` function, sometimes it helps to either set `init = 0` or `init_r = 0.2`.

Thanks!

With init = 0, initial values were rejected for all chains, which terminated. Tried values closer and closer to 0, which produced negative values for scale parameters closer to 0, e.g., with init = 0.001,

Chain 4 Exception: lognormal_lpdf: Scale parameter is -2.27657e-05, but must be positive finite! (in ‘/var/folders/_2/27km6kjs38d49s497vbt7g7x888y_h/T/RtmpmvVLSO/model-11de8de620fe.stan’, line 116, column 4 to column 50)

but progress has halted.

“init_r” was not recognized.

That’s frustrating. You might need to adjust the initial values for your primary parameters manually, then.

I am merely learning Brms but I have used RStan and CmdStanR for a number of years. I believe your model has a random effect on non-negative parameters, sigma, but with a normal prior. In RStan, you need to use a trick to make the random effect parameters with normal prior non-negative. I do not believe Brms is doing it by default. Please ignore this message if I misunderstand your model.

There are `lb` and `ub` (as in lower and upper bound) parameters in ` brms::set_prior()`. You might need to update to the newest version to be able to use it.

Thanks! You didn’t misunderstand my model. What is the trick?

Thanks! Is this the trick referred to in the previous response?

This discussion is what I was thinking about: Non-centered parameterisation with boundaries

At a minimum, you can apply a transformation to ensure positivity. But using the solution is more elegant. I don’t know if either method is available in Brms.

Good luck

1 Like