2

As you probably know, the CDFs for many widely-used distributions are difficult, if not impossible, to express in closed form without the use of special functions

  • The normal distribution uses $\mathrm{erf}$.

  • Student's $t$-distribution requires the incomplete beta function or the Euler gamma function

  • The $\chi^2$ distribution requires the Euler gamma function and the lower incomplete gamma function.

I could continue, but you get the idea. Unfortunately, all of these functions share the property of being impossible to compute.

Does anybody know of a good (freely accessible) resource for approximating these various CDFs? Since I'm after p-values, I'm especially interested in approximations which are accurate for extreme values.

Macro
  • 40,561
  • 8
  • 143
  • 148
MathematicalOrchid
  • 2,430
  • 3
  • 13
  • 15
  • 5
    [R](http://cran.r-project.org/) – whuber May 10 '12 at 15:35
  • 3
    Let me add this: what precisely do you mean by "impossible to compute"? *All* the functions you name are no more "impossible" or difficult to compute than, say, $\exp$, $\sin$, $\cos$, or even $\sqrt{}$ for that matter. – whuber May 10 '12 at 17:30
  • Sqrt is easy to compute with a simple Newton iteration. The common transcendental functions such as $\sin$ can be computed with a truncated Taylor series. But I'm not aware of any known method that computes $\mathrm{erf}$. That's kind of the point of me asking. – MathematicalOrchid May 10 '12 at 19:02
  • See https://stats.stackexchange.com/questions/7200/evaluate-definite-interval-of-normal-distribution/29899#29899 for $\operatorname{erf}.$ It might give you some sense of how it becomes possible to compute values of transcendental functions. – whuber Mar 06 '20 at 15:34
  • See https://stats.stackexchange.com/questions/191492/how-does-saddlepoint-approximation-work/191781#191781 – kjetil b halvorsen Mar 06 '20 at 15:36

2 Answers2

4

To expand on @whuber's comments. What is wrong with the approximations that already exist?

You say that the square root is easy to compute, but the newton iteration approximates the square root, but does not give its exact value (unless you happen to have a situation where the root is rational and you get lucky in the itteration and rounding). So if you are happy with an approximation method for square roots and others then you should be happy approximating the erf and other functions, and those approximations already exist.

You could approximate the approximations that already exist with splines or logsplines or taylor series, or ..., but what advantage do these less accurate approximations of approximations have over the existing approximations?

The wikipedia link for the error function has many different approximations for it along with a long list of programs that implement approximations, those should fill your definition of good and freely accessable (for some on the list) resources. I would expect there will be similar links to the other functions mentioned.

But why not just use R?

Greg Snow
  • 46,563
  • 2
  • 90
  • 159
  • "What is wrong with the approximations that already exist?" I don't know what they are? Which is why I'm asking about them? – MathematicalOrchid May 11 '12 at 07:57
  • 1
    Did you follow the link in the answer? Did you read the page? Did you look at R like @whuber suggested (and provided a link)? Did you google (or other search) for "error function" or "library distribution function" or other possibilities? – Greg Snow May 11 '12 at 16:12
1

You can take a look into the GNU Scientific Library (gsl) which is free to use: https://www.gnu.org/software/gsl/doc/html/randist.html?highlight=tdist#

However, you need to look into the code to understand the algorithms if needed. The algorithms are really precise as they employ different methods depending on the parameters. So, it is complicated to understand them without prior knowledge.

Another easy to undestand resource is the famous book "Numerical recipes in C" http://numerical.recipes/, with a very good chapter for the algorithms.

Press, William H., Saul A. Teukolsky, William T. Vetterling, and Brian P. Flannery. "Numerical recipes in C." (1988).

enter image description here

Hamed
  • 21
  • 4