Created
February 23, 2015 09:45
-
-
Save BrianOn99/8e2d218dedca30726ced to your computer and use it in GitHub Desktop.
poisson 95% confidence interval with scipy
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
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:1d71f04e6484b78595702fc90c1d6312b9d46cec685a650540b54987368fa731" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# asking for 95% confidence interval for a parameter lambda of\n", | |
"# a poisson distribution if 3 events detected" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"from scipy.stats import poisson\n", | |
"import scipy.optimize as optimize\n", | |
"\n", | |
"threshold_lambda = optimize.bisect(lambda l: poisson.cdf(3, mu=l) - 0.05, 1, 10)\n", | |
"print(threshold_lambda)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"7.75365652793\n" | |
] | |
} | |
], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# there is a backbround signal of lambda = 2.5, subtract it out\n", | |
"print(\"95% confidence interval : {} to {}\".format(0, threshold_lambda-2.5))" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"95% confidence interval : 0 to 5.25365652793\n" | |
] | |
} | |
], | |
"prompt_number": 5 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment