McNemar's Test Calculator
Table of contents
What is McNemar's test for paired proportions?How do I calculate the contingency table for McNemar's test?McNemar's test definitionHow to perform McNemar's test?What is McNemar's exact test?How to use this McNemar's test calculatorMcNemar's test exampleFAQsOmni's McNemar's test calculator can help you perform different versions of McNemar's test for paired proportions  as many as five versions of this test are available. In particular, this tool can serve as McNemar's exact test calculator.
Not sure what the definition of McNemar's test is? Scroll down to learn everything you need about it (the correct interpretation of McNemar's test included). At the end of this article, you'll find an example of McNemar's test to see how it works in practice.
What is McNemar's test for paired proportions?
Let's first discuss what the assumptions of McNemar's test are. As you might've already heard, this statistical test deals with paired binomial data. More precisely, we call on McNemar's test when we have two paired groups, for instance, patients before and after treatment. Additionally, we have the values of a dichotomous variable (i.e., a variable with only two categories). So, for our patients, we can have a result of some medical test that is either positive or negative.
Other examples of when we can use McNemar's test:
 Maths exam result (pass vs. fail) of a group of students prior to and following a special preparatory curse.
 The will of citizens (yes vs. no) to vote for candidates before and after watching their TV spot.
💡 Have you seen our paired ttest calculator? McNemar's test has a similar aim, but it uses a dichotomous dependent variable, while the ttest needs a continuous variable.
Like in the ttest, the crucial assumption of McNemar's test is that we have a simple random sample (i.e., a set of independent, identically distributed random variables).
When we want to perform McNemar's test, the first step is to prepare the contingency table. We'll discuss this in the next section. And once we have the contingency tables, we'll be able to state the hypotheses of McNemar's test more formally. Let's go!
How do I calculate the contingency table for McNemar's test?
The contingency table that appears in the context of McNemar's test is a 2 x 2 table registering how many subjects fall into a given pair of categories. For instance, for patients subject to a test before and after treatment, we have the following pairs of categories:
 Before treatment and positive test result;
 After treatment and positive test result;
 Before treatment and negative test result; and
 After treatment and negative test result.
The corresponding contingency table looks like this:
before  after  

positive  
negative 
As you can see, there are four fields, which we need to fill in with the data we obtained during our experiment. Assume we have:
a
people in the beforeandpositive group;b
people in the afterandpositive group;c
people in the beforeandnegative group; andd
people in the afterandnegative group.
This translates into the following table:
before  after  

positive  a  b  
negative  c  d 
We can now easily add to our table both column totals and row totals. By N
, we denote the total number of observations.
before  after  row total  

positive  a  b  a+b 
negative  c  d  c+d 
column total  a+c  b+d  N 
Having discussed the contingency table, we are in a good position to discuss the hypotheses connected to McNemar's test.
McNemar's test definition
Let's denote by p_{a}, p_{b}, p_{c}, p_{d} the theoretical probability of their respective group:
before  after  row total  

positive  p_{a}  p_{b}  p_{a}+p_{b} 
negative  p_{c}  p_{d}  p_{c}+p_{d} 
column total  p_{a}+p_{c}  p_{b}+p_{d} 
As probabilities always sum to one, we obviously have:
p_{a} + p_{b} + p_{c} + p_{d} = 1
Now, the null hypothesis of McNemar's test is a claim about the marginal distributions. Namely, it states that the row marginal and column marginal are equal  people often call this the hypothesis of marginal homogeneity:
H₀: p_{a} + p_{b} = p_{a} + p_{c}
(and p_{c} + p_{d} = p_{b} + p_{d}, but this follows immedately from the previous equation).
The alternative hypothesis is that the marginal distributions are not equal, i.e., that the above equation does not hold:
H₁: p_{a} + p_{b} ≠ p_{a} + p_{c}
Simplifying these equations, we get a slightly simpler form of our hypotheses, which you can often see in textbooks:
H₀: p_{b} = p_{c}
H₁: p_{b} ≠ p_{c}
McNemar's test interpretation
Let's discuss the interpretation of McNemar's test by stating the hypotheses this test deals with, without any mathematical notation:
 The null hypothesis of McNemar's test is that the treatment (or the preparatory math course or the TV spot) has no effect on the proportion of people with the positive result (or, respectively, the proportion of students passing the exam, or that of citizens willing to vote in favor of our candidate).
 The alternative hypothesis is that these proportions differ significantly, and so the treatment (course/TV spot) does have some effect.
A quick tip: don't focus that much on formulas, but try to remember the examples  they are beneficial when it comes to recalling the correct interpretation of McNemar's test for paired proportions.
How to perform McNemar's test?
When we've got the contingency table ready, we can quickly and easily compute McNemar's test statistic. The formula employs only the offdiagonal fields from the contingency table:
χ² = (b  c)² / (b + c)
Under the null hypothesis and if b
and c
are large enough, then χ²
follows approximately the chisquared distribution with 1
degree of freedom.
Note that, under the null hypothesis, we expect to observe small test statistic values. Indeed, if p_{b} = p_{c}, then in our data b
should be roughly equal to c
, which translates into small values of χ²
. Hence, by contradiction, big values of χ²
provide evidence in favor of the alternative hypothesis H₁. The next step of McNemar's test depends on the approach you want to use:

