NAG Library Routine Document
G08CGF computes the test statistic for the goodness-of-fit test for data with a chosen number of class intervals.
|SUBROUTINE G08CGF (
||NCLASS, IFREQ, CB, DIST, PAR, NPEST, PROB, CHISQ, P, NDF, EVAL, CHISQI, IFAIL)
||NCLASS, IFREQ(NCLASS), NPEST, NDF, IFAIL
||CB(NCLASS-1), PAR(2), PROB(NCLASS), CHISQ, P, EVAL(NCLASS), CHISQI(NCLASS)
The goodness-of-fit test performed by G08CGF is used to test the null hypothesis that a random sample arises from a specified distribution against the alternative hypothesis that the sample does not arise from the specified distribution.
Given a sample of size
, denoted by
, drawn from a random variable
, and that the data has been grouped into
goodness-of-fit test statistic is defined by
is the observed frequency of the
th class, and
is the expected frequency of the
The expected frequencies are computed as
is the probability that
lies in the
th class, that is
These probabilities are either taken from a common probability distribution or are supplied by you. The available probability distributions within this routine are:
- Normal distribution with mean , variance ;
- uniform distribution on the interval ;
- exponential distribution with probability density function ;
- -distribution with degrees of freedom; and
- gamma distribution with .
You must supply the frequencies and classes. Given a set of data and classes the frequencies may be calculated using G01AEF
G08CGF returns the test statistic, , together with its degrees of freedom and the upper tail probability from the -distribution associated with the test statistic. Note that the use of the -distribution as an approximation to the distribution of the test statistic improves as the expected values in each class increase.
Conover W J (1980) Practical Nonparametric Statistics Wiley
Kendall M G and Stuart A (1973) The Advanced Theory of Statistics (Volume 2) (3rd Edition) Griffin
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill
- 1: NCLASS – INTEGERInput
On entry: , the number of classes into which the data is divided.
- 2: IFREQ(NCLASS) – INTEGER arrayInput
On entry: must specify the frequency of the th class, , for .
, for .
- 3: CB() – REAL (KIND=nag_wp) arrayInput
On entry: must specify the upper boundary value for the th class, for .
. For the exponential, gamma and -distributions .
- 4: DIST – CHARACTER(1)Input
: indicates for which distribution the test is to be carried out.
- The Normal distribution is used.
- The uniform distribution is used.
- The exponential distribution is used.
- The -distribution is used.
- The gamma distribution is used.
- You must supply the class probabilities in the array PROB.
, , , , or .
- 5: PAR() – REAL (KIND=nag_wp) arrayInput
: must contain the parameters of the distribution which is being tested. If you supply the probabilities (i.e.,
) the array PAR
is not referenced.
If a Normal distribution is used then and must contain the mean, , and the variance, , respectively.
If a uniform distribution is used then and must contain the boundaries and respectively.
If an exponential distribution is used then must contain the parameter . is not used.
If a -distribution is used then must contain the number of degrees of freedom. is not used.
If a gamma distribution is used and must contain the parameters and respectively.
- if , ;
- if , and and ;
- if , ;
- if , ;
- if , and .
- 6: NPEST – INTEGERInput
On entry: the number of estimated parameters of the distribution.
- 7: PROB(NCLASS) – REAL (KIND=nag_wp) arrayInput
: if you are supplying the probability distribution (i.e.,
must contain the probability that
lies in the
is not referenced.
if , , , for .
- 8: CHISQ – REAL (KIND=nag_wp)Output
On exit: the test statistic, , for the goodness-of-fit test.
- 9: P – REAL (KIND=nag_wp)Output
On exit: the upper tail probability from the -distribution associated with the test statistic, , and the number of degrees of freedom.
- 10: NDF – INTEGEROutput
On exit: contains , the degrees of freedom associated with the test.
- 11: EVAL(NCLASS) – REAL (KIND=nag_wp) arrayOutput
On exit: contains the expected frequency for the th class, , for .
- 12: CHISQI(NCLASS) – REAL (KIND=nag_wp) arrayOutput
On exit: contains the contribution from the th class to the test statistic, that is, , for .
- 13: IFAIL – INTEGERInput/Output
must be set to
. If you are unfamiliar with this parameter you should refer to Section 3.3
in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if
on exit, the recommended value is
. When the value is used it is essential to test the value of IFAIL on exit.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Note: G08CGF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
|On entry,||DIST is invalid.|
|On entry,|| for some , for .|
On entry, the elements of CB
are not in ascending order. That is,
On entry, , or and . No negative class boundary values are valid for the exponential, gamma or -distributions.
|On entry,||the values provided in PAR are invalid.|
|On entry,||with , for some , for ,|
An expected frequency is equal to zero when the observed frequency was not.
This is a warning that expected values for certain classes are less than . This implies that we cannot be confident that the -distribution is a good approximation to the distribution of the test statistic.
The solution obtained when calculating the probability for a certain class for the gamma or -distribution did not converge in iterations. The solution may be an adequate approximation.
The computations are believed to be stable.
The time taken by G08CGF is dependent both on the distribution chosen and on the number of classes, .
This example applies the
goodness-of-fit test to test whether there is evidence to suggest that a sample of
randomly generated observations do not arise from a uniform distribution
. The class intervals are calculated such that the interval
is divided into five equal classes. The frequencies for each class are calculated using G01AEF
9.1 Program Text
Program Text (g08cgfe.f90)
9.2 Program Data
Program Data (g08cgfe.d)
9.3 Program Results
Program Results (g08cgfe.r)