Rejecting initial value error message

Hi, I am trying to fit a non-linear formula model, specifically a hyperbolic function for delayed discounting using hiearchical model.

I want to estimate logk with a covariate (factor variable with 9 levels), but it keeps giving me an error message that MCMC fails to find an initial value for the chain. Variables used in this formula are all numeric excpet for subject and choice_type_detail. When I remove choice_type for estimating logk, the model has no fitting issues. It converged well. Can you guys share your wisdom how to fix this issue? Thank you so much!

formula_cross <- bf(
  choice ~ 0.5 + 0.5 * inv_logit(beta * (EVlater - EVsooner)),
  nlf(EVlater  ~   log_amount_later / (1 + exp(logk) * delay_later_years)),
  nlf(EVsooner ~   log_amount_sooner / (1 + exp(logk) * delay_sooner_years)),
  logk  ~ 0 + choice_type_detail + (1|subject),
  beta  ~ 1 + (1|subject),
  nl = TRUE
)

priors_cross_commodity <- c(
  prior(normal(-4, 2), class = "b", nlpar = "logk"),
  prior(normal(0, 1), class = "b", nlpar = "beta"),
  prior(normal(0, 0.5), class = "sd", nlpar = "logk"),
  prior(normal(0, 0.5), class = "sd", nlpar = "beta")
)

set_cmdstan_path(path = "C:/Users/jdi94/.cmdstan/cmdstan-2.35.0")

options(brms.backend = "cmdstanr")

fit_cross_comm_full <- brm(
  formula,
  data = full_df,
  family = bernoulli(),
  prior = priors_cross_commodity,
  chains = 4,
  cores = 4,
  iter = 4000,
  warmup = 2000,
  control = list(adapt_delta = 0.99, max_treedepth = 15)
)

My guess is that a) choice_type_detail is a factor with a somewhat large number of factors and so b) the probability that the coefficient for one of the levels is initialized to a large-ish value is high (by default the init is between -2 and 2) and c) with large-ish logk some numerical instability arises in the formula… The formula doesn’t appear to be particularly nasty, but if some of the data variables are very large and some very small, maybe something happens? Not completely sure though…

Typically you can avoid those problems by choosing better initial values for your model (see the docs for the init argument). E.g. init = 0.1 might work, but you may also want to set specific inits just for the coefficients of choice_type_detail.

Also one thing that is weird about the model is bernoulli familyfor choice implicitly assumes a logit link, so not sure what the 0.5 + 0.5 * inv_logit(...) term is doing there. Maybe you wanted to have a bernoulli(link = "identity") family?

Best of luck with your model!

1 Like