To compare proportions between two groups or to test for independence between two categorical variables we use the Chi-square test .But when the categorical data are paired Mcnemar test is the appropriate one. The Basic McNemar test applies to a 2*2 contingency table with the dichotomous variable at time 1 and time 2.
If we want to determine whether or not, a particular drug has an effect on a disease, then a count of the individuals is recorded (as positive/negative, or 0 and 1) in a table before and after being given the drug.
Considered 155 subjects and recorded their response on particular disease before and after the treatment. The 82 subjects who had no disease (negative) at both time point and 23 subjects who had disease (positive) at both time points are irrelevant to this comparison. We are actually interested in the change in subjects’ response. Cell b, c is represented pairs with difference.
The McNemar’s Chi-square statistic is calculated using the counts in the ‘b’ and ‘c’ cells of the table:
χ2 = 2(b-c) / (b+c)
To determine whether a drug has an effect on the disease, the result of diagnosis before and after the treatment is tabulated on a 2×2 contingency table
|After : Disease Negative||After : Disease Positive||Total|
|Before : Disease Negative||82 (a)||11 (b)||93|
|Before : Disease Positive||39 (c)||23 (d)||62|
The null hypothesis of the Mcnemar test indicates that the drug has same effect on disease before – after treatments.
How to do Mcnemar’s test in SAS
Consider the above example
To do Mcnemar in SAS use PROC FREQ procedure. McNemar’s test is requested by including the AGREE option on the TABLES statement. The EXPECTED option displays the expected cell frequencies under the hypothesis of independence (or homogeneity).The printing of the percent, column percent and row percent in each cell can be suppressed by specifying the NOPERCENT, NOCOL and NOROW options on the TABLES statement. A kappa statistic can determine the level of agreement in these responses.
value res 1 =’Positive’
input before after count;
format before after $res.;
0 0 82
0 1 11
1 1 23
1 0 39
proc freq data=Mcn order = data;
tables before*after/agree expected norow nocol nopercent;
The output table is as follows:
Then the test statistic is 15.6800 and the 2-tails p-values <.001.Therefore the null hypothesis is rejected with 1% significance level. Thus we conclude that drug has an effect on the disease.