* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * File: McNemar.SPS . * Date: 2-March-2001 . * Author: Bruce Weaver, weaverb@mcmaster.ca . * Notes: Demonstration of McNemar chi-square test . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * This syntax performs the chi-square test of association for the McNemar change test example described in the notes . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * First approach using individual data . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * Generate the data file with an input program . new file. input program. loop #i = 1 to 60. compute case = $casenum. do if range(case,1,20). compute before = 1. compute after = 1. else if range(case,21,24). compute before = 1. compute after = 2. else if range(case,25,37). compute before = 2. compute after = 1. else. compute before = 2. compute after = 2. end if. end case. end loop. end file. end input program. exe. formats case before after (f5.0). val lab before after 1 'For' 2 'Against' . * There are two ways to get the McNemar Change test. * One way is ANALYZE-->DESCRIPTIVES-->CROSSTABS . crosstabs before by after /stat = mcnemar. * The second way is ANALYZE-->NONPARAMETRIC-->2 RELATED SAMPLES, then check off the McNemar box . NPAR TEST /MCNEMAR= before WITH after (PAIRED) /MISSING ANALYSIS.    * NOTE that SPSS has calculated a p-value using the binomial * distribution here. I consulted the SPSS algorithms website, * where it says that SPSS uses the binomial is used whenever * the sum of the counts in the off-diagonal is equal to or * less than 25. Otherwise, it uses equation 2.16 from the * notes (i.e., with a correction for continuity) . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * Second approach using cell counts and WEIGHT cases . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . DATA LIST LIST /before (f2.0) after (f2.0) count(f5.0) . BEGIN DATA. 1 1 20 1 2 4 2 1 13 2 2 23 END DATA. val lab before after 1 'For' 2 'Against' . * Show structure of file. list all. * Weight cases by variable COUNT, then run CROSSTABS . weight by count. crosstabs before by after /stat = mcnemar. NPAR TEST /MCNEMAR= before WITH after (PAIRED) /MISSING ANALYSIS. * Finished. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .