NAG Library Routine Document
g08cgf
(test_chisq)
1
Purpose
g08cgf computes the test statistic for the goodness-of-fit test for data with a chosen number of class intervals.
2
Specification
Fortran Interface
Subroutine g08cgf ( |
nclass,
ifreq,
cb,
dist,
par,
npest,
prob,
chisq,
p,
ndf,
eval,
chisqi,
ifail) |
Integer, Intent (In) | :: |
nclass,
ifreq(nclass),
npest | Integer, Intent (Inout) | :: |
ifail | Integer, Intent (Out) | :: |
ndf | Real (Kind=nag_wp), Intent (In) | :: |
cb(nclass-1),
par(2),
prob(nclass) | Real (Kind=nag_wp), Intent (Out) | :: |
chisq,
p,
eval(nclass),
chisqi(nclass) | Character (1), Intent (In) | :: |
dist |
|
C Header Interface
#include nagmk26.h
void |
g08cgf_ (
const Integer *nclass,
const Integer ifreq[],
const double cb[],
const char *dist,
const double par[],
const Integer *npest,
const double prob[],
double *chisq,
double *p,
Integer *ndf,
double eval[],
double chisqi[],
Integer *ifail,
const Charlen length_dist) |
|
3
Description
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.
4
References
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
5
Arguments
- 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.
If
,
prob is not referenced.
Constraint:
if , , , for .
- 8: – Real (Kind=nag_wp)Output
-
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
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation 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 arguments 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.
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
or
, 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, | , |
or | . |
-
On entry, | for some , for . |
-
On entry, the elements of
cb are not in ascending order. That is,
for some
, for
.
-
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 , |
or | . |
-
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.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
The computations are believed to be stable.
8
Parallelism and Performance
g08cgf is not threaded in any implementation.
The time taken by g08cgf is dependent both on the distribution chosen and on the number of classes, .
10
Example
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.
10.1
Program Text
Program Text (g08cgfe.f90)
10.2
Program Data
Program Data (g08cgfe.d)
10.3
Program Results
Program Results (g08cgfe.r)