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)
)