Calculates the marginal likelihood of a chain via bridge sampling

bridgesample(chain, nParams, lower = NULL, upper = NULL, ...)

Arguments

chain

a single mcmc chain with samples as rows and parameters and posterior density as columns.

nParams

number of parameters

lower

optional - lower bounds of the prior

upper

optional - upper bounds of the prior

...

arguments passed to bridge_sampler

Details

This function uses "bridge_sampler" from the package "bridgesampling".

See also

marginalLikelihood

Examples

means <- c(0, 1, 2) sds <- c(1, 0.6, 3) # log-likelihood ll <- function (x) { return(sum(dnorm(x, mean = means, sd = sds, log = TRUE))) } # lower and upper bounds for prior lb <- rep(-10, 3) ub <- rep(10, 3) # create setup and run MCMC setup <- createBayesianSetup(likelihood = ll, lower = lb, upper = ub) out <- runMCMC(bayesianSetup = setup, settings = list(iterations = 1000), sampler = "DEzs")
#> Running DEzs-MCMC, chain 1 iteration 300 of 1002 . Current logp -14.67601 -13.46839 -16.29187 . Please wait! Running DEzs-MCMC, chain 1 iteration 600 of 1002 . Current logp -14.8849 -14.08858 -15.73934 . Please wait! Running DEzs-MCMC, chain 1 iteration 900 of 1002 . Current logp -15.12236 -14.57723 -12.89714 . Please wait! Running DEzs-MCMC, chain 1 iteration 1002 of 1002 . Current logp -13.07464 -13.45026 -14.50715 . Please wait!
#> runMCMC terminated after 0.980000000000018seconds
# sample from MCMC output with "burn-in" of 25% sample <- getSample(out$chain, start = 250, numSamples = 500) # use bridge sampling to get marginal likelihood bs_result <- bridgesample(chain = sample, nParams = out$setup$numPars, lower = lb, upper = ub)
#> Iteration: 1 #> Iteration: 2 #> Iteration: 3 #> Iteration: 4 #> Iteration: 5 #> Iteration: 6 #> Iteration: 7 #> Iteration: 8 #> Iteration: 9 #> Iteration: 10
bs_result
#> Bridge sampling estimate of the log marginal likelihood: -9.7342 #> Estimate obtained in 10 iteration(s) via method "normal".