McNemar Test Calculator

McNemar Test Inputs

Enter the observed frequencies from your 2x2 contingency table for paired data. These are typically counts of subjects or observations.

Number of subjects who tested positive both before and after an intervention.
Please enter a non-negative integer.
Number of subjects who tested positive before and negative after. (Discordant pair)
Please enter a non-negative integer.
Number of subjects who tested negative before and positive after. (Discordant pair)
Please enter a non-negative integer.
Number of subjects who tested negative both before and after.
Please enter a non-negative integer.

What is the McNemar Test?

The McNemar Test calculator is a non-parametric statistical test used to analyze paired nominal data. It is specifically designed to determine if there is a significant difference between two related (dependent) proportions. Unlike the Chi-squared test for independence, which examines relationships between two categorical variables in independent samples, McNemar's test is ideal for "before-and-after" study designs or when comparing two different treatments on the same subjects.

Who should use it? Researchers in medicine, public health, psychology, and social sciences frequently use the McNemar test. For example, it can assess the effectiveness of a drug by comparing the proportion of patients who improve after treatment versus those who worsen, or evaluate the impact of a training program by comparing pre- and post-training success rates.

Common misunderstandings: A frequent error is using the standard Chi-squared test for independent samples when data is paired. This incorrectly assumes independence, leading to inaccurate p-values and conclusions. The McNemar test correctly accounts for the dependency between observations, focusing only on the "discordant" pairs (those who changed categories).

McNemar Test Formula and Explanation

The McNemar test focuses on the cells in a 2x2 contingency table where subjects change categories. Consider a scenario where subjects are measured "before" and "after" an intervention, or under "Condition 1" and "Condition 2".

The 2x2 table structure is typically:

2x2 Contingency Table for Paired Data
After (Positive) After (Negative)
Before (Positive) N++ (a) N+- (b)
Before (Negative) N-+ (c) N-- (d)
  • N++ (a): Number of subjects who were positive before and remained positive after. (Concordant)
  • N+- (b): Number of subjects who were positive before and became negative after. (Discordant)
  • N-+ (c): Number of subjects who were negative before and became positive after. (Discordant)
  • N-- (d): Number of subjects who were negative before and remained negative after. (Concordant)

The McNemar test specifically evaluates the difference between the discordant pairs (b and c). If there's no significant change, we expect b to be roughly equal to c.

The formula for the McNemar Chi-squared (χ²) statistic is:

χ² = (b - c)² / (b + c)

This formula applies when the sum of discordant pairs (b + c) is sufficiently large (typically > 20). For smaller sums, or for increased accuracy, a continuity correction can be applied:

χ² = (|b - c| - 1)² / (b + c)

The calculator provided uses the formula without continuity correction for simplicity unless (b+c) is very small, which would typically warrant Fisher's Exact Test for paired data or an exact binomial test instead.

The resulting Chi-squared value is then compared to a Chi-squared distribution with 1 degree of freedom (df = 1) to obtain a p-value. A small p-value (typically < 0.05) indicates a statistically significant difference between the two proportions.

Variables Table for McNemar Test

Key Variables in McNemar Test
Variable Meaning Unit Typical Range
N++ (a) Count: Positive before, Positive after Unitless (counts) 0 to N (total subjects)
N+- (b) Count: Positive before, Negative after Unitless (counts) 0 to N (total subjects)
N-+ (c) Count: Negative before, Positive after Unitless (counts) 0 to N (total subjects)
N-- (d) Count: Negative before, Negative after Unitless (counts) 0 to N (total subjects)
χ² McNemar Chi-squared Statistic Unitless Non-negative real number
df Degrees of Freedom Unitless Always 1 for McNemar
p-value Probability value Unitless 0 to 1

Practical Examples of Using the McNemar Test Calculator

Example 1: Drug Efficacy Study

A pharmaceutical company wants to test a new drug for reducing allergy symptoms. They recruit 100 patients and assess their symptom status (positive/negative for symptoms) before and after taking the drug for a month.

  • Before Positive, After Positive (N++): 10 patients (still have symptoms)
  • Before Positive, After Negative (N+-): 40 patients (symptoms resolved)
  • Before Negative, After Positive (N-+): 5 patients (developed symptoms)
  • Before Negative, After Negative (N--): 45 patients (remained symptom-free)

Using the calculator:

  • N++ = 10
  • N+- = 40
  • N-+ = 5
  • N-- = 45

Results:

  • Chi-squared (χ²) = (40 - 5)² / (40 + 5) = 35² / 45 = 1225 / 45 ≈ 27.22
  • Degrees of Freedom = 1
  • p-value < 0.001 (highly significant)
  • Conclusion: We reject the null hypothesis. There is a statistically significant difference in allergy symptom status before and after taking the drug, suggesting the drug is effective.

Example 2: Advertising Campaign Impact

An advertising agency launches a new campaign and surveys 200 consumers about their preference for a particular brand ("preferred" vs. "not preferred") before and after seeing the ads.

  • Before Preferred, After Preferred (N++): 80 consumers
  • Before Preferred, After Not Preferred (N+-): 30 consumers (changed preference away from brand)
  • Before Not Preferred, After Preferred (N-+): 50 consumers (changed preference towards brand)
  • Before Not Preferred, After Not Preferred (N--): 40 consumers

Using the calculator:

  • N++ = 80
  • N+- = 30
  • N-+ = 50
  • N-- = 40

Results:

  • Chi-squared (χ²) = (30 - 50)² / (30 + 50) = (-20)² / 80 = 400 / 80 = 5.00
  • Degrees of Freedom = 1
  • p-value < 0.05
  • Conclusion: We reject the null hypothesis. There is a statistically significant change in brand preference after the advertising campaign. Since N-+ is greater than N+-, it suggests the campaign was successful in shifting preferences towards the brand.

