The routine may be called by the names g08cgf or nagf_nonpar_test_chisq.
3Description
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 classes,
then the goodness-of-fit test statistic is defined by
where is the observed frequency of the th class, and is the expected frequency of the th class.
The expected frequencies are computed as
where 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.
4References
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
5Arguments
1: – IntegerInput
On entry: , the number of classes into which the data is divided.
Constraint:
.
2: – Integer arrayInput
On entry: must specify the frequency of the th class, , for .
Constraint:
, for .
3: – Real (Kind=nag_wp) arrayInput
On entry: must specify the upper boundary value for the th class, for .
Constraint:
. For the exponential, gamma and -distributions .
4: – Character(1)Input
On entry: 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.
Constraint:
, , , , or .
5: – Real (Kind=nag_wp) arrayInput
On entry: 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.
Constraints:
if , ;
if , and and ;
if , ;
if , ;
if , and .
6: – IntegerInput
On entry: the number of estimated parameters of the distribution.
Constraint:
.
7: – Real (Kind=nag_wp) arrayInput
On entry: if you are supplying the probability distribution (i.e., ) then must contain the probability that lies in the th class.
On exit: the test statistic, , for the goodness-of-fit test.
9: – 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: – IntegerOutput
On exit: contains , the degrees of freedom associated with the test.
11: – Real (Kind=nag_wp) arrayOutput
On exit: contains the expected frequency for the th class, , for .
12: – Real (Kind=nag_wp) arrayOutput
On exit: contains the contribution from the th class to the test statistic, that is, , for .
13: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended since useful values can be provided in some output arguments even when on exit. When the value or is used it is essential to test the value of ifail on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
Note: in some cases g08cgf may return useful information.
On entry, .
Constraint: .
On entry, .
Constraint: , , , , or .
On entry, .
Constraint: .
On entry, and .
Constraint: .
On entry, , and .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: for the exponential distribution, .
On entry, .
Constraint: for the distribution, .
On entry, and .
Constraint: for the gamma distribution, and .
On entry, and .
Constraint: for the uniform distribution, , and .
On entry, .
Constraint: for the Normal distribution, .
On entry, and .
Constraint:
On entry, .
Constraint: .
An expected frequency equals zero, when the observed frequency was not.
At least one class has an expected frequency less than . The distribution may not be a good approximation to the distribution of the test statistic.
The solution has failed to converge whilst computing the expected values. The returned solution may be an adequate approximation.
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
The computations are believed to be stable.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g08cgf is not threaded in any implementation.
9Further Comments
The time taken by g08cgf is dependent both on the distribution chosen and on the number of classes, .
10Example
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.