* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * File: goodfit.SPS . * Date: 2-March-2001 . * Author: Bruce Weaver, weaverb@mcmaster.ca . * Notes: Demonstration of chi-square goodness of fit . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * This syntax performs the chi-square goodness of fit tests described in the notes. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * Problem 1: Pepsi challenge . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * First approach using individual data. * Generate the data file with an input program . new file. input program. loop #i = 1 to 150. compute case = $casenum. do if range(case,1,45). compute brand = 1. else if range(case,46,85). compute brand = 2. else. compute brand = 3. end if. end case. end loop. end file. end input program. exe. formats case brand (f5.0). val lab brand 1 'Coke' 2 'Pepsi' 3 'Brand X'. freq brand. * Chi-square goodness of fit test is found under Analyze-->Nonparametric-->Chi-square . NPAR TEST /CHISQUARE=brand /EXPECTED=EQUAL /STATISTICS DESCRIPTIVES /MISSING ANALYSIS. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * Second approach using the 3 cell counts and WEIGHT cases . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . DATA LIST LIST /brand (f2.0) count(f5.0) . BEGIN DATA. 1 45 2 40 3 65 END DATA. val lab brand 1 'Coke' 2 'Pepsi' 3 'Brand X'. weight by count. NPAR TEST /CHISQUARE=brand /EXPECTED=EQUAL /STATISTICS DESCRIPTIVES /MISSING ANALYSIS. * Note that SPSS yields the same value for Pearson's chi-square that was reported in the notes. * Note as well that SPSS does not generate the likelihood ratio chi-square statistic for a goodness of fit test . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * Problem 2: Fruit flies . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~ . new file. input program. loop #i = 1 to 100. compute case = $casenum. do if range(case,1,44). compute type = 1. else if range(case,45,80). compute type = 2. else if range(case,81,92). compute type = 3. else. compute type = 4. end if. end case. end loop. end file. end input program. exe. formats case type (f5.0). var lab type 'Fruit fly subtype'. freq type. * This time, we need to specify the expected proportion for each of the 4 cells under the null hypothesis . NPAR TEST /CHISQUARE=type /EXPECTED=.4 .3 .2 .1 /STATISTICS DESCRIPTIVES /MISSING ANALYSIS. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . * Second approach, using the 4 cell counts and WEIGHT cases . * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . DATA LIST LIST /type (f2.0) count(f5.0) . BEGIN DATA. 1 44 2 36 3 12 4 8 END DATA. formats type count (f5.0). var lab type 'Fruit fly subtype'. WEIGHT by count. freq type. NPAR TEST /CHISQUARE=type /EXPECTED=.4 .3 .2 .1 /STATISTICS DESCRIPTIVES /MISSING ANALYSIS. * TIP: command to turn WEIGHT off is: WEIGHT OFF . weight off. freq type. * Finished. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .