naginterfaces.library.contab.chisq

naginterfaces.library.contab.chisq(nobs)[source]

chisq computes statistics for a two-way contingency table. For a table with a small number of observations exact probabilities are computed.

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

https://support.nag.com/numeric/nl/nagdoc_30.2/flhtml/g11/g11aaf.html

Parameters
nobsint, array-like, shape

The contingency table must contain , for , for .

Returns
exptfloat, ndarray, shape

The table of expected values. contains , for , for .

chistfloat, ndarray, shape

The table of contributions. contains , for , for .

probfloat

If , and then contains the two tail significance level for Fisher’s exact test, otherwise contains the significance level from the Pearson statistic.

chifloat

The Pearson statistic.

gfloat

The likelihood ratio test statistic.

dffloat

The degrees of freedom for the statistics.

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, all elements of .

(errno )

On entry, , and .

Constraint: .

(errno )

On entry, a table has a row or column with both values zero.

Warns
NagAlgorithmicWarning
(errno )

At least one cell has an expected frequency, .

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.

For a set of observations classified by two variables, with and levels respectively, a two-way table of frequencies with rows and columns can be computed.

To measure the association between the two classification variables two statistics that can be used are, the Pearson statistic, , and the likelihood ratio test statistic, , where are the fitted values from the model that assumes the effects due to the classification variables are additive, i.e., there is no association. These values are the expected cell frequencies and are given by

Under the hypothesis of no association between the two classification variables, both these statistics have, approximately, a -distribution with degrees of freedom. This distribution is arrived at under the assumption that the expected cell frequencies, , are not too small. For a discussion of this point see Everitt (1977). He concludes by saying, ‘… in the majority of cases the chi-square criterion may be used for tables with expectations in excess of in the smallest cell’.

In the case of the table, i.e., and , the approximation can be improved by using Yates’ continuity correction factor. This decreases the absolute value of by . For tables with a small value of the exact probabilities from Fisher’s test are computed. These are based on the hypergeometric distribution and are computed using stat.prob_hypergeom. A two tail probability is computed as , where and are the upper and lower one-tail probabilities from the hypergeometric distribution.

References

Everitt, B S, 1977, The Analysis of Contingency Tables, Chapman and Hall

Kendall, M G and Stuart, A, 1973, The Advanced Theory of Statistics (Volume 2), (3rd Edition), Griffin