Learn R Programming

brms (version 2.1.0)

bayes_factor.brmsfit: Bayes Factors from Marginal Likelihoods

Description

Compute Bayes factors from marginal likelihoods.

Usage

# S3 method for brmsfit
bayes_factor(x1, x2, log = FALSE, ...)

Arguments

x1

A brmsfit object

x2

Another brmsfit object based on the same responses.

log

Report Bayes factors on the log-scale?

...

Additional arguments passed to bridge_sampler.

Details

Computing the marginal likelihood requires samples of all variables defined in Stan's parameters block to be saved. Otherwise bayes_factor cannot be computed. Thus, please set save_all_pars = TRUE in the call to brm, if you are planning to apply bayes_factor to your models.

More details are provided under bayes_factor.

See Also

bridge_sampler, post_prob

Examples

Run this code
# NOT RUN {
# model with the treatment effect
fit1 <- brm(
  count ~ log_Age_c + log_Base4_c + Trt_c,
  data = epilepsy, family = negbinomial(), 
  prior = prior(normal(0, 1), class = b),
  save_all_pars = TRUE
)
summary(fit1)

# model without the treatment effect
fit2 <- brm(
  count ~ log_Age_c + log_Base4_c,
  data = epilepsy, family = negbinomial(), 
  prior = prior(normal(0, 1), class = b),
  save_all_pars = TRUE
)
summary(fit2)

# compute the bayes factor
bayes_factor(fit1, fit2)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab