1 1 REM MODIFIED FEB 1975
  2 2 PRINT"               L I N R E G"
  3 200 DATA 1E35,1E35
  4 201 PRINT" DO YOU WANT INSTRUCTIONS? (YES=1, NO=0)"
  5 202 INPUT Z9
  6 203 IF Z9 = 1 THEN 650
  7 206 PRINT"WHAT TYPE OF CURVE DO YOU WANT TO FIT:"
  8 210 PRINT "LINEAR=1, EXPONENTIAL=2, POWER=3";
  9 215 INPUT Q1
 10 220 DIM D(250,2)
 11 225 PRINT
 12 230 LET I=0
 13 235 LET I=I+1
 14 240 READ D(I,1),D(I,2)
 15 245 IF D(I,1)<>1E35 THEN 235
 16 250 LET Q2=I-1
 17 255 LET S9=0
 18 260 IF Q1=1 THEN 280
 19 265 IF Q1=2 THEN 335
 20 270 IF Q1=3 THEN 405
 21 275 GOTO 230
 22 280 LET S9=1
 23 285 GOSUB 505
 24 290 PRINT "LINEAR:  Y=A+B*X  WITH  A=";Q8;"AND B=";Q9
 25 295 GOSUB 580
 26 300 FOR J=1 TO Q2
 27 305 LET W7=Q8+Q9*D(J,1)
 28 310 LET Z7=W7-D(J,2)
 29 315 LET Q4=100*Z7/D(J,2)
 30 320 PRINT D(J,1),D(J,2),W7,Z7,Q4
 31 325 NEXT J
 32 330 STOP
 33 335 FOR J=1 TO Q2
 34 340 LET D(J,2)=LOG(D(J,2))
 35 345 NEXT J
 36 350 GOSUB 505
 37 355 PRINT "EXPONENTIAL:  Y=A*EXP(B*X)  WITH  A=";EXP(Q8);"AND B=";Q9
 38 360 GOSUB 580
 39 365 FOR J=1 TO Q2
 40 370 LET W7=EXP(Q8+Q9*D(J,1))
 41 375 LET W8=EXP(D(J,2))
 42 380 LET Z7=W7-W8
 43 385 LET Q4=100*Z7/W8
 44 390 PRINT D(J,1),W8,W7,Z7,Q4
 45 395 NEXT J
 46 400 STOP
 47 405 FOR J=1 TO Q2
 48 410 LET D(J,1)=LOG(D(J,1))
 49 415 LET D(J,2)=LOG(D(J,2))
 50 420 NEXT J
 51 425 GOSUB 505
 52 430 PRINT "POWER:  Y=A*(X^B)  WITH  A=";EXP(Q8);"AND B=";Q9
 53 435 GOSUB 580
 54 440 FOR J=1 TO Q2
 55 445 LET W7=EXP(D(J,1))
 56 450 LET W8=EXP(D(J,2))
 57 455 LET W9=EXP(Q8)*W7^Q9
 58 460 LET Q4=W9/W8-1
 59 465 LET Z7=W9-W8
 60 470 IF Q4<0 THEN 485
 61 475 LET Q4=INT(1000*Q4+0.5)/10
 62 480 GOTO 490
 63 485 LET Q4=INT(1000*Q4-0.5)/10
 64 490 PRINT W7,W8,W9,Z7,Q4
 65 495 NEXT J
 66 500 STOP
 67 505 LET Q3=0
 68 510 LET Q4=0
 69 515 LET Q5=0
 70 520 LET Q6=0
 71 525 LET Q7=0
 72 530 FOR J=1 TO Q2
 73 535 LET Q3=Q3+D(J,1)
 74 540 LET Q4=Q4+D(J,2)
 75 545 LET Q5=Q5+D(J,1)*D(J,2)
 76 550 LET Q6=Q6+(D(J,1))^2
 77 555 LET Q7=Q7+(D(J,2))^2
 78 560 NEXT J
 79 565 LET Q9=(Q2*Q5-Q3*Q4)/(Q2*Q6-Q3^2)
 80 570 LET Q8=(Q4-Q3*Q9)/Q2
 81 575 RETURN
 82 580 LET Q0=(Q2*Q5-Q3*Q4)/SQR((Q2*Q6-Q3^2)*(Q2*Q7-Q4^2))
 83 585 PRINT
 84 590 PRINT "COEFFICIENT OF CORRELATION = ";Q0
 85 595 PRINT "COEFFICIENT OF DETERMINATION = ";Q0^2
 86 600 PRINT
 87 605 PRINT "DO YOU WANT TO SEE A COMPARISON OF THE ACTUAL Y'S AND"
 88 610 PRINT "THE ESTIMATED Y'S. 1=YES, 0=NO";
 89 615 INPUT P9
 90 620 IF P9<>1 THEN 715
 91 625 PRINT
 92 630 PRINT "X-ACTUAL","Y-ACTUAL","Y-ESTIM","DIFFER","PCT-DIFF"
 93 635 PRINT
 94 640 RETURN
 95 645 PRINT
 96 650 PRINT "THIS IS A LINEAR REGRESSION PROGRAM FOR DATA IN TWO "
 97 655 PRINT "VARIABLES, X AND Y.  FROM INPUT POINTS, DESCRIBED BY"
 98 660 PRINT "THEIR X AND Y COORDINATES, AN EQUATION IS PRODUCED THAT"
 99 665 PRINT "BEST FITS THESE POINTS IN THE LEAST-SQUARES SENSE.  TO"
100 670 PRINT "USE THE PROGRAM, TYPE THE FOLLOWING:"
101 675 PRINT
102 680 PRINT "   2 DATA  X(1),Y(1), X(2),Y(2),......, X(N),Y(N)"
103 685 PRINT "        (WHERE X(1),Y(1) IS THE FIRST POINT, X(2),"
104 690 PRINT "        Y(2) IS THE SECOND, AND SO ON UNTIL ALL"
105 695 PRINT "        POINTS HAVE BEEN ENTERED.  ADDITIONAL DATA"
106 700 PRINT "        STATEMENTS 3-199 MAY BE USED AS NEEDED.)"
107 705 PRINT
108 715 END