bayes_factor: Calculate Bayes Factor

bayes_factorR Documentation

Calculate Bayes Factor

Description

Compare two models by calculating the Bayes Factor based on their marginal likelihoods.

Usage

bayes_factor(logml1, logml2, error_threshold = 0.2)

Arguments

logml1

The first model fit (e.g., 'mcmc_fit') or its log-marginal likelihood.

logml2

The second model fit (e.g., 'mcmc_fit') or its log-marginal likelihood.

error_threshold

Threshold for warning about high bridge-sampling error (default 0.2).

Value

An object of class 'bayes_factor' containing the Bayes factor, log Bayes factor, approximate estimation error, and interpretation.

Examples


  # Compare two models using Bayes Factor
  data(debate, package = "BayesRTMB")
  fit1 <- rtmb_lm(sat ~ talk, data = debate)
  fit2 <- rtmb_lm(sat ~ talk + perf, data = debate)
  map1 <- fit1$optimize()
  map2 <- fit2$optimize()
  bf <- bayes_factor(map1, map2)
  print(bf)


BayesRTMB documentation built on Nov. 24, 2026, 9:06 a.m.