How to Use This McNemar Test Calculator

This McNemar Test calculator is designed for ease of use and immediate results:

  1. Identify Your Data: Ensure your data is paired and categorical (dichotomous, e.g., Yes/No, Positive/Negative, Success/Failure). You need counts for each of the four possible outcomes (N++, N+-, N-+, N--).
  2. Enter Your Counts: Input the observed frequencies into the respective fields:
    • Positive before, Positive after (N++): Subjects who remained in the 'positive' category.
    • Positive before, Negative after (N+-): Subjects who switched from 'positive' to 'negative'.
    • Negative before, Positive after (N-+): Subjects who switched from 'negative' to 'positive'.
    • Negative before, Negative after (N--): Subjects who remained in the 'negative' category.
    The values are unitless counts and must be non-negative integers. The calculator will automatically validate your inputs.
  3. Click "Calculate McNemar Test": The calculator will instantly display the Chi-squared statistic, degrees of freedom, total discordant pairs, approximate p-value, and a statistical decision based on a common alpha level (0.05).
  4. Interpret Results:
    • Chi-squared (χ²) Statistic: This is the calculated test statistic.
    • Degrees of Freedom (df): Always 1 for the McNemar test.
    • Total Discordant Pairs: The sum of N+- and N-+. This is important because the test focuses on these changes.
    • Approximate p-value: Indicates the probability of observing such a difference (or more extreme) if the null hypothesis were true.
    • Statistical Decision: Based on the p-value and a significance level (alpha, typically 0.05). If p < 0.05, you reject the null hypothesis, suggesting a significant difference. If p ≥ 0.05, you fail to reject the null hypothesis, meaning no significant difference was found.
  5. Copy Results: Use the "Copy Results" button to quickly save the output for your reports or notes.

Key Factors That Affect the McNemar Test

Understanding the factors influencing the McNemar test helps in designing studies and interpreting results:

  1. Sample Size (Total Discordant Pairs): The power of the McNemar test primarily depends on the number of discordant pairs (b + c), not the total sample size (a + b + c + d). If there are very few or no changes between the two observations, the test will have low power or cannot be performed. A larger number of discordant pairs increases the test's ability to detect a true difference.
  2. Magnitude of Difference Between Discordant Pairs: The larger the absolute difference between `N+-` and `N-+` (i.e., `|b - c|`), the larger the Chi-squared statistic will be, and thus the smaller the p-value. This directly reflects the strength of the observed change.
  3. Direction of Change: The test doesn't inherently tell you the direction, but by comparing `N+-` and `N-+`, you can infer whether the change was predominantly from positive to negative or vice-versa. For instance, if `N+-` > `N-+`, more subjects shifted from positive to negative.
  4. Assumptions: The McNemar test assumes that observations within each pair are dependent (related), but the pairs themselves are independent. It also assumes a sufficiently large number of discordant pairs (usually b+c > 20) for the Chi-squared approximation to be valid. For smaller counts, exact methods are preferred.
  5. Type of Data: The test is strictly for dichotomous (binary) categorical data measured on the same subjects or matched pairs. It is not suitable for continuous, ordinal, or unpaired categorical data. For continuous paired data, a paired t-test calculator would be more appropriate.
  6. Alpha Level (Significance Level): The chosen alpha level (e.g., 0.05) determines the threshold for statistical significance. A smaller alpha makes it harder to reject the null hypothesis, demanding stronger evidence of a difference.

Frequently Asked Questions (FAQ) about the McNemar Test

Q1: What is the primary purpose of the McNemar test?

A: The McNemar test is used to assess if there is a statistically significant change in proportions between two related (dependent) samples or measurements, typically in "before-and-after" study designs.

Q2: When should I use McNemar's test instead of a standard Chi-squared test?

A: Use McNemar's test when your data is paired or matched (e.g., same subjects measured twice). Use a standard Chi-squared test calculator for independent samples.

Q3: What are "discordant pairs" in the context of the McNemar test?

A: Discordant pairs are the observations where a subject's category changes between the two measurements. For a "before/after" study, these are subjects who went from Positive to Negative (N+-) or Negative to Positive (N-+).

Q4: Does this McNemar test calculator use continuity correction?

A: For simplicity and general applicability, this calculator primarily uses the standard formula without continuity correction. For very small total discordant pairs (b+c < 20), exact methods or the continuity-corrected formula might be more appropriate, which can be explored with a Fisher's Exact Test calculator for specific scenarios.

Q5: What does a low p-value mean in the McNemar test?

A: A low p-value (e.g., < 0.05) indicates that the observed difference in proportions between the two related measurements is unlikely to have occurred by chance alone. This leads to rejecting the null hypothesis, suggesting a significant change.

Q6: What if my counts are not integers?

A: The McNemar test, like most count-based statistical tests, requires integer counts (frequencies). If you have proportions or percentages, you must convert them back to raw counts for this calculator to work correctly. The calculator will validate inputs to ensure they are non-negative integers.

Q7: What are the units for the inputs and results?

A: All inputs (N++, N+-, N-+, N--) are unitless counts of observations or subjects. The results like Chi-squared statistic, degrees of freedom, and p-value are also unitless statistical measures.

Q8: Can I use this calculator for more than two categories or more than two time points?

A: No, the standard McNemar test is specifically for two categories and two related measurements (e.g., before/after, treatment A/treatment B). For more complex designs, you would need different statistical tests, such as Cochran's Q test for more than two related dichotomous outcomes.

Related Tools and Internal Resources

Explore other statistical and analytical tools to enhance your data analysis:

🔗 Related Calculators