Five quick statistical tests for managers, chosen from a menu: significance of a mean, difference between two means, test for a trend, test for association, and finding a “foreigner” (an outlier). Each test asks how many items you have, takes them one at a time, and says in plain words whether the result is significant at the 1 in 20 level. The tests are counting methods, not textbook formulas. The first three count how many items fall above or below a reference and compare the difference with twice the square root of the count. The association test counts pairs that fall on the same side of both sample averages, and the foreigner test checks whether a new value more than doubles the spread of the sample. When a change in the mean is not significant, the program also estimates how many more items a repeat test would need.
The REM in line 10 says the program was modified from “Managing with the ZX81” by C. E. Coffin in SYNC Magazine. That article ran in Sync for March/April 1983 and credits the methods to Eric Duckworth. The person who adapted it for the TS2068 is not named.
Program Analysis
Structure
- Lines 10–170: colours, the title and the menu choice.
- Lines 180–290: build and print the menu from
m$(), and a short underline subroutine. - Lines 310–620: significance of a mean. Items above and below the previous average are counted in
jandk, and line 590 works out the totals, the limitz=2*SQR sand the differenced=ABS (j-k). - Lines 630–880: difference between two means. Items are entered in pairs, and the program counts which sample is larger in each pair.
- Lines 890–1190: test for a trend. Each item in the first third is compared with the matching item in the last third.
- Lines 1200–1590: test for association. Pairs are compared with the averages of the two samples.
- Lines 1600–1870: finding a foreigner. The range of the sample is compared with the range once the suspect value is added.
- Lines 1880–1940: the shared item-count input and the return to the menu.
Notable Techniques
- The word “significant” is kept in
s$and joined to “ly”, “not” and “no” to build each verdict. - One subroutine at line 1880 reads the item count, prints it, sizes
n()and clears the counters for every test. - The repeat-test estimate in line 530 is
INT (((2*s)/d)^2)-s, the sample size at which the observed imbalance would reach the limit. It is shown only when the answer is between 1 and 99.
Potential Issues
- Tests 2, 3 and 4 reach line 530, which divides by
d, without checking that it is not zero. The trend test calls line 590 before counting, sodis always 0 there, and a “not significant” trend appears to stop with aNumber too bigerror. Tests 2 and 4 fail the same way when the two counts are equal. - In the association test, line 1460 sets
kafresh on every pass, and line 1470 testsn(q)<av2wheren(q)=av2seems to be meant. Only the last pair’s adjustment survives, so the count of unmatched pairs appears to be wrong. - In the foreigner test, a sample of identical values gives a range of 0, and line 1840 then divides by zero.
- The minimum sample sizes the prompts ask for (at least 5, at least 15, an even number) are not checked.
- The REM dates the source article to 1981, but it appeared in 1983.
This program came from an Oliger (JLO SAFE) disk and was converted to load from tape. The disk-specific SAVE / in line 9998 became a plain SAVE, and the program autostarts at line 20. It was tested in ZEsarUX as far as the menu.
Source Code
10 REM Modified from 'Managing with the ZX81' by C E Coffin in SYNC Magazine, month ?, 1981
20 BORDER 6: PAPER 6: INK 1
30 CLS
40 LET d=0
50 LET s=d: LET z=d
60 LET s$="significant"
70 PRINT AT 1,7;"STATISTICAL TESTS"
80 PRINT TAB 7;"-----------------"
90 GO SUB 180
100 INPUT "Enter your option ";x
110 IF x<1 OR x>5 THEN GO TO 100
120 CLS
130 IF x=1 THEN GO TO 310
140 IF x=2 THEN GO TO 630
150 IF x=3 THEN GO TO 890
160 IF x=4 THEN GO TO 1200
170 IF x=5 THEN GO TO 1600
180 REM menu display
190 DIM m$(5,30)
200 LET m$(1)=" Significance of a mean"
210 LET m$(2)=" Difference between two means"
220 LET m$(3)=" Test for a trend"
230 LET m$(4)=" Test for association"
240 LET m$(5)=" Finding a foreigner"
250 FOR w=1 TO 5
260 PRINT 'w;m$(w)
270 NEXT w: RETURN
290 PRINT TAB 13;"--------": RETURN
310 REM significance of a mean
320 PRINT TAB 4;m$(1)
330 GO SUB 290
340 PRINT AT 6,4;"Enter previous average"
350 INPUT a: PRINT TAB 14;a
360 PRINT AT 10,0;"Enter no. of items in new sample"
370 PRINT AT 11,14;
380 GO SUB 1880
390 PRINT AT 14,2;"Now enter individual items"
400 FOR l=1 TO t
410 INPUT n(l): PRINT n(l)
420 IF n(l)<a THEN LET j=j+1
430 IF n(l)>a THEN LET k=k+1
440 NEXT l
450 GO SUB 590
460 CLS
470 PRINT AT 6,0;"There is ";
480 IF d<=z THEN PRINT "no ";
490 PRINT s$;" change"
500 PRINT TAB 6;"(at 1 in 20 level)"
510 IF d=0 OR d>z THEN GO TO 1930
520 PAUSE 30
530 LET e=INT (((2*s)/d)^2)-s
540 IF e>0 AND e<100 THEN GO TO 560
550 GO TO 1930
560 PRINT AT 11,5;"For repeat tests, ";e
570 PRINT "more items of data are required"
580 GO TO 1930
590 LET s=j+k
600 LET z=2*SQR s
610 LET d=ABS (j-k)
620 RETURN
630 REM Difference between 2 means
640 PRINT TAB 1;m$(2)
650 GO SUB 290
660 PRINT AT 6,2;"No. of items in each sample"
670 PRINT TAB 9;"(at least 5)? ";
680 GO SUB 1880
690 PRINT AT 10,1;"Now enter one item from each"
700 PRINT TAB 7;"sample at a time"
710 DIM r(t)
720 FOR l=1 TO t
730 INPUT n(l)
740 INPUT r(l)
750 PRINT n(l),r(l)
760 IF n(l)>r(l) THEN LET j=j+1
770 IF n(l)<r(l) THEN LET k=k+1
780 NEXT l
790 GO SUB 590
800 CLS
810 PRINT AT 8,9;"1st sample is "
820 IF d>z THEN GO TO 850
830 PRINT "not ";s$;"ly different from"
840 GO TO 870
850 IF j>k THEN PRINT TAB 2;s$;"ly greater than"
860 IF j<k THEN PRINT TAB 3;s$;"ly less than"
870 PRINT TAB 10;"2nd sample"
880 GO TO 520
890 REM Test for a trend
900 PRINT TAB 8;m$(3)
910 GO SUB 290
920 PRINT AT 8,5;"No. of items in sample"
930 PRINT TAB 7;"(at least 15)? ";
940 GO SUB 1880
950 LET t1=INT (t/3)
960 PRINT AT 12,5;"Enter items one by one"
970 FOR l=1 TO t
980 INPUT n(l)
990 PRINT n(l)
1000 NEXT l
1010 GO SUB 590
1020 CLS
1030 LET q=t-t1
1040 FOR p=1 TO t1
1050 IF n(p)<n(q) THEN LET j=j+1
1060 IF n(p)>n(q) THEN LET k=k+1
1070 LET q=q+1
1080 NEXT p
1090 CLS
1100 LET y=2*(SQR t1)
1110 PRINT AT 8,3;"Trend is ";
1120 IF ABS (j-k)<=y THEN GO TO 1180
1130 PRINT s$;"ly"
1140 IF j>k THEN PRINT TAB 12;"up";
1150 IF j<k THEN PRINT TAB 10;"down";
1160 PRINT "wards"
1170 GO TO 1930
1180 PRINT "not ";s$
1190 GO TO 520
1200 REM Test for association
1210 PRINT TAB 6;m$(4)
1220 GO SUB 290
1230 PRINT AT 6,2;"Samples must be of equal size"
1240 PRINT TAB 7;"Total no. of items"
1250 PRINT TAB 2;"(must be an even number): ";
1260 GO SUB 1880
1270 LET tot1=0
1280 LET tot2=0
1290 PRINT AT 11,0;"Enter one item from each sample"
1300 PRINT TAB 11;"at a time"
1310 LET p=1
1320 FOR q=2 TO t STEP 2
1330 INPUT n(p)
1340 INPUT n(q)
1350 PRINT n(p),n(q)
1360 LET tot1=tot1+n(p)
1370 LET tot2=tot2+n(q)
1380 LET p=p+2
1390 NEXT q
1400 CLS
1410 LET av1=tot1/(t/2)
1420 LET av2=tot2/(t/2)
1430 LET p=1
1440 FOR q=2 TO t STEP 2
1450 IF ((n(p)<av1) AND (n(q)<av2)) OR ((n(p)>av1) AND (n(q)>av2)) THEN LET j=j+1
1460 LET k=(t/2)-j
1470 IF (n(p)=av1) OR (n(q)<av2) THEN LET k=k-1
1480 LET p=p+2
1490 NEXT q
1500 LET z=2*(SQR (t/2))
1510 PRINT AT 8,10;"There is ";
1520 IF ABS (j-k)<=z THEN GO TO 1550
1530 PRINT "a"
1540 GO TO 1560
1550 PRINT "no"
1560 PRINT TAB 4;s$;" association"
1570 PRINT TAB 4;"between the two samples"
1580 GO SUB 590
1590 GO TO 520
1600 REM Finding a foreigner
1610 PRINT TAB 6;m$(5)
1620 GO SUB 290
1630 PRINT AT 7,5;"No. of items in sample"
1640 PRINT TAB 5;"(without foreigner)? ";
1650 GO SUB 1880
1660 PRINT
1670 PRINT AT 11,1;"Enter items (without foreigner)"
1680 LET k=100000
1690 FOR l=1 TO t
1700 INPUT n(l)
1710 PRINT n(l)
1720 IF j<n(l) THEN LET j=n(l)
1730 IF k>n(l) THEN LET k=n(l)
1740 NEXT l
1750 CLS
1760 PRINT AT 8,4;"Enter the foreigner: ";
1770 INPUT f
1780 PRINT f
1790 LET y1=ABS (j-k)
1800 IF j<f THEN LET j=f
1810 IF k>f THEN LET k=f
1820 LET y2=ABS (j-k)
1830 PRINT AT 12,5;f;" is";
1840 IF y2/y1>2 THEN GO TO 1860
1850 PRINT " not";
1860 PRINT " a foreigner"
1870 GO TO 1930
1880 INPUT t
1890 PRINT t
1900 DIM n(t)
1910 LET j=0: LET k=j
1920 RETURN
1930 PRINT AT 19,2;"Press any key for menu": PAUSE 0
1940 GO TO 30
9998 SAVE /"BUS STATS" LINE 20Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
