0
$\begingroup$

I have a sample in normal distribution, with known average ($\mu$) and deviation ($\sigma$). As it is known, its probability density function is $f=\frac{1}{\sqrt{2\pi\sigma^2}}e^{-\frac{(x-\mu)^2}{2\sigma^2}}$.

However, what I need to say, that is the probability of that a given value is above (or below) a randomly selected element of the sample.

On this reason, what I would need, that is the inverse of the integrate of f. Already the integrate of f is not analytical ($e^{-x^2}$ has only definite integrals, as far I know).

And, it is yet more worse. I would actually need to approximate it, and ideally quickly1 and well2.

What is a good approximation3 of the inverse of the integrate of $f$?4

1O(1)

2The iteration steps approximate exponentially or yet more quicker the real value.

3"good approximation": usually used in practical mathematical statistics problems, if the applied software environment can not do that

4$(\int f)^{(-1)}$

$\endgroup$
9
  • $\begingroup$ Your formula (2) is different from what you describe in text $\endgroup$ Commented Jun 28 at 18:53
  • $\begingroup$ @kjetilbhalvorsen Right, fixed. (hopefully) $\endgroup$ Commented Jun 28 at 18:54
  • 4
    $\begingroup$ Common packages that support statistical mathematics implement this (qnorm in R, scipy.stats.norm.ppf in Python, even Excel has it in NORMSINV). So for practical use you'll best rely on an existing implementation. If you really need to roll out your own implementation, exploring the source code should be instructive AND/OR provide references for the specific algorithm used. $\endgroup$ Commented Jun 28 at 19:21
  • $\begingroup$ @MartinModrák Thanks. I use python and C. My hope is (was) that maybe a simple approx function exists, not much more complex as, for example, Newton's formula to approximate square roots. Advantage would be that I would very clearly see, what is it doing (the project has also a learning value for me). $\endgroup$ Commented Jun 28 at 20:01
  • 2
    $\begingroup$ Have a look at the source of R's qnorm, there is a bit of boundary checking but once you get to line ~80 it's pretty much self-contained. (I recently did something similar and trust me, it gets much more complicated than this for e.g. $\chi^2$ or $\Gamma$) $\endgroup$ Commented Jun 28 at 20:24

1 Answer 1

1
$\begingroup$

Fortunately, both the open source R and the scipy.stats Python package have implementations.

Checking their source, they are approximating it with a 8th grad rational function for most cases (and different formulas for cases very close to 0 or 1).

This is fast and good, but it is not an iterative algorithm and it is not simple. Probably no simple algorithm exists.

The professional optimum is to use them.

The good side of the algorithm is that it is even parallel-capable (both for CPU and GPU acceleration), as it has only operations usually available in massively parallel processing.

$\endgroup$

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.