naginterfaces.library.nonpar.test_​chisq

naginterfaces.library.nonpar.test_chisq(ifreq, cb, dist, par, npest, prob)[source]

test_chisq computes the test statistic for the goodness-of-fit test for data with a chosen number of class intervals.

For full information please refer to the NAG Library document for g08cg

https://www.nag.com/numeric/nl/nagdoc_29.3/flhtml/g08/g08cgf.html

Parameters
ifreqint, array-like, shape

must specify the frequency of the th class, , for .

cbfloat, array-like, shape

must specify the upper boundary value for the th class, for .

diststr, length 1

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 .

parfloat, array-like, shape

Must contain the parameters of the distribution which is being tested. If you supply the probabilities (i.e., ) the array 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.

npestint

The number of estimated parameters of the distribution.

probfloat, array-like, shape

If you are supplying the probability distribution (i.e., ) then must contain the probability that lies in the th class.

If , is not referenced.

Returns
chisqfloat

The test statistic, , for the goodness-of-fit test.

pfloat

The upper tail probability from the -distribution associated with the test statistic, , and the number of degrees of freedom.

ndfint

Contains , the degrees of freedom associated with the test.

efreqfloat, ndarray, shape

contains the expected frequency for the th class, , for .

chisqifloat, ndarray, shape

contains the contribution from the th class to the test statistic, that is, , for .

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: , , , , or .

(errno )

On entry, .

Constraint: .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, , and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, and .

Constraint: for the gamma distribution, and .

(errno )

On entry, .

Constraint: for the distribution, .

(errno )

On entry, .

Constraint: for the exponential distribution, .

(errno )

On entry, and .

Constraint: for the uniform distribution, , and .

(errno )

On entry, .

Constraint: for the Normal distribution, .

(errno )

On entry, .

Constraint: .

(errno )

On entry, and .

Constraint:

(errno )

An expected frequency equals zero, when the observed frequency was not.

Warns
NagAlgorithmicWarning
(errno )

At least one class has an expected frequency less than .

(errno )

The solution has failed to converge whilst computing the expected values. The returned solution may be an adequate approximation.

Notes

In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.

The goodness-of-fit test performed by test_chisq 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 function 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 stat.frequency_table.

test_chisq 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.

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