bridgesample: Calculates the marginal likelihood of a chain via bridge...

Description Usage Arguments Details Author(s) See Also Examples

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

See Also

marginalLikelihood

Examples

 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

BayesianTools documentation built on Dec. 10, 2019, 1:08 a.m.