Search code examples
pythonpoisson

Better way to calculate λ in a Poisson distribution if the probability of occurrence P(X>0) is known


Currently I am using the following function but I am wondering if there is a more efficient way or a simple formula to accomplish this?

from scipy.stats import poisson

def calc_expected_value(event_proba):
    x = 0.01
    while round(1 - poisson.pmf(0, x), 2) != round(event_proba, 2):
        x += 0.01
    return x

Solution

  • P(X = 0) = exp(-lambda), hence P(X > 0) = 1 - exp(-lambda). If you call this probability event_proba, then

    exp(-lambda) = 1 - event_proba
    

    hence

    lambda = -log(1 - event_proba)
    

    Of course, in actual Python code you should avoid the name lambda since it has a built-in meaning.