bridgesample | R Documentation |
Calculates the marginal likelihood of a chain via bridge sampling
bridgesample(chain, nParams, lower = NULL, upper = NULL, posterior, ...)
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 |
This function uses "bridge_sampler" from the package "bridgesampling".
Tankred Ott
marginalLikelihood
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.