Last active
July 27, 2017 15:09
-
-
Save yoavram/963892760c83e6a984e10bd1ee2bf762 to your computer and use it in GitHub Desktop.
Revisions
-
Yoav Ram revised this gist
Jul 27, 2017 . 1 changed file with 18 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,25 @@ def bin_prop_jeffreys_interval(trials, successes, α=0.05): """Binomial proportions confidence Jeffrey's interval. Parameters ---------- trials : np.ndarray number of trials successes : int number of successes α : float, 0<α<1 width of confidence interval Returns ------- low, high : tuple of floats The lower and upper bounds of the proportions confidence interval See --- https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Jeffreys_interval """ import scipy.stats n = int(trials) x = int(successes) assert 0 <= x <= n -
Yoav Ram revised this gist
Jul 27, 2017 . 1 changed file with 27 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,35 @@ def bin_prop_jeffreys_interval(trials, successes, α=0.05): """Binomial proportions confidence Jeffrey's interval. Parameters ---------- trials : np.ndarray number of trials successes : int number of successes α : float, 0<α<1 width of confidence interval Returns ------- low, high : tuple of floats The lower and upper bounds of the proportions confidence interval See --- https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Jeffreys_interval """ import scipy.stats n = int(trials) x = int(successes) assert 0 <= x <= n beta = scipy.stats.beta(x + 0.5, n - x + 0.5) if x == 0: low = 0 else: low = beta.ppf(α / 2) if x == n: high = 1 else: high = beta.ppf(1 - α / 2) return x / n - low, high - x / n -
Yoav Ram revised this gist
Jul 20, 2017 . No changes.There are no files selected for viewing
-
Yoav Ram created this gist
Jul 20, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ def jeffreys_interval(trials, successes, α=0.05): n = int(trials) x = int(successes) beta = scipy.stats.beta(x + 0.5, n-x+0.5) if x == 0: low = 0 else: low = beta.ppf(α/2) if x == n: high = 1 else: high = beta.ppf(1-α/2) return x/n-low, high-x/n