I'm trying to put Poisson continuous error bars on a histogram I'm making with matplotlib, but I can't seem to find a numpy function that will given me a 95% confidence interval assuming poissonian data. Ideally the solution doesn't depend on scipy, but anything will work. Does such a function exist? I've found a lot about bootstrapping but this seems a bit excessive in my case.
I ended up writing my own function based on some properties I found on Wikipedia.
def poisson_interval(k, alpha=0.05):
"""
uses chisquared info to get the poisson interval. Uses scipy.stats
(imports in function).
"""
from scipy.stats import chi2
a = alpha
low, high = (chi2.ppf(a/2, 2*k) / 2, chi2.ppf(1-a/2, 2*k + 2) / 2)
if k == 0:
low = 0.0
return low, high
This returns continuous (rather than discrete) bounds, which is more standard in my field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With