Skip to content

Instantly share code, notes, and snippets.

@BrianOn99
Created February 23, 2015 09:45
Show Gist options
  • Save BrianOn99/8e2d218dedca30726ced to your computer and use it in GitHub Desktop.
Save BrianOn99/8e2d218dedca30726ced to your computer and use it in GitHub Desktop.
poisson 95% confidence interval with scipy
{
"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