4
$\begingroup$

Assuming a Poisson distribution, the probability ($\alpha$) that the result will fall within the range $0\ldots k$ is given by the following expression:

\begin{equation} \alpha = e^{-\lambda}\sum_{i=0}^{k}\frac{\lambda^i}{i!} \end{equation}

where $\lambda$ is the expected value (and variance).

In this particular case, the probability ($\alpha$) as well as the range ($k$) is known but the expected value ($\lambda$) is unknown. Is there a analytical solution or close approximation to the value of $\lambda$?

I have so far been solving the problem numerically by minimizing the equation but this is consuming a rather large part of the processing time of my computer which is why I am looking for ways to optimize my code.

$\endgroup$
2
  • $\begingroup$ Even something as simple-headed as binary section should take only tiny fractions of a second. $\endgroup$
    – Glen_b
    Commented Oct 14, 2014 at 9:10
  • $\begingroup$ You are correct. However, the minimization is performed in the order of tens of thousands to hundreds of thousands of times per second. $\endgroup$ Commented Oct 14, 2014 at 9:20

1 Answer 1

6
$\begingroup$

This is pretty straightforward; we just use the relationship between the Poisson and the chi squared:

If $Y\sim \text{Poisson}(\lambda)$ and $X\sim \chi^2_{2(k+1)}$, for integer $k$, then

$$F_Y(k) = 1-F_{X}(2\lambda) \,.$$

As a result, $$\lambda = \frac{1}{2}\, F_{X}^{-1}(1-F_Y(k))\,.$$

For example, in R, let's try to find the value of $\lambda$ corresponding to $k=6$ and $\alpha=0.1$:

> alpha=.1;k=6
> qchisq(1-alpha,2*(k+1))/2
[1] 10.53207
> ppois(k,10.53207)
[1] 0.1000001

So $\lambda\approx 10.53207$.

On my kids little laptop, running relatively slow R*, $10^5$ such calculations took me a well under a second.

*(compared to C, say)

Hopefully that will be fast enough for you.

$\endgroup$
3
  • $\begingroup$ (+1) The inverse chi-square is implemented even in spreadsheet software these days. $\endgroup$ Commented Oct 14, 2014 at 9:57
  • $\begingroup$ Why are you stealing your kid's little laptop to run R? :p $\endgroup$
    – Hong Ooi
    Commented Oct 14, 2014 at 10:02
  • 2
    $\begingroup$ Thanks for your help! I made a quick and simple comparison between using the minimization function I used first and your solution. The minimization function was able to calculate $\lambda$ approximately 3000 times per second whereas your solution was able to do it approximately 600 000 times per second. $\endgroup$ Commented Oct 14, 2014 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.