-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicolo Musmeci
authored and
Nicolo Musmeci
committed
Sep 3, 2020
1 parent
e4e073a
commit 2318a93
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
from bayes import computeBayesTest | ||
|
||
def test_monotonicity_rates_v1(): | ||
_,P = computeBayesTest([0.2,0.1],1000) | ||
assert P.loc["A","B"] > 0.5 | ||
|
||
def test_monotonicity_rates_v2(): | ||
_,P1 = computeBayesTest([0.9,0.1],1000) | ||
_,P2 = computeBayesTest([0.2,0.1],1000) | ||
assert P1.loc["A","B"] >= P2.loc["A","B"] | ||
|
||
def test_monotonicity_volumes(): | ||
_,P1 = computeBayesTest([0.2,0.1],1000) | ||
_,P2 = computeBayesTest([0.2,0.1],100) | ||
assert P1.loc["A","B"] >= P2.loc["A","B"] | ||
|
||
def test_monotonicity_confidence(): | ||
C1,_ = computeBayesTest([0.2,0.1],1000,credible_interval_prob=80.) | ||
C2,_ = computeBayesTest([0.2,0.1],1000,credible_interval_prob=90.) | ||
assert C2.loc["A","B"][1]-C2.loc["A","B"][0] >= C1.loc["A","B"][1]-C1.loc["A","B"][0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
import numpy as np | ||
import re | ||
from bayes import computeBayesTest,computeBayesTestSampleSize | ||
|
||
def empiricalRateSuccess(n,p1,p2,n_mc): | ||
rate_list = np.random.binomial(n/2.,p2,n_mc)/(n/2.) | ||
pval_list = [np.nan for i in rate_list] | ||
for count,rate in enumerate(rate_list): | ||
pval_list[count] = computeBayesTest([p1,rate],n)[1].loc["B","A"] | ||
return(np.mean(np.array(pval_list)>0.8)) | ||
|
||
def test_size_1(): | ||
p1,p2 = 0.1,0.12 | ||
n_mc = 100 | ||
n = computeBayesTestSampleSize([p1,p2],accuracy=1) | ||
rate_success = empiricalRateSuccess(n,p1,p2,n_mc) | ||
assert ((rate_success<=0.83)and(rate_success>=0.77)),f"Rate success is {rate_success} instead of\ | ||
0.8, with sample size of {n}" | ||
|
||
def test_size_2(): | ||
p1,p2 = 0.5,0.8 | ||
n_mc = 100 | ||
n = computeBayesTestSampleSize([p1,p2],accuracy=1) | ||
rate_success = empiricalRateSuccess(n,p1,p2,n_mc) | ||
assert ((rate_success<=0.83)and(rate_success>=0.77)),f"""Rate success is {rate_success} instead of """ + \ | ||
f"""0.8, with sample size of {n}""" | ||
|
||
def test_error_large_diff(capfd): | ||
p1,p2 = 0.1,0.9 | ||
computeBayesTestSampleSize([p1,p2],accuracy=1) | ||
out, _ = capfd.readouterr() | ||
assert bool(re.match("""The values in the explored size range are all large enough to """ + \ | ||
"""confirm that the positive rates""",out)) | ||
|
||
def test_error_small_diff(capfd): | ||
p1,p2 = 0.1,0.10001 | ||
computeBayesTestSampleSize([p1,p2],accuracy=1) | ||
out, _ = capfd.readouterr() | ||
assert bool(re.match("""The values in the explored size range are too small to confirm """,out)) |