10 PRINT "CHI-SQUARE TEST"
20 PRINT
28 REM - LIMIT SIZE OF CONTINGENCY TABLES TO V1(R*C),A(R)
29 REM - WHERE R=NO. OF ROWS, C=NO, OF COLLUMNS
30 DIM V1(25),V2(5),A(5)
40 PRINT "NUMBER OF ROWS";
49 REM - LINES 50-150 INPUT CONTINGENCY TABLE
50 INPUT R
60 PRINT "NUMBER OF COLUMNS";
70 INPUT C
80 PRINT "CONTINGENCY TABLE:"
90 FOR I=1 TO R
100 PRINT "ROW";I
110 FOR J=1 TO C
120 PRINT "   ELEMENT";J;
130 INPUT V1((I-1)*C+J)
140 NEXT J
150 NEXT I
160 PRINT
169 REM - ADD UP MARGINAL FREQUENCIES FOR EACH ROW
170 L=0
180 M=1
190 FOR I=1 TO R
200 FOR J=1 TO C
210 A(I)=A(I)+V1(M)
220 M=M+1
230 NEXT J
240 L=L+A(I)
250 NEXT I
260 N=R*C
269 REM - ADD UP MARGINAL FREQUENCIES FOR EACH COLUMN
270 FOR I=1 TO C
280 FOR J=I TO N STEP C
290 V2(I)=V2(I)+V1(J)
300 NEXT J
310 NEXT I
320 Z=0
330 PRINT "OBSERVED VALUE","EXPECTED VAULE","CHI[2 CONTRIBUTION"
340 FOR I=1 TO C
350 PRINT "   COLUMN";I
360 FOR J=1 TO R
369 REM - P=EXPECTED CELL VALUE
370 P=A(J)*V2(I)/L
375 X=I+(J-1)*C
379 REM - USE YATES' CORRECTION FOR CONTINUITY IN 2 X 2 CHI-SQUARE TEST
380 IF R<>2 THEN 390
381 IF C<>2 THEN 390
382 Y=(ABS(V1(X)-P)-.5)[2/P
383 GOTO 400
389 REM - Y=CHI-SQUARE CONTRIBUTION FROM THIS CELL
390 Y=(V1(X)-P)[2/P
399 REM - Z=TOTAL CHI-SQUARE VALUE
400 Z=Z+Y
410 PRINT "    ";V1(X),P,Y
420 NEXT J
430 NEXT I
440 PRINT
450 PRINT "CHI-SQUARE =";Z
460 PRINT "DEGREES OF FREEDOM =";(C-1)*(R-1)
470 END
