### Function Reference: `mcnemar_test`

statistics: [h, pval, chisq] = mcnemar_test (x)
statistics: [h, pval, chisq] = mcnemar_test (x, alpha)
statistics: [h, pval, chisq] = mcnemar_test (x, testtype)
statistics: [h, pval, chisq] = mcnemar_test (x, alpha, testtype)

Perform a McNemar’s test on paired nominal data.

@nospell{McNemar’s} test is applied to a 2×2 contingency table x with a dichotomous trait, with matched pairs of subjects, of data cross-classified on the row and column variables to testing the null hypothesis of symmetry of the classification probabilities. More formally, the null hypothesis of marginal homogeneity states that the two marginal probabilities for each outcome are the same.

Under the null, with a sufficiently large number of discordants (`x(1,2) + x(2,1) >= 25`), the test statistic, chisq, follows a chi-squared distribution with 1 degree of freedom. When the number of discordants is less than 25, then the mid-P exact McNemar test is used.

testtype will force `mcnemar_test` to apply a particular method for testing the null hypothesis independently of the number of discordants. Valid options for testtype:

- `"asymptotic"` Original McNemar test statistic
- `"corrected"` Edwards’ version with continuity correction
- `"exact"` An exact binomial test
- `"mid-p"` The mid-P McNemar test (mid-p binomial test)

The test decision is returned in h, which is 1 when the null hypothesis is rejected (`pval < alpha`) or 0 otherwise. alpha defines the critical value of statistical significance for the test.

Further information about the McNemar’s test can be found at https://en.wikipedia.org/wiki/McNemar%27s_test

See also: crosstab, chi2test, fishertest

Source Code: mcnemar_test