McNemar Test in SAS - Example Presidential Approval
In SAS under PROC FREQ: option AGREE gives normal approximation of the McNemar’s test, while EXACT MCNEM will give the exact version based on binomial probabilities. Here is a sample of what this SAS coding, (President.sas), would look like:
and its corresponding output President.lst. Compare the value from the output below, the section labeled "McNemar's Test" to the values we computed on the previous page of the notes. They give the same test statistic, Z=S=17.36 with a p-value of nearly zero indicating that there a strong evidence that the rating did change from Time 1 to Time 2.
The next part of President.sas does the the same test but uses PROC CATMOD. We will not go into details of PROC CATMOD procedure now; you can explore this on your own. We will briefly discuss it later in the course. However, this example is intended to show that there are many ways to do the same analysis even in the same software package. Part of the output President-part2.lst. under "The CATMOD Procedure", labeled "Analysis of Variance" contains the McNemar's statistic for this example.
McNemar Test in R - Example Presidential Approval
In R we can use the mcnemar.test() as demonstrated in President.R:
Compare the first part of the output to the values we computed by hand on the previous page of the notes. The value of the McNemar's chi-squared statistic= 17.3559, df = 1, p-value = 3.099e-05 corresponds to our calculations. We do NOT need to use the continuity correction since the sample size is large. We have strong evidence that the rating did change from Time 1 to Time 2.