# bridgesample: Calculates the marginal likelihood of a chain via bridge... In BayesianTools: General-Purpose MCMC and SMC Samplers and Tools for Bayesian Statistics

## Description

Calculates the marginal likelihood of a chain via bridge sampling

## Usage

 ```1 2``` ```bridgesample(chain, nParams, lower = NULL, upper = NULL, posterior, ...) ```

## 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 `posterior` posterior density function `...` arguments passed to bridge_sampler

## Details

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

## Author(s)

Tankred Ott

`marginalLikelihood`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31``` ```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") # 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, posterior = out\$setup\$posterior\$density) bs_result ```