Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Poisson confidence interval with numpy

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.

like image 457
Shep Avatar asked Feb 11 '13 13:02

Shep


1 Answers

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.

like image 199
Shep Avatar answered Sep 21 '22 13:09

Shep