Rejecting initial value


I keep getting this in a loop:

SAMPLING FOR MODEL ‘8c349b2a7e185059d867bb3fe6b8746e’ NOW (CHAIN 1).
Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: lognormal_lpdf: Random variable[1] is -1.56634, but must be >= 0! (in ‘model120c70da6cea_8c349b2a7e185059d867bb3fe6b8746e’ at line 49)

Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: beta_lpdf: Second shape parameter[1] is 0, but must be > 0! (in ‘model120c70da6cea_8c349b2a7e185059d867bb3fe6b8746e’ at line 58)

I ran:

priors <- c(set_prior(“lognormal(0.01494647, 0.00937701)”, class = “b”, coef = “Temp”))
ins_month <- brm(use2 ~ Temp + (1+Temp|Month.f),
data = dpa.ins.home, family = Beta(), warmup = 1000, iter = 3000, chains = 2,
inits = “random”, control = list(adapt_delta = .95, max_treedepth = 12),
prior = priors, cores = getOption(“mc.cores”, 4L), sample_prior = TRUE))

Can someone provide me with some advice to fix this…

  • Operating System: Windows 10
  • brms Version: 2.5


Please try changing the seed in the rstan::stan().


I don’t really understand init or seed in the rstan::stan() so I don’t know what to change either to. Could you explain these two arguments or provide a reference that you feel explains them well.


init refers to the initial parameter values that Stan starts HMC/NUTS off with. If these values don’t produce a finite log posterior, then Stan has to choose new initial values until it gets a good starting point with a finite log posterior. If no initializer function or list is specified for rstan::stan(), then Stan will sample uniformly on the unconstrained support from the interval (-2, 2) using pseudo RNG. Pseudo RNG is deterministic in the sense that if you provide the same seed, you will get the same sample. So changing the seed will yeild a different set of initial values that may or may not have a finite log posterior. See pg 42 of the rstan manual for more details.

Another approach would be specifying a list or function that returns initial parameter values that you know will yield a finite log posterior. If you do this you should use different initial values for each Markov Chain to get more robust diagnostics.


Let’s suppose that a0, a1, a2, and a3 are my model parameters, and my stan model is:

fit <- stan(fit = model.stan, iter = 2000, init = …, …)

and the initial values I want to use in each of my 4 chains are:

inits_1 <- function(){list(a0=-4,a1=0,a2=0, a3=0)}
inits_2 <- function(){list(a0=-4,a1=0,a2=0, a3=0)}
inits_3 <- function(){list(a0=-4,a1=0,a2=0, a3=0)}
inits_4 <- function(){list(a0=-4,a1=0,a2=0, a3=0)}

could you kindly clarify how could the below be done in practice for this model and these inits?

Thanks in advance.


I would do something like this, but with some RNG noise added to each chain initialization (I usually initialize by sampling from the parameter priors in R).

initializer <- function() list("a0"=-4,"a1"=0,"a2"=0, "a3"=0)
n_chains <- 4

inits <- list()
for (chain in 1:n_chains) inits[[chain]] <- initializer()
draw <- stan(..., init=inits)


That’s great. Thanks @ScottAlder. EDIT: just tested. It reduced notably the number of Error evaluating the log probability at the initial value messages compared to the other approach. Thank you very much for this very helpful insight.

Just to make sure that I am doing it right - it might be that I am not doing it right.

Is it:





The first one would ensure that the list of initial values and the number of chains matched, so probably that one is best. Otherwise, running on the default number of chains (4) won’t break it


Great! Thanks @ScottAlder.