pythonstatisticsscipystatsmodelspymc

Highest Posterior Density Region and Central Credible Region


Given a posterior p(Θ|D) over some parameters Θ, one can define the following:

Highest Posterior Density Region:

The Highest Posterior Density Region is the set of most probable values of Θ that, in total, constitute 100(1-α) % of the posterior mass.

In other words, for a given α, we look for a p* that satisfies:

enter image description here

and then obtain the Highest Posterior Density Region as the set:

enter image description here

Central Credible Region:

Using the same notation as above, a Credible Region (or interval) is defined as:

enter image description here

Depending on the distribution, there could be many such intervals. The central credible interval is defined as a credible interval where there is (1-α)/2 mass on each tail.

Computation:


Solution

  • To calculate HPD you can leverage pymc3, Here is an example

    import pymc3
    from scipy.stats import norm
    a = norm.rvs(size=10000)
    pymc3.stats.hpd(a)