简体   繁体   中英

one-sided Poisson confidence interval in python

Given this code that was given as an answer in another question:

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 snippet returns a two-sided confidence interval, but how would I do it if I want it one-sided. This is more complicated as the Poisson distribution is asymmetrical. Any help would be greatly appreciated.

I think you should change a/2 to a or 0 as it indicates where the interval lies:

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(0, 2*k) / 2, chi2.ppf(1-a, 2*k + 2) / 2)
    if k == 0: 
        low = 0.0
    return low, high

Tell me if it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM