# McNemar's test

This page offers all the basic information you need about the mcnemar's test. It is part of Statkat’s wiki module, containing similarly structured info pages for many different statistical methods. The info pages give information about null and alternative hypotheses, assumptions, test statistics and confidence intervals, how to find *p * values, SPSS how-to’s and more.

To compare the mcnemar's test with other statistical methods, go to Statkat's or practice with the mcnemar's test at Statkat's

##### Contents

- 1. When to use
- 2. Null hypothesis
- 3. Alternative hypothesis
- 4. Assumptions
- 5. Test statistic
- 6. Sampling distribution
- 7. Significant?
- 8. Equivalent to
- 9. Example context
- 10. SPSS
- 11. Jamovi

##### When to use?

Deciding which statistical method to use to analyze your data can be a challenging task. Whether a statistical method is appropriate for your data is partly determined by the measurement level of your variables. The mcnemar's test requires the following variable types:

Independent variable: 2 paired groups | Dependent variable: One categorical with 2 independent groups |

Note that theoretically, it is always possible to 'downgrade' the measurement level of a variable. For instance, a test that can be performed on a variable of ordinal measurement level can also be performed on a variable of interval measurement level, in which case the interval variable is downgraded to an ordinal variable. However, downgrading the measurement level of variables is generally a bad idea since it means you are throwing away important information in your data (an exception is the downgrade from ratio to interval level, which is generally irrelevant in data analysis).

If you are not sure which method you should use, you might like the assistance of our method selection tool or our method selection table.

##### Null hypothesis

The mcnemar's test tests the following null hypothesis (H_{0}):

Let's say that the scores on the dependent variable are scored 0 and 1. Then for each pair of scores, the data allow four options:

- First score of pair is 0, second score of pair is 0
- First score of pair is 0, second score of pair is 1 (switched)
- First score of pair is 1, second score of pair is 0 (switched)
- First score of pair is 1, second score of pair is 1

_{0}is that for each pair of scores, P(first score of pair is 0 while second score of pair is 1) = P(first score of pair is 1 while second score of pair is 0). That is, the probability that a pair of scores switches from 0 to 1 is the same as the probability that a pair of scores switches from 1 to 0.

Other formulations of the null hypothesis are:

- H
_{0}: $\pi_1 = \pi_2$, where $\pi_1$ is the population proportion of ones for the first paired group and $\pi_2$ is the population proportion of ones for the second paired group - H
_{0}: for each pair of scores, P(first score of pair is 1) = P(second score of pair is 1)

##### Alternative hypothesis

The mcnemar's test tests the above null hypothesis against the following alternative hypothesis (H_{1} or H_{a}):

The alternative hypothesis H_{1} is that for each pair of scores, P(first score of pair is 0 while second score of pair is 1) $\neq$ P(first score of pair is 1 while second score of pair is 0). That is, the probability that a pair of scores switches from 0 to 1 is not the same as the probability that a pair of scores switches from 1 to 0.

Other formulations of the alternative hypothesis are:

- H
_{1}: $\pi_1 \neq \pi_2$ - H
_{1}: for each pair of scores, P(first score of pair is 1) $\neq$ P(second score of pair is 1)

##### Assumptions

Statistical tests always make assumptions about the sampling procedure that was used to obtain the sample data. So called parametric tests also make assumptions about how data are distributed in the population. Non-parametric tests are more 'robust' and make no or less strict assumptions about population distributions, but are generally less powerful. Violation of assumptions may render the outcome of statistical tests useless, although violation of some assumptions (e.g. independence assumptions) are generally more problematic than violation of other assumptions (e.g. normality assumptions in combination with large samples).

The mcnemar's test makes the following assumptions:

- Sample of pairs is a simple random sample from the population of pairs. That is, pairs are independent of one another

##### Test statistic

The mcnemar's test is based on the following test statistic:

$X^2 = \dfrac{(b - c)^2}{b + c}$Here $b$ is the number of pairs in the sample for which the first score is 0 while the second score is 1, and $c$ is the number of pairs in the sample for which the first score is 1 while the second score is 0.

##### Sampling distribution

Sampling distribution of $X^2$ if H_{0}were true:

If $b + c$ is large enough (say, > 20), approximately the chi-squared distribution with 1 degree of freedom.

If $b + c$ is small, the Binomial($n$, $P$) distribution should be used, with $n = b + c$ and $P = 0.5$. In that case the test statistic becomes equal to $b$.

##### Significant?

This is how you find out if your test result is significant:

For test statistic $X^2$:- Check if $X^2$ observed in sample is equal to or larger than critical value $X^{2*}$ or
- Find $p$ value corresponding to observed $X^2$ and check if it is equal to or smaller than $\alpha$

- Check if $b$ observed in sample is in the rejection region or
- Find two sided $p$ value corresponding to observed $b$ and check if it is equal to or smaller than $\alpha$

##### Equivalent to

The mcnemar's test is equivalent to:

- Stuart-Maxwell test, with a categorical dependent variable consisting of two independent groups
- Cochran's Q test, with two related groups
- Two sided sign test: $b = W$, and $X^2 = z^2$

##### Example context

The mcnemar's test could for instance be used to answer the question:

Does a tv documentary about spiders change whether people are afraid (yes/no) of spiders?##### SPSS

How to perform the mcnemar's test in SPSS:

Analyze > Nonparametric Tests > Legacy Dialogs > 2 Related Samples...- Put the two paired variables in the boxes below Variable 1 and Variable 2
- Under Test Type, select the McNemar test

##### Jamovi

How to perform the mcnemar's test in jamovi:

Frequencies > Paired Samples - McNemar test- Put one of the two paired variables in the box below Rows and the other paired variable in the box below Columns