ICHISQ 3CW "29 March 2006" "mathcw-1.00"

Table of contents


NAME

ichisqf, ichisq, ichisql, ichisqw, ichisqq, ichisqll, ichisqdf, ichisqd, ichisqdl, ichisqdll - inverse of chi-square distribution function

SYNOPSIS

cc [ flags ] -I/usr/local/include file(s) -L/usr/local/lib -lmcw [ ... ]

#include <mathcw.h>

extern float ichisqf (int nu, float p);

extern double ichisq (int nu, double p);

extern long double ichisql (int nu, long double p);

extern __float80 ichisqw (int nu, __float80 p);

extern __float128 ichisqq (int nu, __float128 p);

extern long_long_double ichisqll (int nu, long_long_double p);

extern decimal_float ichisqdf (int nu, decimal_float p);

extern decimal_double ichisqd (int nu, decimal_double p);

extern decimal_long_double ichisqdl (int nu, decimal_long_double p);

extern decimal_long_long_double ichisqdll (int nu, decimal_long_long_double p);

NB: Functions with prototypes containing underscores in type names may be available only with certain extended compilers.


DESCRIPTION

Compute the inverse of the chi-square distribution function for nu degrees of freedom (an integer in [0, Infinity)) and probability p (in [0,1]). This is the chi-square measure that corresponds to that probability, and the functions have these relations:
chisq(nu, x) = p,
ichisq(nu, p) = x.
In the statistics literature, the notations for the chi-square probability use functions P and Q with these relations to ours:
P(x**2|nu) = chisq(nu,x**2),
Q(x**2|nu) = 1 - P(x**2|nu).
When P is large, it is better to compute the small value Q from the complementary incomplete gamma function, and obtain the other by subtraction:
Q(x**2|nu) = gamic(nu/2, x**2/2),
P(x**2|nu) = 1 - Q(x**2|nu).
The chi-square measure is a common statistical test for evaluating the goodness-of-fit of data to a model. For n experiments, if the measured value in experiment k is M(k), and the expected value is E(k), then the value
x = sum(k = 1 to n) (M(k) - E(k))**2 / E(k)
is the chi-square measure.

The number of degrees of freedom is the number of independent variables: for example, a coin toss has two outcomes, but only one degree of freedom (if it is not heads, then it must be tails).

A p-value near 0 or 1 suggests that the model fits the data poorly. Conversely, given, for example, p = 0.95, there is a 95% chance that, if the model fits the data, the computed chi-square measure should not exceed the value x returned by ichisq(nu, 0.95). If it does, then the model may be in poor agreement with experiment.


CAVEAT

For large nu, and for p near 1, the distribution is almost flat, and its accurate inversion requires high precision. Consequently, the lower-precision members of the inverse function family should be avoided in such cases.

RETURN VALUES

If p is a NaN, return that NaN. If p is outside the range [0,1], return a quiet NaN. Otherwise, return the inverse of chi-square distribution function.

ERRORS

If x is negative, set errno to EDOM. If x is a NaN, set errno to EDOM.

INVERSE CHI-SQUARE TABLE

Mathematical and statistical handbooks, and textbook treatments of the chi-square distribution, often contain tables like this one computed from ichisq(nu,p), extending an example in the book Donald E. Knuth, The Art of Computer Programming, vol. 2, Seminumerical Algorithms, Addison-Wesley (1997), ISBN 0-201-89684-2, p. 44:

---------------------------------------------------------------------
p =            0.01      0.05    0.25    0.50    0.75    0.95    0.99
---------------------------------------------------------------------
nu =    1 0.0001571  0.003932  0.1015  0.4549   1.323   3.841   6.635
nu =    2   0.02010    0.1026  0.5754   1.386   2.773   5.991   9.210
nu =    3    0.1148    0.3518   1.213   2.366   4.108   7.815   11.34
nu =    4    0.2971    0.7107   1.923   3.357   5.385   9.488   13.28
nu =    5    0.5543     1.145   2.675   4.351   6.626   11.07   15.09
nu =    6    0.8721     1.635   3.455   5.348   7.841   12.59   16.81
nu =    7     1.239     2.167   4.255   6.346   9.037   14.07   18.48
nu =    8     1.646     2.733   5.071   7.344   10.22   15.51   20.09
nu =    9     2.088     3.325   5.899   8.343   11.39   16.92   21.67
nu =   10     2.558     3.940   6.737   9.342   12.55   18.31   23.21
nu =   11     3.053     4.575   7.584   10.34   13.70   19.68   24.72
nu =   12     3.571     5.226   8.438   11.34   14.85   21.03   26.22
nu =   15     5.229     7.261   11.04   14.34   18.25   25.00   30.58
nu =   20     8.260     10.85   15.45   19.34   23.83   31.41   37.57
nu =   30     14.95     18.49   24.48   29.34   34.80   43.77   50.89
nu =   50     29.71     34.76   42.94   49.33   56.33   67.50   76.15
nu =   99     69.23     77.05   89.18   98.33   108.1   123.2   134.6
nu =  100     70.06     77.93   90.13   99.33   109.1   124.3   135.8
nu =  999     898.0     926.6   968.5   998.3   1029.   1074.   1106.
nu = 1000     898.9     927.6   969.5   999.3   1030.   1075.   1107.
---------------------------------------------------------------------

For example, the last entry in the first line says that ichisq(1,0.99) = 6.635 is the chi-square measure at the 99-th percentile. About 99% of repeated coin-toss experiments should produce chi-square measures no larger than that value, if the coin and the tosses are fair.


SEE ALSO

chisq(3CW), erf(3CW), erfc(3CW), exp(3CW), gami(3CW), gamib(3CW), gamic(3CW), lgamma(3CW), pow(3CW), tgamma(3CW).