1 /* cdf/inverse_normal.c
3 * Copyright (C) 2002 Przemyslaw Sliwa and Jason H. Stover.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21 * Computes the inverse normal cumulative distribution function
22 * according to the algorithm shown in
24 * Wichura, M.J. (1988).
25 * Algorithm AS 241: The Percentage Points of the Normal Distribution.
26 * Applied Statistics, 37, 477-484.
30 #include <gsl/gsl_errno.h>
31 #include <gsl/gsl_math.h>
32 #include <gsl/gsl_cdf.h>
39 const double a[8] = { 3.387132872796366608, 133.14166789178437745,
40 1971.5909503065514427, 13731.693765509461125,
41 45921.953931549871457, 67265.770927008700853,
42 33430.575583588128105, 2509.0809287301226727
45 const double b[8] = { 1.0, 42.313330701600911252,
46 687.1870074920579083, 5394.1960214247511077,
47 21213.794301586595867, 39307.89580009271061,
48 28729.085735721942674, 5226.495278852854561
51 double r = 0.180625 - q * q;
53 double x = q * rat_eval (a, 8, b, 8, r);
59 intermediate (double r)
61 const double a[] = { 1.42343711074968357734, 4.6303378461565452959,
62 5.7694972214606914055, 3.64784832476320460504,
63 1.27045825245236838258, 0.24178072517745061177,
64 0.0227238449892691845833, 7.7454501427834140764e-4
67 const double b[] = { 1.0, 2.05319162663775882187,
68 1.6763848301838038494, 0.68976733498510000455,
69 0.14810397642748007459, 0.0151986665636164571966,
70 5.475938084995344946e-4, 1.05075007164441684324e-9
73 double x = rat_eval (a, 8, b, 8, (r - 1.6));
81 const double a[] = { 6.6579046435011037772, 5.4637849111641143699,
82 1.7848265399172913358, 0.29656057182850489123,
83 0.026532189526576123093, 0.0012426609473880784386,
84 2.71155556874348757815e-5, 2.01033439929228813265e-7
87 const double b[] = { 1.0, 0.59983220655588793769,
88 0.13692988092273580531, 0.0148753612908506148525,
89 7.868691311456132591e-4, 1.8463183175100546818e-5,
90 1.4215117583164458887e-7, 2.04426310338993978564e-15
93 double x = rat_eval (a, 8, b, 8, (r - 5.0));
99 gsl_cdf_ugaussian_Pinv (const double P)
114 if (fabs (dP) <= 0.425)
121 pp = (P < 0.5) ? P : 1.0 - P;
123 r = sqrt (-log (pp));
127 x = intermediate (r);
146 gsl_cdf_ugaussian_Qinv (const double Q)
161 if (fabs (dQ) <= 0.425)
168 pp = (Q < 0.5) ? Q : 1.0 - Q;
170 r = sqrt (-log (pp));
174 x = intermediate (r);
193 gsl_cdf_gaussian_Pinv (const double P, const double sigma)
195 return sigma * gsl_cdf_ugaussian_Pinv (P);
199 gsl_cdf_gaussian_Qinv (const double Q, const double sigma)
201 return sigma * gsl_cdf_ugaussian_Qinv (Q);