I have a brms implementation of a weighted bayes model (integrating information from different sources) relying on a stan function, which runs without any issue using the default backend.
However, when I try to change backend to cmdstanr, I get an error: "Error in formula.default(object, env = baseenv()) : invalid formula.
Data: https://www.dropbox.com/s/nekgayjpugs8z51/d.csv?dl=0
library(brms)
F_stancode = "
real F(real a_raw, real L_raw, real w_raw) {
real a;
real L;
real w;
a = exp(a_raw);
L = exp(L_raw * a);
w = 0.5 + inv_logit(w_raw)/2;
return log((w * L + 1 - w)./((1 - w) * L + w));
}
"
m_f <- bf(RedChoice ~ bias +
F(0, lSelf, wSelf) +
F(0, lOthers1, wOthers + bConfidence * Confidence1) +
F(0, lOthers2, wOthers + bConfidence * Confidence2) +
F(0, lOthers3, wOthers + bConfidence * Confidence3) +
F(0, lOthers4, wOthers + bConfidence * Confidence4),
wSelf + wOthers + bConfidence + bias ~ 1,
nl = TRUE)
m_prior <- c(prior(normal(2,1), nlpar = "bConfidence"),
prior(normal(0,1), nlpar = "wSelf", coef = "Intercept"),
prior(normal(0,1), nlpar = "wOthers", coef = "Intercept"),
prior(normal(0,.1), nlpar = "bias"))
m <- brm(m_f,
d,
stan_funs = F_stancode,
prior = m_prior,
sample_prior = TRUE,
family = "bernoulli",
chains = 2,
cores = 2,
#backend = "cmdstanr", # uncomment to see the error
#threads = threading(2),
control = list(adapt_delta = 0.99,
max_treedepth=20))
The issue might be in me using stan_fun(), instead of stanvar(), but I get an error when trying to convert to stanvar() even when using the default rstan backend.
- Operating System: MacOS Catalina
- brms Version: 2.14.2