Table of Contents
McNemar’s Test is a specialized non-parametric statistical procedure used to determine if there are significant changes in a binary variable across two related or paired groups. This method is particularly invaluable in longitudinal studies or clinical trials where the same subjects are evaluated at two distinct points in time, such as before and after a specific intervention. By focusing on the marginal homogeneity of a 2×2 contingency table, this test allows researchers to assess whether the distribution of binary outcomes has shifted significantly. Understanding how to perform this analysis in Excel provides a accessible yet powerful way to derive insights from paired categorical data without requiring complex statistical software.
Perform McNemar’s Test in Excel
Comprehensive Overview of McNemar’s Test
At its core, McNemar’s Test is designed to analyze paired nominal data. This test is most frequently employed when researchers want to observe the effectiveness of a treatment or the impact of an event on a specific population. Unlike the standard Chi-Square test of independence, which compares two independent groups, this test is specifically tailored for dependent samples. This dependency typically arises when the same individual is measured twice—once in a control state and once in a treatment state—or when subjects are matched in pairs based on specific characteristics.
The primary objective of the test is to analyze the “discordant pairs” within the dataset. In a study with binary outcomes, such as “Pass/Fail” or “Support/Oppose,” there are four possible combinations of results for a paired subject. Two of these are “concordant,” meaning the subject stayed the same (e.g., Support/Support), and two are “discordant,” meaning the subject changed (e.g., Support/Oppose). McNemar’s Test specifically evaluates whether the number of subjects switching from one state to the other is balanced or if there is a significant trend toward one specific direction of change.
Performing this test in Excel is a straightforward process that involves setting up a specific data structure and utilizing basic mathematical functions. While Excel does not have a single built-in button labeled for this test, its robust calculation engine allows users to manually compute the test statistic and the resulting p-value with ease. This versatility makes it an excellent tool for researchers who need to validate their findings quickly while maintaining a high degree of transparency in their calculations.
Fundamental Assumptions and Data Requirements
Before initiating any statistical analysis, it is vital to ensure that the data meets the necessary assumptions. For McNemar’s Test, the most critical requirement is that the data must consist of a binary variable (dichotomous) and that the observations must be paired. This means that for every data point in the “before” or “control” group, there must be a corresponding, linked data point in the “after” or “treatment” group. If the groups were independent—meaning different people were used in each group—a standard Chi-Square test or a Z-test for proportions would be more appropriate.
Another essential assumption involves the nature of the sampling. The subjects should be selected through a random sampling process to ensure that the results are representative of the broader population. Additionally, while McNemar’s Test does not require a normal distribution, it does rely on the size of the discordant pairs. If the sum of the discordant pairs is very small (typically less than 25), many statisticians recommend using the Exact Binomial Test instead of the Chi-Square approximation to maintain accuracy in the statistical significance results.
In the context of Excel, the data must be organized in a way that the software can interpret the shifts between states. This is usually achieved by creating a summary table that counts the transitions. It is not enough to simply have two lists of outcomes; you must know exactly which individuals changed their status and which did not. This paired relationship is the foundation upon which the entire test is built, ensuring that the analysis accounts for the inherent correlation between the two sets of observations.
Note: This test is appropriate to use when the same subjects show up in both the control and treatment group. This tutorial shows how to conduct McNemar’s Test in Excel.
Designing the Contingency Table for Paired Samples
The first practical step in performing the test is the construction of a 2×2 contingency table. This table serves as a visual and mathematical summary of the transitions between the two states. Typically, the rows represent the status of the subjects in the first measurement (e.g., “Pre-Test”), while the columns represent the status in the second measurement (e.g., “Post-Test”). The four cells created by this intersection represent the four possible paths a subject can take during the study period.
In a standard contingency table, the cells are often labeled A, B, C, and D. Cell A represents subjects who were “Positive” in both tests, while cell D represents subjects who were “Negative” in both tests. These are the concordant pairs and are largely ignored by the test statistic because they do not represent a change in opinion or status. Cells B and C are the discordant pairs. Cell B represents those who moved from “Positive” to “Negative,” and cell C represents those who moved from “Negative” to “Positive.”
When setting this up in Excel, accuracy is paramount. Each subject’s journey must be tracked to ensure they are placed in the correct cell. For instance, if you are measuring the impact of an advertisement on brand preference, you must identify how many people liked the brand before but not after, and how many liked it after but not before. Once these counts are finalized, the table provides all the necessary inputs for the mathematical formula that determines the p-value.
The Mathematical Foundation of the Test Statistic
The calculation of the test statistic for McNemar’s Test is based on the difference between the two discordant cells. The logic is that if the intervention had no effect, the number of people switching from “A to B” should be roughly equal to the number of people switching from “B to A.” Any significant deviation from this balance suggests that the intervention caused a systematic shift in one direction. The formula used is a variation of the Chi-Square statistic, specifically focused on these shifting values.
To improve the accuracy of the test, especially with smaller sample sizes, researchers often apply the Edwards’ continuity correction. This involves subtracting 0.5 or 1 from the absolute difference between the discordant pairs before squaring the result. In the specific formula used in this tutorial, the test statistic is calculated as follows: X2 = (|A-B| – 1)2 / (A+B). Here, A and B represent the two types of discordant pairs. This correction ensures that the discrete nature of the data does not lead to an overestimation of statistical significance.
The resulting value follows a Chi-Square distribution with exactly one degree of freedom. In Excel, once you have calculated this test statistic, you can compare it to a critical value from a statistical table or use an internal function to find the exact probability of obtaining such a result by chance. If the probability is low enough, usually below 0.05, the result is considered significant, and you can conclude that a real change has occurred in the population.
Formulating Hypotheses for Statistical Inquiry
Every statistical test begins with the formulation of a null hypothesis and an alternative hypothesis. These statements define the scope of the investigation and the criteria for success. The null hypothesis (H0) typically states that there is no effect or no change. In the context of this test, it posits that the proportions of the two states are equal across both measurements, meaning any observed differences in the discordant pairs are merely due to random chance.
Conversely, the alternative hypothesis (HA) asserts that there is a significant difference or a noticeable impact. It suggests that the intervention—whether it be a medication, an educational video, or a policy change—has caused a non-random shift in the binary variable. By setting these hypotheses, the researcher establishes a formal framework for decision-making based on the p-value generated at the end of the analysis.
It is important to define the significance level (alpha), usually set at 0.05, before conducting the test. This threshold determines how much evidence is required to reject the null hypothesis. If the calculated probability is less than alpha, the researcher rejects the idea that no change occurred and accepts the alternative hypothesis. This structured approach prevents biased interpretations and ensures that the conclusions drawn from the Excel data are statistically sound and defensible.
Practical Step-by-Step Scenario Analysis
Suppose researchers survey 100 people about a certain law and find that 30 support the law while 70 oppose the law. Researchers then show this group of 100 people a video about the financial benefits of the law and repeat the survey again. This time, 12 people go from supporting to opposing the law while 14 go from opposing to supporting the law. We must conduct a McNemar’s Test to determine if this video had a significant impact on people’s opinion.
First, state the null hypothesis and alternative hypothesis for the test:
- H0: The video has no impact on people’s opinion regarding the law.
- HA: The video has a significant impact on people’s opinion regarding the law.
Next, we must identify the specific discordant pairs from our data set to use in our calculations:
- A = Number of people who changed from supporting to opposing the law: 12
- B = Number of people who changed from opposing to supporting the law: 14
The test statistic is calculated using the formula: X2 = (|A-B| – 1)2 / (A+B). Plugging in our values, we get: (|12-14| – 1)2 / (12+14). This simplifies to (2 – 1)2 / 26, which equals 1 / 26, or approximately 0.03846. This low value suggests that the number of people who changed their minds in one direction is very close to the number of people who changed their minds in the other direction.
This test statistic follows a Chi-Square distribution with one degree of freedom. According to the standard distribution table, the critical value for a significance level of 0.05 with one degree of freedom is 3.841. Since our calculated test statistic (0.03846) is significantly less than the critical value (3.841), we fail to reject the null hypothesis. We do not have sufficient evidence to say that the video had a significant impact on people’s opinion.
Executing Calculations Within the Excel Environment
To perform this McNemar’s Test in Excel, you can set up a simple spreadsheet where the inputs for A and B are clearly labeled. By using the ABS function to find the absolute difference and standard arithmetic operators, you can build the formula directly into a cell. For example, if your value for A is in cell B1 and B is in cell B2, your formula for the test statistic would look like: =((ABS(B1-B2)-1)^2)/(B1+B2). This provides the X2 value instantly.
To find the p-value associated with this statistic, Excel provides the CHISQ.DIST.RT function. This function calculates the right-tailed probability of the Chi-Square distribution. The syntax is =CHISQ.DIST.RT(test_statistic, deg_freedom). In our case, the degrees of freedom will always be 1 for a 2×2 table. By inputting our calculated statistic into this function, Excel will return the exact probability that the observed change happened by chance.
The visual representation of this data in Excel helps in maintaining a clear record of the analysis. You can create a small table that displays the “Before” and “After” counts, the calculation steps for the statistic, and the final p-value. This makes it easy to update the analysis if the sample size changes or if you are running the same test across different demographic groups. The image below illustrates how such a setup might look in a standard spreadsheet.
As demonstrated in the spreadsheet layout, the results match our manual calculations perfectly. By automating the process in Excel, you reduce the risk of manual arithmetic errors and create a reusable template for future paired sample tests.
Interpreting Results and Understanding Significance
Interpreting the output of McNemar’s Test requires a clear understanding of the p-value. The p-value represents the probability of observing a difference as large as (or larger than) the one found in your sample, assuming the null hypothesis is true. A high p-value, like the one we derived in our example, suggests that the observed shifts in opinion were likely due to random fluctuations rather than the influence of the video.
When the p-value is greater than the chosen significance level (usually 0.05), we state that we “fail to reject the null hypothesis.” This does not necessarily prove that the intervention had zero effect, but rather that the study did not find enough evidence to confirm an effect exists. In our law survey example, while 26 people changed their minds, the split between those moving to support (14) and those moving to opposition (12) was too balanced to be considered a statistically significant trend.
On the other hand, if our test statistic had been much higher—for instance, if 25 people moved to support and only 1 moved to opposition—the p-value would have been extremely small. In such a case, we would reject the null hypothesis and conclude that the video had a significant impact. This distinction is crucial for making evidence-based decisions in fields ranging from public policy to medical research, and Excel serves as an efficient tool for reaching these conclusions.
Common Pitfalls and Best Practices in Analysis
One of the most common mistakes when performing McNemar’s Test is using the total number of subjects in the denominator of the formula. It is critical to remember that the test is only concerned with the discordant pairs (A and B). The individuals who did not change their status (concordant pairs) do not contribute to the test statistic, although they are part of the total sample size. Focusing on the correct cells in your contingency table is essential for a valid result.
Another pitfall involves the application of the test to independent groups. If you are comparing the opinions of two different cities, or a group of men versus a group of women, you cannot use this test. Those groups are independent, and the paired nature of McNemar’s Test would lead to incorrect findings. Always verify that your data points are truly linked, such as a “pre-test” and “post-test” score for the exact same person, before proceeding with this analysis in Excel.
Finally, always consider the power of your test. If your sample size of discordant pairs is very small, the test may not have enough power to detect a real change, leading to a Type II error. In these instances, reporting the raw percentages and the confidence intervals alongside your p-value can provide a more nuanced view of the data. By following these best practices and utilizing the calculation capabilities of Excel, you can ensure that your statistical analysis is both rigorous and insightful.
Cite this article
stats writer (2026). How to Perform McNemar’s Test in Excel: A Step-by-Step Guide. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-perform-mcnemars-test-in-excel/
stats writer. "How to Perform McNemar’s Test in Excel: A Step-by-Step Guide." PSYCHOLOGICAL SCALES, 1 Mar. 2026, https://scales.arabpsychology.com/stats/how-can-i-perform-mcnemars-test-in-excel/.
stats writer. "How to Perform McNemar’s Test in Excel: A Step-by-Step Guide." PSYCHOLOGICAL SCALES, 2026. https://scales.arabpsychology.com/stats/how-can-i-perform-mcnemars-test-in-excel/.
stats writer (2026) 'How to Perform McNemar’s Test in Excel: A Step-by-Step Guide', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-perform-mcnemars-test-in-excel/.
[1] stats writer, "How to Perform McNemar’s Test in Excel: A Step-by-Step Guide," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, March, 2026.
stats writer. How to Perform McNemar’s Test in Excel: A Step-by-Step Guide. PSYCHOLOGICAL SCALES. 2026;vol(issue):pages.

