Skip to contents

Convergence is the agreement between the sampled distribution and the target, and the Kullback-Leibler divergence over a common binning is the sharpest such summary. Bins with no chain mass contribute nothing; a bin with chain mass but no target mass makes the divergence infinite, which is a genuine failure and is reported rather than smoothed away.

Usage

Klmcmc(chain, target, bins = 20, lo = NULL, hi = NULL)

Arguments

chain

Numeric draws.

target

Density function evaluated at the bin midpoints, or a vector of one value per bin.

bins

Number of equal-width bins.

lo, hi

Optional binning range; the chain range by default.

Value

List with estimate, kl, p, q, unsupported_bins, n, method.

Details

Formula: D(p || q) = sum_k p_k log(p_k / q_k) over equal-width bins.

References

Brooks and Gelman (1998), General methods for monitoring convergence of iterative simulations, Journal of Computational and Graphical Statistics 7(4):434-455. doi:10.1080/10618600.1998.10474787

Examples

set.seed(5)
chain <- rnorm(5000)
Klmcmc(chain, target = dnorm, bins = 20)$kl    # near 0 for a well-mixed chain
#> [1] 0.002188567