Trailing-Edge
-
PDP-10 Archives
-
decus_20tap1_198111
-
decus/20-0020/linfit.sta
There are 2 other files named linfit.sta in the archive. Click here to see a list.
100' NAME--LINFIT
110'
120' DESCRIPTION--COMPUTES THE BEST LINEAR FIT FOR A SET OF
130' INDEPENDENT VARIABLES TO A DEPENDENT VARIABLE. ALSO,
140' CALCULATES THE CORRELATIONS BETWEEN THE INDEPENDENT VARIABLES
150' AND THE DEPENDENT VARIABLE. X(1),.....,X(N) ARE THE INDEPENDENT
160' VARIABLES AND Y IS THE DEPENDENT VARIABLE. THE PROGRAM
170' PRINTS OUT:
190' CORRELATIONS OF EACH X TO Y
200' COEFFICIENTS OF X'S IN BEST LINEAR FIT OF Y
210' CONSTANT TERM IN BEST LINEAR FIT
220'
230' SOURCE--UNKNOWN
240'
250' INSTRUCTIONS--PLACE DATA IN LINE 900 AND FOLLOWING.
260' FIRST DATA IS N, THE NUMBER OF INDEPENDENT VARIABLES. THEN
270' ENTER THE DATA BY SETS OF X(1),....X(N),Y.
280' SAMPLE DATA IS IN LINES 900 THROUGH 920.
290' IF THERE ARE MORE THAN 20 INDEPENDENT VARIABLES, THE DIM STATEMENTS
300' IN LINE 360 MUST BE CHANGED.
310'
320'
330' * * * * * * MAIN PROGRAM * * * * * * * * *
340'
350'
360 DIM P(22,22),Q(22,22),X(22)
370 READ N
380 MAT X = CON(N+2)
390 MAT P = ZER(N+2,N+2)
400 DEF FNR(Z) = INT(Z*1E3+.5)/1E3
410 READ X
420 IF X = -1E9 THEN 530
430 LET X(2) = X
440 FOR I = 3 TO N+2
450 READ X(I)
460 NEXT I
470 FOR I = 1 TO N+2
480 FOR J = I TO N+2
490 LET P(I,J) = P(I,J) + X(I)*X(J)
500 NEXT J
510 NEXT I
520 GOTO 410
530 FOR I = 1 TO N+1
540 FOR J = I+1 TO N+2
550 LET P(J,I) = P(I,J)
560 NEXT J
570 NEXT I
580 LET M = P(1,1)
590 LET S2 = P(1,N+2)
600 LET S5 = P(N+2,N+2)
610 FOR I = 2 TO N+1
620 PRINT "FACTOR" I-1, "CORRELATION =";
630 LET S1 = P(1,I)
640 LET S3 = P(I,N+2)
650 LET S4 = P(I,I)
660 LET A = M*S3-S1*S2
670 LET B = (M*S4-S1^2)*(M*S5-S2^2)
680 PRINT FNR(A/SQR(B))
690 NEXT I
700 PRINT
710 MAT Q = INV(P)
720 LET S = -1/Q(N+2,N+2)
730 PRINT "COEFFICIENTS OF BEST LINEAR FIT:"
740 PRINT
750 FOR I = 2 TO N+1
760 PRINT FNR(Q(I,N+2)*S),
770 NEXT I
780 PRINT
790 PRINT "CONSTANT TERM =" FNR(Q(1,N+2)*S)
800 PRINT
810 LET D = S5 - S2^2/M
820 PRINT "CORRELATION =" FNR(SQR(1+S/D))
900 DATA 1
910 DATA 2,86,3,95,4,94,5,75,6,102,7,164,8,135,9,135
9980 DATA -1E9
9990 END