| bayes_factor | R Documentation |
Estimates both marginal likelihoods with bridge sampling and compares the
first model with the second model using bridgesampling::bridge_sampler()
and bridgesampling::bf().
bayes_factor(
model1,
model2,
log = FALSE,
repetitions = 1L,
ghk_draws = 500L,
progress = interactive()
)
model1, model2 |
[ |
log |
[ |
repetitions |
[ |
ghk_draws |
[ |
progress |
[ |
A bf_bridge object from
bridgesampling.
Values greater than one favor model1; values below one favor model2.
Gronau2020RprobitB
### Simulate and fit the correctly specified model
set.seed(1)
correct_model <- fit(
choice ~ x + z | 0,
dgp_parameters = list(beta = c(x = 1, z = 0.5)),
iterations = 500,
chains = 1
)
simulated_data <- as.data.frame(correct_model$data)
### Fit the same data again, but omit the relevant regressor z
misspecified_model <- fit(
choice ~ x | 0,
data = simulated_data,
iterations = 500,
chains = 1
)
### A Bayes factor greater than one favors the correct first model
bayes_factor(correct_model, misspecified_model)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.