# FITTTEST.MAC # # Conducts a chi-square goodness-of-fit test and provides a # graphical display # # Macro is for MINITAB for Windows, release 10 and above # Written by: Neil A. Weiss # Date: 03/30/98 # Revision history: # 04/02/98: Changed E to W to avoid conflict with Release 12 use # 04/04/00: Revised to account for changes in Release 13 for what is # acceptable syntax in Minitab macros. MACRO FITTEST MCOLUMN A B C D F G H I L O Q T U W X FX Y FY MCONSTANT k n df p r x2 ans j m xmin xmax ymax NOTITLES BRIEF 2 NOTE NOTE NOTE This macro performs a chi-square goodness-of-fit test, computes the NOTE P-value, and provides a graphical display. NOTE NOTE Enter the number of possible values for the variable under consideration. NOTE SET C; FILE 'TERMINAL'; NOBS 1. COPY C k NOTE NOTE Enter the relative frequencies (or probabilities) for the null hypothesis. NOTE SET Q; FILE 'TERMINAL'; NOBS k. NOTE NOTE Enter the observed frequencies. NOTE SET O; FILE 'TERMINAL'; NOBS k. NOTE NOTE LET df=k-1 LET n=SUM(O) LET W=n*Q LET C=(W<1) LET m=sum(C) IF m>0 NOTE WARNING: One or more of the expected frequencies are less than 1. NOTE The conditions for using the goodness-of-fit test are violated. GOTO 1 ELSE LET C=(W<5) LET m=sum(C) IF m/k<=.2 GOTO 2 ELSE NOTE WARNING: More than 20% of the expected frequencies are less than 5. NOTE The conditions for using the goodness-of-fit test are violated. ENDIF ENDIF MLABEL 1 NOTE NOTE Do you want to abort the test? NOTE BRIEF 0 YESNO ans IF ans=1 BRIEF 2 TITLES EXIT ENDIF MLABEL 2 BRIEF 0 LET x2=SUM((O-W)**2/W) CDF x2 p; CHIS df. LET p=1-p COPY n F COPY k G COPY x2 H COPY p I NAME F 'n' G 'k' H 'ChiSq' I 'P-value' BRIEF 2 NOTE SET T; FORMAT (A32). Chi-square goodness-of-fit test END PRINT T; FORMAT (A32). PRINT F G H I NOTE NOTE NOTE Do you want to see a graphical display of the results NOTE of the chi-square goodness-of-fit test (Y/N)? NOTE YESNO ans BRIEF 0 IF ans=0 BRIEF 2 TITLES EXIT ENDIF READ L; FORMAT (A8). ChiSq = P = END READ A B 0.5 1.0 0.5 0.5 END IF df=1 LET xmin=0.2 LET xmax=8 LET ymax=0.81 LET r=x2 ELSEIF df=2 LET xmin=0.01 LET xmax=16 LET ymax=0.55 LET r=x2 ELSE LET xmin=0 LET xmax=25 LET ymax=0.136 LET df=6 # USING DF=6 AS A STANDARD CURVE CHI-SQUARE CURVE. LET k=1-p INVCDF k r; CHIS 6. ENDIF SET X xmin:xmax/.1 END PDF X FX; CHIS df. SET D x2 p END NTOA D D; DECIMALS 3. CONCAT L D U IF r