SSJ
V. 2.6.

Package umontreal.iro.lecuyer.gof

This package contains tools for performing univariate goodness-of-fit (GOF) statistical tests.

See:
          Description

Class Summary
FBar This class is similar to FDist, except that it provides static methods to compute or approximate the complementary distribution function of X, which we define as bar(F)(x) = P[X >= x], instead of F(x) = P[X <= x].
FDist This class provides methods to compute (or approximate) the distribution functions of special types of goodness-of-fit test statistics.
GofFormat This class contains methods used to format results of GOF test statistics, or to apply a series of tests simultaneously and format the results.
GofStat This class provides methods to compute several types of EDF goodness-of-fit test statistics and to apply certain transformations to a set of observations.
GofStat.OutcomeCategoriesChi2 This class helps managing the partitions of possible outcomes into categories for applying chi-square tests.
KernelDensity This class provides methods to compute a kernel density estimator from a set of n individual observations x0,…, xn-1, and returns its value at m selected points.
 

Package umontreal.iro.lecuyer.gof Description

This package contains tools for performing univariate goodness-of-fit (GOF) statistical tests. Methods for computing (or approximating) the distribution function F(x) of certain GOF test statistics, as well as their complementary distribution function bar(F)(x) = 1 - F(x), are implemented in classes of package probdist. Tools for computing the GOF test statistics and the corresponding p-values, and for formating the results, are provided in classes GofStat and GofFormat.

We are concerned here with GOF test statistics for testing the hypothesis H0 that a sample of N observations X1,..., XN comes from a given univariate probability distribution F. We consider tests such as those of Kolmogorov-Smirnov, Anderson-Darling, Crámer-von Mises, etc. These test statistics generally measure, in different ways, the distance between a continuous distribution function F and the empirical distribution function (EDF) hat(F)N of X1,..., XN. They are also called EDF test statistics. The observations Xi are usually transformed into Ui = F(Xi), which satisfy 0 <= Ui <= 1 and which follow the U(0, 1) distribution under H0. (This is called the probability integral transformation.) Methods for applying this transformation, as well as other types of transformations, to the observations Xi or Ui are provided in GofStat.

Then the GOF tests are applied to the Ui sorted by increasing order. The corresponding p-values are easily computed by calling the appropriate methods in the classes of package probdist. If a GOF test statistic Y has a continuous distribution under H0 and takes the value y, its (right) p-value is defined as p = P[Y >= y | H0]. The test usually rejects H0 if p is deemed too close to 0 (for a one-sided test) or too close to 0 or 1 (for a two-sided test).

In the case where Y has a discrete distribution under H0, we distinguish the right p-value pR = P[Y >= y | H0] and the left p-value pL = P[Y <= y | H0]. We then define the p-value for a two-sided test as

p = pR         if pR < pL,
p = 1 - pL         if pR >= pL and pL < 0.5,
p = 0.5         otherwise.

Why such a definition? Consider for example a Poisson random variable Y with mean 1 under H0. If Y takes the value 0, the right p-value is pR = P[Y >= 0 | H0] = 1. In the uniform case, this would obviously lead to rejecting H0 on the basis that the p-value is too close to 1. However, P[Y = 0 | H0] = 1/e =  0.368, so it does not really make sense to reject H0 in this case. In fact, the left p-value here is pL = 0.368, and the p-value computed with the above definition is p = 1 - pL =  0.632. Note that if pL is very small, in this definition, p becomes close to 1. If the left p-value was defined as pL = 1 - pR = P[Y < y | H0], this would also lead to problems. In the example, one would have pL = 0 in that case.

A very common type of test in the discrete case is the chi-square test, which applies when the possible outcomes are partitioned into a finite number of categories. Suppose there are k categories and that each observation belongs to category i with probability pi, for 0 <= i < k. If there are n independent observations, the expected number of observations in category i is ei = npi, and the chi-square test statistic is defined as

X2 = ∑i=0k-1(oi - ei)2/ei

where oi is the actual number of observations in category i. Assuming that all ei's are large enough (a popular rule of thumb asks for ei >= 5 for each i), X2 follows approximately the chi-square distribution with k - 1 degrees of freedom. The class GofStat.OutcomeCategoriesChi2, a nested class defined inside the GofStat class, provides tools to automatically regroup categories in the cases where some ei's are too small.

The class GofFormat contains methods used to format results of GOF test statistics, or to apply several such tests simultaneously to a given data set and format the results to produce a report that also contains the p-values of all these tests. A C version of this class is actually used extensively in the package TestU01, which applies statistical tests to random number generators. The class also provides tools to plot an empirical or theoretical distribution function, by creating a data file that contains a graphic plot in a format compatible with a given software.


SSJ
V. 2.6.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.