I’m using brm()
with cmdstanr
as its backend (i.e. I set backend = "cmdstanr"
in formulae) and trying to calculate the Bays Factor using bayes_factor()
comparing multiple models.
However, bayes_factor()
returns Error: Backend 'rstan' is required for this method
and no computation shows progress. Actually, I really need to use cmdstanr
to analyse more complicated data repetitively with speed, and I dis-prefer to using rstan
this time. Is there any way to compute BF with brms with cmdstanr backend?
MWE
## For sleepstudy data
library(lme4)
## Null model
fm0 <- brm(
Reaction ~ 0 + Intercept + (0 + Intercept + Days|Subject),
data = sleepstudy,
family = "normal",
prior =
c(
prior(normal(0, 1), class = b, coef = Intercept),
prior(normal(0, 1), class = sd),
prior(lkj(2), class = cor)
),
save_pars = save_pars(all = TRUE),
backend = "cmdstanr"
)
## Alternative model
fm1 <- brm(
Reaction ~ 0 + Intercept + Days + (0 + Intercept + Days|Subject),
data = sleepstudy,
family = "normal",
prior =
c(
prior(normal(0, 1), class = b, coef = Intercept),
prior(normal(0, 1), class = b, coef = Days),
prior(normal(0, 1), class = sd),
prior(lkj(2), class = cor)
),
save_pars = save_pars(all = TRUE),
backend = "cmdstanr"
)
## The following commands return an error suggesting us to use rstan
bayes_factor(bridge_sampler(fm1), bridge_sampler(fm0))
bayes_factor(fm1, fm0)
I’m running on:
- Operating System: Windows 10 x64 (build 18362)
- CmdStan Version: 0.1.3
- brms Version: 2.14.0
Any suggestion is appreciated.