This program performs statistical analysis including standard deviation, mean, linear regression, and trend line calculation on paired X/Y data sets. The user selects one of three modes — Statistics (X only), Regression, or Trend — before entering data values one at a time. Running totals for sums, sums of squares, and cross-products (SXTY) are accumulated incrementally, allowing standard deviation and mean to be updated after each entry using the computational formula SDX = SQR((E – N*CMX²)/(N-1)). Entering X = -9999 halts input cleanly, while a value where A – P < -10000 triggers the final regression/trend output at line 500. The slope and Y-intercept are computed from the accumulated sums using the standard least-squares formulas.
Program Analysis
Program Structure
The program is organized into four logical phases:
- Initialization (lines 3–11): All accumulators are zeroed and mode variable
Pis prepared. - Menu and mode selection (lines 10–20): The user chooses between Statistics (1), Regression (2), or Trend (3) via
INPUT P. - Data entry loop (lines 96–310): Repeated
INPUTof X (and conditionally Y) values with live display of running statistics. - Final output (lines 500–530): Full regression results printed after the sentinel value triggers exit from the loop.
Accumulator Variables
| Variable | Meaning |
|---|---|
TX | Running sum of X values |
TY | Running sum of Y values |
E | Running sum of X² values |
D | Running sum of Y² values |
SXTY | Running sum of X×Y cross-products |
N | Count of data points entered |
CMX / CMY | Current mean of X / Y |
SDX / SDY | Sample standard deviation of X / Y |
B | Regression slope |
C | Y-intercept |
Data Entry and Sentinel Logic
The data entry loop begins at line 96. Two sentinel mechanisms are used. Entering -9999 at line 102 triggers STOP, aborting the program entirely. The more interesting mechanism at line 101 checks IF A-P<-10000: because P is 1, 2, or 3, subtracting it from a large negative value like -9999 gives approximately -10000 or slightly less, so an input of -9999 is intended to route to the output section at line 500. However, the STOP at line 102 intercepts -9999 first, meaning line 101’s branch to line 500 would only activate for values below roughly -10001 + P — a subtle ordering issue. In practice, entering a value such as -10002 would correctly route to line 500 without stopping.
Standard Deviation Formula
The program uses the computational (single-pass) formula for sample standard deviation: SDX = SQR((E - N*CMX²) / (N-1)), which avoids storing all individual values. This is memory-efficient and well-suited to the constrained environment. Guards at lines 165 and 245 skip the calculation when N=1 to avoid division by zero.
Regression Calculation
At line 500, the least-squares slope is computed as B = (SXTY - N*CMX*CMY) / (E - N*CMX²), which is the standard formula expressed in terms of accumulated sums. The Y-intercept follows as C = CMY - B*CMX. These are algebraically equivalent to the textbook formulas using raw sums of deviations. Line 530 conditionally prints the trend line equation in the form Y = C + B*X only when mode 3 (Trend) is selected.
Display Techniques
The program makes extensive use of PRINT AT for precise screen positioning, overlaying live-updating statistics (mean and standard deviation) at fixed screen coordinates during Statistics mode. In Regression/Trend modes, the row variable R is incremented at line 216 after each Y entry to scroll data down the screen, providing a running table of entered X/Y pairs. The column positions (3, 12, 16) give a rough tabular layout without using TAB in the loop.
Notable Anomalies
- In Statistics mode (
P=1), the Y input section (lines 200–260) is bypassed by theGOTO 300at line 180, butSDYandCMYare never initialized, which would produce an error if they were accidentally referenced — they are not, so this is harmless. - The row counter
Ris initialized to 1 at line 6 and never reset, so entering more than roughly 18 data pairs in Regression/Trend mode would causePRINT AT R,...to wrap or error. - In Statistics mode the live display at line 300 updates
SDXandCMXon screen after each X entry, providing immediate feedback, which is a useful interactive design choice.
Content
Image Gallery
Source Code
3 LET TX=0
4 LET TY=0
5 LET N=0
6 LET R=1
7 LET E=0
8 LET D=0
9 LET SXTY=0
10 PRINT AT 4,10;"[C][H][O][O][S][E]█[T][E][S][T]";AT 7,8;"1. STATISTICS";AT 9,8;"2. REGRESSION";AT 11,8;"3. TREND"
11 LET SDX=0
20 INPUT P
50 CLS
60 IF P=1 THEN PRINT AT 4,2;"[S][T][A][N][.]█[D][E][V][.][=]";AT 5,8;"[M][E][A][N][=]"
85 IF P=1 THEN GOTO 96
90 PRINT " X"," Y"
96 PRINT AT 20,1;"TYPE ONE X-VALUE-[X][=][-][9][9][9][9]█[T][O]█[R][U][N]"
100 INPUT A
101 IF A-P<-10000 THEN GOTO 500
102 IF A=-9999 THEN STOP
105 IF P<>1 THEN PRINT AT R,3;A;AT R,12;"█"
130 LET TX=TX+A
140 LET E=E+A**2
150 LET N=N+1
160 LET CMX=TX/N
165 IF N=1 THEN GOTO 180
170 LET SDX=SQR ((E-N*CMX**2)/(N-1))
180 IF P=1 THEN GOTO 300
200 PRINT AT 10,20;"[Y]"
210 INPUT Y
215 PRINT AT R,16;Y
216 LET R=R+1
220 LET TY=TY+Y
230 LET D=D+Y**2
240 LET CMY=TY/N
245 IF N=1 THEN GOTO 260
250 LET SDY=SQR ((D-N*CMY**2)/(N-1))
260 LET SXTY=SXTY+A*Y
270 GOTO 96
300 PRINT AT 4,13;SDX;AT 5,13;CMX
310 GOTO 96
500 LET B=(SXTY-N*CMX*CMY)/(E-N*CMX**2)
501 LET C=CMY-B*CMX
505 CLS
510 PRINT "STAN DEV X=";SDX
511 PRINT TAB 9;"Y=";SDY
512 PRINT "CUR MEAN X=";CMX
513 PRINT TAB 9;"Y=";CMY
520 PRINT "Y-INTCPT= ";C
525 PRINT "SLOPE= ";B
530 IF P=3 THEN PRINT AT 9,0;"TREND LINE EQ> Y=";C;"+";B;"X"
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.