Learn R Programming

bayesforecast (version 1.0.1)

bayes_factor.varstan: Bayes Factors from Marginal Likelihoods.

Description

Compute Bayes factors from marginal likelihoods.

Usage

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

Arguments

x1

A varstan object

x2

Another varstan object based on the same data.

log

A boolean parameter for report the Bayes_factor in log scale. The default value is FALSE.

...

Additional arguments passed to bayes_factor.

Value

The bayes factors of two models.

Details

The computation of marginal likelihoods based on bridge sampling requires a lot more posterior samples than usual. A good conservative rule of thump is perhaps 10-fold more samples (read: the default of 4000 samples may not be enough in many cases). If not enough posterior samples are provided, the bridge sampling algorithm tends to be unstable leading to considerably different results each time it is run. We thus recommend running bridge_sampler multiple times to check the stability of the results.

For more details check the bridgesampling package.

Examples

Run this code
# NOT RUN {
 library(astsa)
 # Fitting a seasonal arima model
 mod1 = Sarima(birth,order = c(0,1,2),seasonal = c(1,1,1))
 fit1 = varstan(mod1,iter = 500,chains = 1)

 # Fitting a Dynamic harmonic regression
 mod2  = Sarima(birth,order = c(0,1,2),xreg = fourier(birth,K=6))
 fit2 = varstan(mod2,iter = 500,chains = 1)

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

Run the code above in your browser using DataLab