Compare two models by calculating the Bayes Factor based on their marginal likelihoods.
Value
An object of class `bayes_factor` containing the Bayes factor, log Bayes factor, approximate estimation error, and interpretation.
Examples
# \donttest{
# Compare two models using Bayes Factor
data(debate, package = "BayesRTMB")
fit1 <- rtmb_lm(sat ~ talk, data = debate)
#> Pre-checking model code...
#> Checking RTMB setup...
fit2 <- rtmb_lm(sat ~ talk + perf, data = debate)
#> Pre-checking model code...
#> Checking RTMB setup...
map1 <- fit1$optimize()
#> Starting RTMB optimization...
#>
map2 <- fit2$optimize()
#> Starting RTMB optimization...
#>
bf <- bayes_factor(map1, map2)
print(bf)
#> Bayes Factor (BF12) : 0
#> Log Bayes Factor : -10.3811
#> Evidence : Decisive evidence for Model 2
# }