statsmodels.stats.contingency_tables.mcnemar

statsmodels.stats.contingency_tables.mcnemar(table, exact=True, correction=True)[source]

McNemar test of homogeneity.

Parameters:
tablearray_like

A square contingency table.

exactbool

If exact is true, then the binomial distribution will be used. If exact is false, then the chisquare distribution will be used, which is the approximation to the distribution of the test statistic for large sample sizes.

correctionbool

If true, then a continuity correction is used for the chisquare distribution (if exact is false.)

Returns:
A bunch with attributes:
statisticfloat or int, array

The test statistic is the chisquare statistic if exact is false. If the exact binomial distribution is used, then this contains the min(n1, n2), where n1, n2 are cases that are zero in one sample but one in the other sample.

pvaluefloat or array

p-value of the null hypothesis of equal marginal distributions.

Notes

This is a special case of Cochran’s Q test, and of the homogeneity test. The results when the chisquare distribution is used are identical, except for continuity correction.