From f9b9f28add70eb377fae6116bb44d158def81ae3 Mon Sep 17 00:00:00 2001 From: Alex Eftimiades Date: Wed, 17 Aug 2022 13:51:08 -0400 Subject: [PATCH 1/4] raise ValueError when alpha or beta <= 1 --- mvtk/credibility.py | 6 ++++-- mvtk/version.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mvtk/credibility.py b/mvtk/credibility.py index 72add6b..844366c 100644 --- a/mvtk/credibility.py +++ b/mvtk/credibility.py @@ -22,9 +22,11 @@ def credible_interval(positive, negative, credibility=0.5, prior=(1, 1)): """ positive += prior[0] negative += prior[1] + if positive < 1 or negative < 1: + raise ValueError( + "Credible intervals are undefined when counts + priors are not both greater than 1" + ) distribution = beta(positive, negative) - if positive + negative <= 0: - raise ValueError("Counts plus pseudocounts must be positive") mode = positive / (positive + negative) cdf_mode = distribution.cdf(mode) cred_2 = credibility / 2 diff --git a/mvtk/version.py b/mvtk/version.py index b3f4756..ae73625 100644 --- a/mvtk/version.py +++ b/mvtk/version.py @@ -1 +1 @@ -__version__ = "0.1.2" +__version__ = "0.1.3" From 0cc22245e1613277807bf9040c38fd1683f36b3e Mon Sep 17 00:00:00 2001 From: Alex Eftimiades Date: Wed, 17 Aug 2022 13:57:23 -0400 Subject: [PATCH 2/4] raise value error under more general circumstances --- mvtk/credibility.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mvtk/credibility.py b/mvtk/credibility.py index 844366c..6e523a1 100644 --- a/mvtk/credibility.py +++ b/mvtk/credibility.py @@ -22,9 +22,10 @@ def credible_interval(positive, negative, credibility=0.5, prior=(1, 1)): """ positive += prior[0] negative += prior[1] - if positive < 1 or negative < 1: + if not (positive > 1 or negative > 1): raise ValueError( - "Credible intervals are undefined when counts + priors are not both greater than 1" + "Credible intervals are only defined when at least one count + psueocount is" + " greater than 1" ) distribution = beta(positive, negative) mode = positive / (positive + negative) From 1131c921ccf452b1468fd2d43c4b5faaaf2022ce Mon Sep 17 00:00:00 2001 From: Alex Eftimiades Date: Wed, 17 Aug 2022 13:59:41 -0400 Subject: [PATCH 3/4] fix line length --- mvtk/credibility.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mvtk/credibility.py b/mvtk/credibility.py index 6e523a1..720e9b6 100644 --- a/mvtk/credibility.py +++ b/mvtk/credibility.py @@ -24,8 +24,8 @@ def credible_interval(positive, negative, credibility=0.5, prior=(1, 1)): negative += prior[1] if not (positive > 1 or negative > 1): raise ValueError( - "Credible intervals are only defined when at least one count + psueocount is" - " greater than 1" + "Credible intervals are only defined when at least one count + psueocount" + " is greater than 1" ) distribution = beta(positive, negative) mode = positive / (positive + negative) From fb3505ddc169b394f7f6737e727857266d824923 Mon Sep 17 00:00:00 2001 From: Alex Eftimiades Date: Wed, 17 Aug 2022 14:06:17 -0400 Subject: [PATCH 4/4] fix test --- tests/credibility/test_credibility.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/credibility/test_credibility.py b/tests/credibility/test_credibility.py index b9d728c..5bca0e9 100644 --- a/tests/credibility/test_credibility.py +++ b/tests/credibility/test_credibility.py @@ -14,8 +14,8 @@ def test_value_error(): def test_equivalence(): - assert credibility.credible_interval(0, 0) == credibility.credible_interval( - 1, 1, prior=(0, 0) + assert credibility.credible_interval(0, 1) == credibility.credible_interval( + 1, 2, prior=(0, 0) )