10 PRINT "NTH-ORDER REGRESSION"
20 PRINT
28 REM - SET LIMITS ON DEGREE OF EQUATION TO
29 REM - A(2D+1),R(D+1,D+2),T(D+2) (WHERE D=MAX. DEGREE OF EQUATION)
30 DIM A(13),R(7,8),T(8)
40 PRINT "DEGREE OF EQUATION";
50 INPUT D
60 PRINT "NUMBER OF KNOWN POINTS";
70 INPUT N
80 A(1)=N
89 REM - ENTER COORDINATES OF DATA POINTS
90 FOR I=1 TO N
100 PRINT "X,Y OF POINT";I;
110 INPUT X,Y
118 REM - LINES 120-200 POPULATE MATRICES WITH
119 REM - A SYSTEM OF EQUATIONS
120 FOR J=2 TO 2*D+1
130 A(J)=A(J)+X[(J-1)
140 NEXT J
150 FOR K=1 TO D+1
160 R(K,D+2)=T(K)+Y*X[(K-1)
170 T(K)=T(K)+Y*X[(K-1)
180 NEXT K
190 T(D+2)=T(D+2)+Y[2
200 NEXT I
209 REM - LINES 210-490 SOLVE THE SYSTEM OF EQUATIONS IN THE MATRICES
210 FOR J=1 TO D+1
220 FOR K=1 TO D+1
230 R(J,K)=A(J+K-1)
240 NEXT K
250 NEXT J
260 FOR J=1 TO D+1
270 FOR K=J TO D+1
280 IF R(K,J)<>0 THEN 320
290 NEXT K
300 PRINT "NO UNIQUE SOLUTION"
310 GOTO 790
320 FOR I=1 TO D+2
330 S=R(J,I)
340 R(J,I)=R(K,I)
350 R(K,I)=S
360 NEXT I
370 Z=1/R(J,J)
380 FOR I=1 TO D+2
390 R(J,I)=Z*R(J,I)
400 NEXT I
410 FOR K=1 TO D+1
420 IF K=J THEN 470
430 Z=-R(K,J)
440 FOR I=1 TO D+2
450 R(K,I)=R(K,I)+Z*R(J,I)
460 NEXT I
470 NEXT K
480 NEXT J
490 PRINT
495 PRINT "              CONSTANT =";R(1,D+2)
499 REM - PRINT EQUATION COEFFICIENTS
500 FOR J=1 TO D
510 PRINT J;"DEGREE COEFFICIENT =";R(J+1,D+2)
520 NEXT J
530 PRINT
539 REM - COMPUTE REGRESSION ANALYSIS
540 P=0
550 FOR J=2 TO D+1
560 P=P+R(J,D+2)*(T(J)-A(J)*T(1)/N)
570 NEXT J
580 Q=T(D+2)-T(1)[2/N
590 Z=Q-P
600 I=N-D-1
610 J=P/D
620 PRINT
630 J=P/Q
640 PRINT "COEFFICIENT OF DETERMINATION (R[2) =";J
650 PRINT "COEFFICIENT OF CORRELATION =";SQR(J)
660 PRINT "STANDARD ERROR OF ESTIMATE =";SQR(Z/I)
670 PRINT
679 REM - COMPUTE Y-COORDINATE FROM ENTERED X -COORDINATE
680 PRINT "INTERPOLATION:(ENTER 0 TO END PROGRAM)"
690 P=R(1,D+2)
700 PRINT "X =";
710 INPUT X
720 IF X=0 THEN 790
730 FOR J=1 TO D
740 P=P+R(J+1,D+2)*X[J
750 NEXT J
760 PRINT "y =";P
770 PRINT
780 GOTO 690
790 END
