Compucolor.org – Virtual Media

Listing of file='POLREG.BAS;01' on disk='vmedia/statistics_2-sector.ccvf'

5 REM   POLREG
6 REM   POLYNOMIAL REGRESSION
7 REM  WRITTEN BY WALTER DEGLER  3/30/79
10 REM
12 REM  POLYNOMIAL REGRESSION FOR DEGREES 2 TO 5
30 DIM XS(8),YS(14)
32 DIM D(199,1)
40 PLOT 12,14,27,24,6,2
50 GOTO 2000
2000 REM  INPUT DATA
2025 INPUT "DATA SOURCE (F-FILE OR K-KEYBOARD): ";Z$
2050 IF Z$= "F"THEN 2500
2075 INPUT "NUMBER OF DATA POINTS: ";NO
2080 PLOT 12,15,27,11,6,1
2100 PRINT "OBSERVATION #, INDEPENDENT VALUE, DEPENDENT VALUE:"
2110 PRINT
2125 PLOT 6,3
2150 INPUT "#";I
2175 IF I< 1THEN PLOT 27,24,6,2:GOTO 2800
2200 PRINT SPC( 6);:PLOT 28
2225 INPUT "";D(I- 1,0)
2250 PRINT SPC( 16);:PLOT 28
2275 INPUT "";D(I- 1,1)
2300 GOTO 2150
2500 INPUT "FILE NAME: ";F$
2525 INPUT "DEPENDENT VARIABLE TYPE, INDEPENDENT VARIABLE TYPE: ";T1,T2
2550 FILE "R",1,F$,6
2575 GET 1,1,5;NO
2600 FOR I= 0TO NO- 1
2625 GET 1,T1,4* I+ 9;D(I,0)
2650 GET 1,T2,4* I+ 9;D(I,1)
2675 NEXT
2700 FILE "C",1
2800 INPUT "DEGREE: ";D
2999 REM
3000 REM  COMPUTE SUMS
3010 X(0)= NO
3025 FOR I= 0TO NO- 1
3030 FOR J= 0TO 1
3035 IF I= 0THEN MN(J)= D(I,J):MX(J)= D(I,J)
3040 IF D(I,J)< MN(J)THEN MN(J)= D(I,J)
3045 IF D(I,J)> MX(J)THEN MX(J)= D(I,J)
3047 NEXT
3050 SM(1)= SM(1)+ D(I,1)
3055 SQ(1)= SQ(1)+ D(I,1)* D(I,1)
3065 X= 1
3075 FOR J= 1TO D+ D
3080 Z(J- 1)= Z(J- 1)+ X* D(I,1)
3100 X= X* D(I,0)
3125 X(J)= X(J)+ X
3150 NEXT J,I
3152 SM(0)= X(1):SQ(0)= X(2)
3155 FOR I= 0TO 1
3160 R(I)= MX(I)- MN(I)
3165 M(I)= SM(I)/ NO
3167 U(I)= NO* SQ(I)- SM(I)* SM(I)
3170 W(I)= U(I)/ (NO* (NO- 1))
3175 SD(I)= SQR (ABS (W(I)))
3225 NEXT
3999 REM
4000 REM  SET UP MATRIX
4025 FOR I= 0TO D
4050 A(I,D+ 1)= Z(I)
4075 FOR J= 0TO D
4100 A(I,J)= X(I+ J)
4125 NEXT J,I
4999 REM
5000 REM  SOLVE EQUATIONS SIMULTANEOUSLY FOR COEFFICIENTS
5025 FOR I= 0TO D
5050 REM
5075 REM  FIND PIVOT IN ROW
5080 MX= 0
5100 FOR J= 0TO D
5125 IF ABS (A(I,J))< = MXTHEN 5225
5150 IF CK(J)= 1THEN 5225
5175 MX= ABS (A(I,J))
5200 LC(I)= J
5225 NEXT J
5231 GOTO 5275
5240 IF ABS (MX)> = 1E- 5THEN 5275
5245 PRINT "MATRIX SINGULAR":PRINT "CHANGE DATA"
5250 FOR K= 0TO 500:NEXT K
5255 GOTO 40
5275 CK(LC(I))= 1
5300 REM  NORMALIZE PIVOT ROW
5325 K= LC(I):L= A(I,K)
5350 FOR J= 0TO D+ 1
5375 A(I,J)= A(I,J)/ L
5400 NEXT J
5425 REM  TRANSFORM NON-PIVOT ROWS
5450 FOR J= 0TO D
5475 IF J= ITHEN 5625
5525 L= A(J,K)
5550 FOR M= 0TO D+ 1
5575 A(J,M)= A(J,M)- L* A(I,M)
5600 NEXT M
5625 NEXT J
5650 NEXT I
5675 FOR I= 0TO D
5700 V(LC(I))= A(I,D+ 1)
5710 S$(LC(I))= "+":IF V(LC(I))< 0THEN S$(LC(I))= "-"
5725 NEXT
5750 FOR I= 0TO D
5775 CO= CO+ V(I)* Z(I)
5800 NEXT
5825 CO= 1- (SQ(1)- CO)/ (W(1)* NO)
5850 CD= 100* CO
5875 CO= SQR (ABS (CO))
5900 GOTO 10000
5999 REM
6999 REM
7000 REM  DRAW COORDINATE SYSTEM
7025 PLOT 12,14,6,2
7050 INPUT "GRAPH NAME: ";G$
7075 INPUT "X-SCALE NAME, Y-SCALE NAME: ";X$,Y$
7080 INPUT "X-SCALE (START, END, DIFFERENCE): ";XS,XE,XD
7085 INPUT "Y-SCALE (START, END, DIFFERENCE): ";YS,YE,YD
7087 PLOT 15
7090 XN= INT ((XE- XS)/ XD)+ 1:IF XN> 8THEN XN= 8
7095 YN= INT ((YE- YS)/ YD)+ 1:IF YN> 14THEN YN= 14
7100 XI= INT (49/ (XN- 1))
7105 YI= INT (26/ (YN- 1))
7110 IF XI< 7THEN XI= 7
7115 IF YI< 1THEN YI= 1
7120 PLOT 12,6,6,15
7125 PLOT 3,INT ((64- LEN (G$))/ 2),0:PRINT G$
7150 PLOT 27,10
7175 PLOT 3,0,2+ INT ((26- LEN (Y$))/ 2):PRINT Y$
7200 PLOT 27,24
7225 PLOT 3,7+ INT ((56- LEN (X$))/ 2),30:PRINT X$
7250 PLOT 6,4
7275 I= 2* (10+ XI* (XN- 1)):J= 17+ 4* YI* (YN- 1)
7300 PLOT 2,17,15,242
7325 PLOT I,15,I,J,17,J,17,15,255
7350 FOR I= 0TO XN- 1
7375 PLOT 6,3
7400 XS(I)= XS+ I* XD
7425 PLOT 3,8+ I* XI,29:PRINT XS(I)
7430 PLOT 6,4,2,18+ 2* I* XI,14,255
7450 NEXT
7460 PLOT 6,3
7475 FOR I= 0TO YN- 1
7480 PLOT 6,3
7500 LY= LEN (STR$ (YS+ I* YD))
7525 YS(I)= YS+ I* YD
7550 PLOT 3,7- LY,27- I* YI:PRINT YS(I)
7560 PLOT 6,4,2,16,16+ 4* I* YI,255
7575 NEXT
7999 REM
8000 REM  DRAW CURVE AND PLOT POINTS
8025 PLOT 6,1
8050 FOR I= 0TO 2* XI* (XN- 1)
8075 X= XS+ I* XD/ (XI+ XI)
8100 IF X> XS+ XD* (XN- 1)THEN 8325
8110 Y= V(D)
8120 FOR J= D- 1TO 0STEP - 1
8130 Y= Y* X+ V(J)
8140 NEXT
8150 IF Y< YSOR Y> YS+ YD* (YN- 1)THEN 8200
8175 PLOT 2,18+ I,16+ 4* YI* (Y- YS)/ YD,255
8200 NEXT
8325 PLOT 6,3
8350 FOR I= 0TO NO- 1
8360 IF D(I,0)< XSOR D(I,0)> XS+ XD* (XN- 1)THEN 8450
8370 IF D(I,1)< YSOR D(I,1)> YS+ YD* (YN- 1)THEN 8450
8375 XP= 18+ 2* XI* (D(I,0)- XS)/ XD
8400 YP= 16+ 4* YI* (D(I,1)- YS)/ YD
8425 PLOT 2,XP,YP,255
8450 NEXT
8475 PLOT 6,1,3,0,31
8500 INPUT "ENTER 1-NEW SCALES, 2-SAVE OR 3-END: ";Z
8525 IF Z= 1THEN PLOT 12,14,6,2:GOTO 7080
8550 IF Z< > 2THEN LOAD "MENU":RUN
8575 PLOT 27,4:PRINT "SAV POLGR.DSP 6000-6FFF":PLOT 27,27
8600 GOTO 8475
9999 REM
10000 REM  DISPLAY STATISTICS
10010 PLOT 6,1,12,14
10025 PRINT SPC( 21)"REGRESSION STATISTICS"
10030 PLOT 6,3,15
10050 PRINT "# OF OBSERVATIONS: "NO
10075 PRINT "CORRELATION:       "CO
10100 PRINT "COEFF. OF DET.:    "CD"%"
10125 PRINT "XY-SUM:            "Z(1)
10130 PRINT
10150 PRINT "THE REGRESSION EQUATION IS"
10155 IF S$(0)= "+"THEN S$(0)= " "
10157 PRINT "Y=";
10160 X= ABS (V(0))
10165 IF X< 1E- 5THEN 10200
10170 C$= STR$ (X):IF X< .01THEN GOSUB 16000
10175 PRINT S$(0);C$
10200 X= ABS (V(1))
10205 IF X< 1E- 5THEN 10230
10210 C$= STR$ (X):IF X< .01THEN GOSUB 16000
10225 PRINT "  "S$(1);C$;TAB( 17);"* X"
10230 IF D= 1THEN 10330
10250 FOR I= 2TO D
10275 X= ABS (V(I))
10280 IF X< 1E- 5THEN 10325
10285 C$= STR$ (X):IF X< .01THEN GOSUB 16000
10300 PRINT "  "S$(I);C$;TAB( 17);"* X ^"I
10325 NEXT
10330 PRINT :PRINT
10335 PLOT 6,1,14
10350 PRINT TAB( 18)"X-STATISTICS    Y-STATISTICS"
10360 PLOT 6,3,15
10375 PRINT "ARITHMETIC MEAN:     "M(0);TAB( 37);M(1)
10400 PRINT "STANDARD DEVIATION:  "SD(0);TAB( 37);SD(1)
10425 PRINT "RANGE:               "R(0);TAB( 37);R(1)
10500 PRINT "MINIMUM VALUE:       "MN(0);TAB( 37);MN(1)
10525 PRINT "MAXIMUM VALUE:       "MX(0);TAB( 37);MX(1)
10550 PRINT "TOTAL SUM:           "SM(0);TAB( 37);SM(1)
10575 PRINT "SUM OF SQUARES:      "SQ(0);TAB( 37);SQ(1)
10600 PLOT 6,1,3,0,30
10625 INPUT "ENTER 1-SAVE, 2-DRAW GRAPH OR 3-END PROGRAM: ";Z
10650 IF Z= 2THEN 7000
10675 IF Z< > 1THEN LOAD "MENU":RUN
10700 PLOT 27,4:PRINT "SAV POLDSP.DSP 6000-6FFF":PLOT 27,27
10725 PLOT 12
10750 INPUT "ENTER 1-DRAW GRAPH OR 2-END PROGRAM: ";Z
10775 IF Z= 1THEN 7000
10800 LOAD "MENU":RUN
15999 REM
16000 REM   CHANGE EXPONENTIAL-FORM NUMBERS FOR DISPLAY
16025 B$= STR$ (X)
16030 C$= " .":IF X< 0THEN C$= "-."
16040 Z= VAL (RIGHT$ (B$,2))
16050 FOR K= 2TO Z
16075 C$= C$+ "0"
16080 IF LEN (C$)> 6THEN C$= "0":RETURN
16100 NEXT
16125 C$= C$+ MID$ (B$,2,1)
16130 IF LEN (B$)< 7THEN RETURN
16150 FOR K= 4TO LEN (B$)- 4
16175 C$= C$+ MID$ (B$,K,1)
16200 NEXT
16225 RETURN