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

Time:10-06

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

CodePudding user response:

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.

CodePudding user response:

Here it is as a simple formula:

from math import log

def calc_lambda(p_gt_0):
    return -log(1.0 - p_gt_0)

This is derived from the fact that P{X=0} = 1 - P{X>0}. Plug in the formula for a Poisson probability and solve to yield the implementation given above.

  • Related