pvalue approach  To calculate the pvalue, you have to compute the probability that a random variable with the chisquared distribution with
1
degree of freedom assumes values greater than or equal to the value of the test statisticχ²
we've got for our sample:pvalue = 1  cdf(χ²)
where
cdf
is the cumulative distribution function of the chisquared distribution with1
degree of freedom. If thepvalue
is smaller than the significance level we set for the test, we reject the null hypothesis. 
Critical region approach — The critical region is rightsided, i.e., it takes the form
[k, ∞)
, where the critical valuek
is the(1α)
quantile of the chisquared distribution with1
degree of freedom andα
is the significance level you set for the test. Ifχ²
falls into the critical region, i.e., ifχ² ≥ k
, we reject the null hypothesis.
🙋 If you're not sure what the two approaches mentioned above are, make sure to visit our tools that cover these important concepts:
Corrections to the test statistics
When we approximate a smooth distribution (in this case, the chisquared distribution) with a discrete distribution, we are bound to have some inaccuracy, for which we can compensate by using a continuity correction. In the case of McNemar's test, the correction appears in the numerator of the test statistics. It involves:
 Taking first the absolute value of
bc
.  Subtracting some constant from it.
 Squaring the resulting number.
The denominator remains unchanged. There are two corrections you can encounter:

Edwards correction
χ² = (b  c  1)² / (b + c)

Yates correction
χ² = (b  c  ½)² / (b + c)
Edwards correction is more widespread, and some statistical packages use it by default  keep that in mind when they give a different value of χ²
than you expected.
What is McNemar's exact test?
As mentioned earlier, in the standard way of performing McNemar's test, we approximate the distribution of the test statistic with the chisquared distribution with 1
degree of freedom. However, as always, this approximation fails when our sample contains too few observations.
In such a case, we do not approximate but rather perform the exact binomial test. Here's the formula for its (twosided) pvalue:
After a moment's thought, one can recognize here the cumulative distribution function of the binomial distribution b(n,p)
with parameters p = 0.5
and n = b + c
. We use the exact McNemar's test if our sample satisfies b + c < 25
.
Alternatively, we can use the midpvalue McNemar's test, which we can calculate by subtracting the probability of the observed b
from the exact twosided pvalue, that is:
Here's the full formula:
The midpvalue approach has been recently becoming more and more popular.
We won't throw at you any technical details; let us just say that the midpvalue allows us to avoid the disadvantages of the other methods (especially those related to controlling the type I error) while keeping their advantages to the almost full extent. In Omni's McNemar's exact test calculator, we've implemented both exactpvalue and midpvalue so that you can easily compare the results these two approaches yield.
How to use this McNemar's test calculator
To perform McNemar's test with the help of our calculator, follow these steps:

Input your data (that is, the coefficients of the 2x2 contingency table) into the dedicated fields. The filledin contingency table will appear at the bottom of McNemar's test calculator along with its marginals so that you can easily verify if you've entered data correctly.

Decide on the version of the McNemar's test you want to perform. There are five options available:
 Standard McNemar's test;
 With Edwards correction;
 With Yates correction;
 Exact binomial test; and
 Midp binomial test.
If you are not sure which one to choose, go for the standard McNemar's test.

Our McNemar's test calculator will return the pvalue, based on which you can decide if your findings are significant at the desired significance level.

Additionally, for tests based on the
χ²
test statistic, our McNemar's test calculator displays the value of test statistic so that you can easily verify your own calculations.
McNemar's test example
In this final section, we'll go through an example of McNemar's test for paired proportions together to see how all these calculations work in practice.
Assume we have the following data:
before  after  

positive  60  70 
negative  50  40 

Calculate the value of test statistics:
χ² = (b  c)² / (b + c) = (70  50)² / (70 + 50) = 400 / 120 = 3.33

Determine the value of cdf of the chisquared distribution with 1 degree of freedom at
3.33
:cdf(3.33) = 0.932

Determine the pvalue:
pvalue = 1  cdf(3.33) = 0.068
As we can see, at the standard significance level 0.05
, we do not have enough evidence to reject the null hypothesis  our findings are not statistically significant.
That's it, we're done with our example of McNemar's test! We hope you agree that's it's not at all hard to perform this test even if you have to compute it by hand. But, certainly, it's much more fun to use Omni's McNemar's test calculator 😉.
What is McNemar's test?
McNemar's test is a statistical technique for paired binomial data which helps us decide if the contingency table has equal marginal distributions. For instance, we can use it to decide if a particular treatment has any effect on the results of a dichotomous medical test.
How do I calculate McNemar's test?
In McNemar's test, we compute the test statistic using the offdiagonal fields b
and c
from the contingency table:
χ² = (b  c)² / (b + c)
If b
and c
are large enough, then the pvalue is equal to one minus the cdf of the chisquared distribution with 1
degree of freedom taken at the value of χ²
. Alternatively, use the rightsided critical region.
When to use McNemar's exact test?
Use McNemar's exact test (instead of the standard version based on χ² approximation) when your sample is small, that is, the offdiagonal cells b
and c
in the contingency table are such that b + c < 25
.
Why do I need the contingency table in McNemar's test?
Strictly speaking, you don't need the whole contingency table to perform McNemar's test, but only its offdiagonal values, also known as discordant values (as opposed to concordant values at the diagonal). You need these values to compute the test statistic of McNemar's test.