Compucolor.org – Virtual Media

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

5 REM  REGRES
7 REM  WRITTEN BY WALTER DEGLER  2/15/79
9 REM
10 REM  REGRESSION INFORMATION AND A GRAPH ARE DISPLAYED FOR
12 REM  DATA IN A DISK FILE OR ENTERED BY KEYBOARD.
20 DATA Y=AX+B,Y=LOG(AX+B),Y=EXP(AX+B),Y=1/(AX+B)
25 FOR I= 0TO 3:READ E$(I):NEXT
30 DIM XS(5),YS(13),T(29)
35 DATA 12.706,4.303,3.182,2.776,2.571,2.447,2.365,2.306,2.262
36 DATA 2.228,2.201,2.179,2.16,2.145,2.131,2.12,2.11,2.101,2.093
37 DATA 2.086,2.08,2.074,2.069,2.064,2.06,2.056,2.052,2.048
38 DATA 2.045,2.042
40 FOR I= 0TO 29:READ T(I):NEXT
45 PLOT 27,24,12,14
1999 REM
2000 REM  INPUT DATA
2005 INPUT "DATA SOURCE (F-FILE OR K-KEYBOARD): ";Z$
2010 IF Z$= "F"THEN 2025
2015 IF Z$< > "K"THEN 2005
2020 GOTO 10000
2025 INPUT "FILE NAME AND TYPES (EG. TEST,1,3): ";F$,T1,T2
2050 FILE "R",1,F$,4
2075 GET 1,1,1;NT,NO
2080 DIM D(NO- 1,2)
2100 FOR I= 0TO NO- 1
2125 GET 1,T1,4* I+ 9;D(I,0)
2150 GET 1,T2,4* I+ 9;D(I,1)
2175 NEXT
2200 FILE "C",1
2999 REM
3000 REM  SELECT CURVE AND TRANSFORM DATA
3005 PRINT
3010 PLOT 6,1
3025 PRINT "SELECT NUMBER OF REGRESSION EQUATION:"
3030 PLOT 6,3
3050 PRINT "1)LINEAR      Y=AX+B"
3075 PRINT "2)LOGARITHMIC Y=LOG(AX+B)"
3100 PRINT "3)EXPONENTIAL Y=EXP(AX+B)"
3125 PRINT "4)RECIPROCAL  Y=1/(AX+B)"
3150 INPUT Z
3160 PLOT 15
3175 E$= E$(Z- 1)
3200 IF Z= 1THEN DEF FN A(X)= X:DEF FN B(X)= SL* X+ IN
3225 IF Z= 2THEN DEF FN A(X)= EXP (X):DEF FN B(X)= LOG (SL* X+ IN)
3250 IF Z= 3THEN DEF FN A(X)= LOG (X):DEF FN B(X)= EXP (SL* X+ IN)
3275 IF Z= 4THEN DEF FN A(X)= 1/ X:DEF FN B(X)= 1/ (SL* X+ IN)
3300 FOR I= 0TO NO- 1
3310 IF Z= 2AND D(I,1)> 87THEN D(I,1)= 87
3312 IF Z= 3AND D(I,0)< = 0THEN D(I,1)= 1E- 38
3315 D(I,2)= FN A(D(I,1))
3322 NEXT
3999 REM
4000 REM  COMPUTE STATISTICS
4025 FOR I= 0TO NO- 1
4050 FOR J= 0TO 2
4075 SM(J)= SM(J)+ D(I,J)
4100 SQ(J)= SQ(J)+ D(I,J)* D(I,J)
4110 IF I= 0THEN MX(J)= D(I,J):MN(J)= D(I,J)
4125 IF D(I,J)> MX(J)THEN MX(J)= D(I,J)
4150 IF D(I,J)< MN(J)THEN MN(J)= D(I,J)
4175 NEXT
4200 SS= SS+ D(I,0)* D(I,2)
4225 NEXT
4250 FOR I= 0TO 2
4275 R(I)= MX(I)- MN(I)
4300 M(I)= SM(I)/ NO
4310 V(I)= (NO* SQ(I)- SM(I)* SM(I))/ (NO* (NO- 1))
4325 SD(I)= SQR (ABS (V(I)))
4350 SE(I)= SD(I)/ SQR (NO)
4375 NEXT
4380 FOR I= 0TO NO- 1
4385 FOR J= 0TO 2
4390 M2(J)= M2(J)+ (D(I,J)- M(J))* (D(I,J)- M(J))
4395 NEXT J,I
4400 X= NO* SQ(0)- SM(0)* SM(0)
4425 SL= (NO* SS- SM(0)* SM(2))/ X
4430 IN= (SQ(0)* SM(2)- SM(0)* SS)/ X
4450 CO= SL* SD(0)/ SD(2)
4475 CD= CO* CO* 100
4500 DF= NO- 2:GOSUB 12000
4999 REM
5000 REM  PRINT STATISTICS
5010 PLOT 6,1,12,14
5025 PRINT SPC( 21)"REGRESSION STATISTICS"
5060 PLOT 6,3,15
5075 PRINT "# OBSERVATIONS: "NO;TAB( 30)"CORRELATION: "CO
5100 PRINT "A:              "SL;TAB( 30)"EQUATION: "E$
5125 PRINT "B:              "IN
5150 PRINT "XY-SUM:         "SS
5175 PRINT :PRINT
5180 PLOT 6,1,14
5200 PRINT TAB( 18)"X-STATISTICS    Y-STATISTICS"
5210 PLOT 6,3,15
5225 PRINT "ARITHMETIC MEAN:     "M(0);TAB( 37);M(1)
5250 PRINT "STANDARD DEVIATION:  "SD(0);TAB( 37);SD(1)
5275 PRINT "RANGE:               "R(0);TAB( 37);R(1)
5300 PRINT "STANDARD ERROR:      "SE(0);TAB( 37);SE(1)
5325 PRINT "MAXIMUM VALUE:       "MX(0);TAB( 37);MX(1)
5350 PRINT "MINIMUM VALUE:       "MN(0);TAB( 37);MN(1)
5375 PRINT "TOTAL SUM:           "SM(0);TAB( 37);SM(1)
5400 PRINT "SUM OF SQUARES:      "SQ(0);TAB( 37);SQ(1)
5425 PLOT 6,6,14
5430 PRINT :PRINT
5435 GOSUB 12000
5440 GOSUB 14000
5460 PLOT 6,4
5470 INPUT "SAVE? ";Z$
5475 IF LEFT$ (Z$,1)= "Y"THEN PLOT 27,4:PRINT "SAVE REGRES.DSP 6000 1000":PLOT 27,27
5477 PRINT
5480 INPUT "ARE CONFIDENCE LIMITS FOR A PREDICTED VALUE DESIRED? ";Z$
5485 IF LEFT$ (Z$,1)= "N"THEN 5525
5487 PLOT 12
5490 INPUT "VALUE: ";X0
5495 GOSUB 15000:GOTO 5480
5500 PRINT
5525 REM
5999 REM
6000 REM  SET SCALES
6025 FOR I= 0TO 1
6030 S(I)= .4* 10^ (INT (LOG (R(I))/ 2.30259+ .8539))
6050 S(I)= S(I)/ 2:IF R(I)/ S(I)< 2.799THEN 6050
6075 MN(I)= S(I)* INT ((MN(I)+ .001* S(I))/ S(I))
6100 MX(I)= - S(I)* INT (- (MX(I)- .001* S(I))/ S(I))
6110 R(I)= MX(I)- MN(I)
6125 NEXT
6150 XS= MN(0):YS= MN(1)
6160 XE= MX(0):YE= MX(1)
6175 XD= R(0)/ 5:YD= R(1)/ 13
6200 GOTO 11000
6999 REM
7000 REM  DRAW COORDINATE SYSTEM
7025 PLOT 2,21,15,242
7050 PLOT 114,15,114,120,21,120,21,15
7075 PLOT 255
7100 FOR I= 0TO 5
7125 PLOT 2,22+ 18* I,14,255
7150 XS(I)= XS+ I* XD
7175 PLOT 3,9+ 9* I,29:PRINT XS(I)
7200 NEXT
7225 FOR I= 0TO 13
7250 PLOT 2,20,16+ 8* I,255
7275 LY= 6
7300 YS(I)= YS+ I* YD
7325 PLOT 3,7- LY,27- 2* I:PRINT YS(I)
7350 NEXT
7375 GOTO 9000
7999 REM
8000 REM  PLOT DATA POINTS
8010 PLOT 6,3
8025 FOR I= 0TO NO- 1
8100 XP= 23+ 18* (D(I,0)- XS)/ XD
8125 YP= 16+ 8* (D(I,1)- YS)/ YD
8150 PLOT 2,XP,YP,255
8175 NEXT
8180 SS= 0
8185 FOR I= 0TO 2:SM(I)= 0:SQ(I)= 0:M2(I)= 0:NEXT
8200 PLOT 6,1,3,0,31
8210 INPUT "ENTER 1-NEW CURVE, 2-SAVE OR 3-END: ";X
8220 PLOT 12
8275 IF X= 1THEN PLOT 6,2:GOTO 3000
8300 IF X< > 2THEN LOAD "MENU":RUN
8325 PLOT 27,4:PRINT "SAVE RGPLOT.DSP 6000 1000":PLOT 27,27
8350 PLOT 12
8375 INPUT "ENTER 1-NEW CURVE OR 2-END: ";X
8380 PLOT 12
8400 IF X= 1THEN PLOT 6,2:GOTO 3000
8425 LOAD "MENU":RUN
8999 REM
9000 REM  PLOT CURVE
9010 PLOT 6,1
9025 FOR I= 0TO 111
9050 X= XS+ I* XD/ 18
9075 IF X> XETHEN 8000
9080 IF Z= 2AND SL* X+ IN< = 0THEN 9225
9085 IF Z= 3AND SL* X+ IN> 87THEN 9225
9100 Y= FN B(X)
9125 IF Y< YSOR Y> YETHEN 9225
9150 XP= 22+ I
9175 YP= 16+ 8* (Y- YS)/ YD
9200 PLOT 2,XP,YP,255
9225 NEXT
9230 PLOT 6,2
9250 GOTO 8000
9999 REM
10000 REM  TYPE IN DATA
10025 PLOT 27,11,12
10050 INPUT "NUMBER OF PAIRS: ";NO
10060 DIM D(NO- 1,2)
10065 PLOT 12,15,6,1
10075 PRINT :PRINT "OBSERVATION NUMBER, INDEPENDENT VALUE, DEPENDENT VALUE:"
10080 PLOT 6,3
10100 INPUT "#";I
10125 IF I< 1THEN PLOT 27,24,12,14:GOTO 3000
10150 FOR J= 0TO 1
10175 PRINT SPC( 6+ 10* J);:PLOT 28
10200 INPUT "";D(I- 1,J)
10225 NEXT
10250 GOTO 10100
10999 REM
11000 REM  PRINT NAMES
11005 PLOT 12,6,1,4
11010 INPUT "GRAPH NAME: ";G$
11020 INPUT "X-SCALE NAME, Y-SCALE NAME: ";X$,Y$
11023 PLOT 12
11025 PLOT 12,6,6,15
11050 PLOT 3,INT ((64- LEN (G$))/ 2),0:PRINT G$
11075 PLOT 27,10
11100 PLOT 3,0,2+ INT ((26- LEN (Y$))/ 2):PRINT Y$
11125 PLOT 27,24
11150 PLOT 3,7+ INT ((56- LEN (X$))/ 2),30:PRINT X$
11175 PLOT 6,2
11200 GOTO 7000
11999 REM
12000 REM  DETERMINE T-VALUE
12025 IF DF< 31THEN T= T(DF- 1):GOTO 12125
12050 IF DF< 40THEN T= (17397- 35* DF)/ 8000:GOTO 12125
12075 IF DF< 120THEN T= 1.99:GOTO 12125
12100 T= 1.98
12125 S2= (M2(2)- SL* SL* M2(0))/ (NO- 2)
12150 RETURN
13999 REM
14000 REM  PRINT CONFIDENCE LIMITS
14010 PLOT 6,1
14050 PRINT "THERE IS A 95% PROBABILITY THAT"
14075 PRINT "TRUE 'A' LIES BETWEEN ";
14100 X= T* SQR (ABS (S2/ M2(0)))
14125 PRINT SL- X" AND "SL+ X
14150 PRINT "TRUE 'B' LIES BETWEEN ";
14175 X= T* SQR (ABS (S2/ NO))
14200 PRINT IN- X" AND "IN+ X
14210 PLOT 15
14225 RETURN
14999 REM
15000 REM  PRINT CONFIDENCE LIMITS FOR PREDICTION
15002 IF Z= 2AND SL* X0+ IN< = 0THEN PLOT 6,1:PRINT "OUT OF RANGE!":PLOT 6,2:RETURN
15005 IF Z= 3AND SL* X0+ IN> 87THEN PLOT 6,1:PRINT "OUT OF RANGE!":PLOT 6,2:RETURN
15007 PRINT
15009 PLOT 6,3
15010 PRINT "THE COMPUTED VALUE FOR "X0" IS "FN B(X0)
15025 P= T* SQR (ABS (S2* (1+ 1/ NO+ (X0- MN(0))* (X0- MN(0))/ M2(0))))
15050 X= FN B(X0)
15055 PRINT
15060 PLOT 6,6
15075 PRINT "THERE IS A 95% PROBABILITY THAT"
15100 PRINT "THE TRUE VALUE FOR "X0" LIES BETWEEN ";
15125 PRINT X- P" AND "X+ P
15127 PRINT
15130 PLOT 6,1
15150 RETURN