bayes_factor: Bayes factor and posterior odds ratio for DSGE model...

View source: R/bayes-diagnostics.R

bayes_factorR Documentation

Bayes factor and posterior odds ratio for DSGE model comparison

Description

Computes Bayes factors (ratios of marginal likelihoods) between pairs of estimated DSGE models and converts them to posterior odds ratios when prior model probabilities are supplied. Evidence strength follows the Kass-Raftery (1995) scale.

Usage

bayes_factor(..., prior_odds = NULL, method = "harmonic_mean", tau = 0.5)

Arguments

...

Two or more objects of class "dsge_bayes" or "dsge_marginal_likelihood" (results of marginal_likelihood()). Named arguments are used as model labels; unnamed arguments are labelled Model 1, Model 2, etc.

prior_odds

A numeric vector of prior model probabilities (or unnormalized weights) in the same order as .... Defaults to NULL (equal prior probabilities).

method

Passed to marginal_likelihood() when the inputs are "dsge_bayes" objects and marginal likelihoods have not yet been computed. Default: "harmonic_mean".

tau

Truncation parameter passed to marginal_likelihood(). Default: 0.5.

Details

The Bayes factor BF_{12} = p(y|M_1)/p(y|M_2) measures how much the data prefer model M_1 over M_2. Following Kass and Raftery (1995), evidence strength is assessed via 2 \log BF_{12}:

2 log BF Evidence for M1
< 0 Negative (favours M2)
0 to 2 Not worth more than a bare mention
2 to 6 Positive
6 to 10 Strong
10 Very strong

When prior_odds is supplied the posterior model probability of model i is

P(M_i | y) \propto p(y | M_i) \cdot \pi_i

where \pi_i is the (possibly unnormalized) prior weight.

The marginal likelihood estimates are based on the modified harmonic mean estimator and inherit its limitations (see marginal_likelihood). Use consistent MCMC settings across all models being compared.

Value

An object of class "dsge_bayes_factor" containing:

log_ml

Named numeric vector of log marginal likelihoods.

nse

Numerical standard errors for each log-ML estimate.

bf_matrix

Matrix of log Bayes factors \log BF_{ij} = \log ML_i - \log ML_j.

posterior_probs

Posterior model probabilities.

prior_odds

Prior model probabilities used.

model_names

Character vector of model labels.

References

Kass, R. E. and Raftery, A. E. (1995). Bayes factors. Journal of the American Statistical Association, 90(430), 773-795.

See Also

marginal_likelihood, bayes_dsge

Examples


m1 <- dsge_model(
  obs(y ~ lead(y) + u),
  state(u ~ rho * u),
  start = list(rho = 0.5)
)
m2 <- dsge_model(
  obs(y ~ u),
  state(u ~ rho * u),
  start = list(rho = 0.5)
)
set.seed(1)
y <- cumsum(rnorm(60, sd = 0.1))
dat <- data.frame(y = y)
pr <- list(rho = prior("beta", shape1 = 5, shape2 = 5))
fit1 <- bayes_dsge(m1, dat, pr, chains = 1L, iter = 500L, warmup = 200L)
fit2 <- bayes_dsge(m2, dat, pr, chains = 1L, iter = 500L, warmup = 200L)
bf <- bayes_factor(M1 = fit1, M2 = fit2)
print(bf)



dsge documentation built on Sept. 25, 2026, 5:08 p.m.