Learn R Programming

bayesforecast (version 1.0.1)

bridge_sampler.varstan: Log Marginal Likelihood via Bridge Sampling.

Description

Computes log marginal likelihood via bridge sampling, which can be used in the computation of Bayes factors and posterior model probabilities.

Usage

# S3 method for varstan
bridge_sampler(samples, ...)

Arguments

samples

A varstan object.

...

Additional arguments passed to bridge_sampler.stanfit.

Value

the model's marginals likelihood from the bridge_sampler package.

Details

The varstan class is just a thin wrapper that contains the stanfit objects.

Computing the marginal likelihood via the bridgesampler package for stanfit objects.

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)

fit1
bridge_sampler(fit1)

# 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)

fit2
bridge_sampler(fit2)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab