Move ConfidenceInterval to yli.utils
This commit is contained in:
parent
6d1802fbaf
commit
12a0707998
@ -39,4 +39,4 @@ def test_hdi_beta_vs_r():
|
||||
#1 bayes 12 250 13 239 0.0515873 0.02594348 0.0793006 0.05
|
||||
expected = np.array([0.02594348, 0.0793006])
|
||||
|
||||
assert hdi == approx(expected)
|
||||
assert (hdi.lower, hdi.upper) == approx(expected)
|
||||
|
@ -17,9 +17,8 @@
|
||||
import numpy as np
|
||||
from scipy import integrate, optimize, stats
|
||||
|
||||
import collections
|
||||
|
||||
from .config import config
|
||||
from .utils import ConfidenceInterval
|
||||
|
||||
class betarat_gen(stats.rv_continuous):
|
||||
"""
|
||||
@ -294,8 +293,6 @@ class transformed_gen(stats.rv_continuous):
|
||||
|
||||
transformed_dist = transformed_gen(name='transformed')
|
||||
|
||||
ConfidenceInterval = collections.namedtuple('ConfidenceInterval', ['lower', 'upper'])
|
||||
|
||||
def hdi(distribution, level=None):
|
||||
"""
|
||||
Get the highest density interval for the distribution, e.g. for a Bayesian posterior, the highest posterior density interval (HPD/HDI)
|
||||
|
12
yli/utils.py
12
yli/utils.py
@ -139,6 +139,18 @@ def fmt_p(p, *, html, tabular=False):
|
||||
# ------------------------------
|
||||
# General result-related classes
|
||||
|
||||
class ConfidenceInterval:
|
||||
"""A confidence interval"""
|
||||
|
||||
def __init__(self, lower, upper):
|
||||
self.lower = lower
|
||||
self.upper = upper
|
||||
|
||||
def _repr_html_(self):
|
||||
return self.summary()
|
||||
|
||||
def summary(self):
|
||||
return '{:.2f}–{:.2f}'.format(self.lower, self.upper)
|
||||
class Estimate:
|
||||
"""A point estimate and surrounding confidence interval"""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user