Move ConfidenceInterval to yli.utils

This commit is contained in:
RunasSudo 2022-10-18 17:57:19 +11:00
parent 6d1802fbaf
commit 12a0707998
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 14 additions and 5 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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"""