CONAN.funcs.credregionML#
- CONAN.funcs.credregionML(posterior=None, percentile=0.6827, pdf=None, xpdf=None)#
Compute a smoothed posterior density distribution and the minimum density for a given percentile of the highest posterior density. These outputs can be used to easily compute the HPD credible regions.
- Parameters:
posterior (1D float ndarray) – A posterior distribution.
percentile (Float) – The percentile (actually the fraction) of the credible region. A value in the range: (0, 1).
pdf (1D float ndarray) – A smoothed-interpolated PDF of the posterior distribution.
xpdf (1D float ndarray) – The X location of the pdf values.
- Returns:
pdf (1D float ndarray) – A smoothed-interpolated PDF of the posterior distribution.
xpdf (1D float ndarray) – The X location of the pdf values.
HPDmin (Float) – The minimum density in the percentile-HPD region.
Example
>>> import numpy as np >>> npoints = 100000 >>> posterior = np.random.normal(0, 1.0, npoints) >>> pdf, xpdf, HPDmin = credregion(posterior) >>> # 68% HPD credible-region boundaries (somewhere close to +/-1.0): >>> print(np.amin(xpdf[pdf>HPDmin]), np.amax(xpdf[pdf>HPDmin])) >>> # Re-compute HPD for the 95% (withour recomputing the PDF): >>> pdf, xpdf, HPDmin = credregion(pdf=pdf, xpdf=xpdf, percentile=0.9545) >>> print(np.amin(xpdf[pdf>HPDmin]), np.amax(xpdf[pdf>HPDmin]))