# 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: 06/25/96 # Revision history: # 06/28/96: Added check of conditions for use. # 07/01/96: Added separate curves for df=1 and df=2. MACRO FITTEST MCOLUMN A B C D E F G H I L O Q U X FX Y FY MCONSTANT k n df p r x2 ans j m xmin xmax ymax BRIEF 2 NOTE NOTE NOTE This macro performs a chi-square goodness-of-fit test, computes NOTE the P-value, and provides a graphical display. NOTE NOTE NOTE Type "R" and press the Enter key to continue. BRIEF 0 PAUSE BRIEF 2 NOTE NOTE Enter the number of categories in the distribution. NOTE SET C; FILE 'TERMINAL'; NOBS=1. COPY C k NOTE NOTE Enter the probability distribution 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 E=n*Q LET m=0 DO j=1:k IF E(j)<1 NOTE WARNING: One or more expected frequencies are less than 1. The NOTE conditions for using the goodness-of-fit test are violated. GOTO 1 ELSEIF E(j)<5 let m=m+1 ENDIF ENDDO IF m/k<=.2 GOTO 2 ELSE NOTE WARNING: More than 20% of the expected frequencies are less than 5. The NOTE conditions for using the goodness-of-fit test are violated. ENDIF MLABEL 1 NOTE NOTE Do you want to abort the test? NOTE BRIEF 0 YESNO ans IF ans=1 BRIEF 2 EXIT ENDIF MLABEL 2 BRIEF 0 LET x2=SUM((O-E)**2/E) 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 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 EXIT ENDIF BRIEF 0 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