10 '     MULTREG                   10/23/83
15 ' COPYRIGHT (c) 1983 BY GREGORY C. DAHL
17 '    * *  ALL RIGHTS RESERVED  * * *
20 ' THIS PROGRAM RUNS A MULTIPLE REGRESSION
200 '
210 ' DETAILED INSTRUCTIONS ARE GIVEN IN MULTREG.DOC
220 '
230 COMP =  0 ' FLAG FOR COMPILED VERSION
240 IF COMP THEN N=350 ELSE N= 80 ' BLINK SPEED
245 WIDTH 52
250 PRINT CHR$(&H1A);
260 PRINT TAB(16)"MULTREG (ver. 1.0)":PRINT
270 PRINT TAB(7)"COPYRIGHT (C) 1983 BY GREGORY C. DAHL
280 IF COMP THEN PRINT TAB(6)CHR$(&H1B)CHR$(&H29)"PORTIONS COPYRIGHTED BY MICROSOFT, 1981"CHR$(&H1B)CHR$(&H28) ELSE PRINT
290 PRINT" This program is "CHR$(&H1B)CHR$(&H6C)"USER SUPPORTED SOFTWARE."CHR$(&H1B)CHR$(&H6D)"  If you
300 PRINT" find it useful and wish to encourage the develop-
310 PRINT" ment of new programs, you are invited to send a
320 PRINT" contribution to the author:
330 PRINT TAB(17) "Gregory C. Dahl
340 PRINT TAB(17)"4050 Arroyo Trail
350 PRINT TAB(17)"Carmel, CA  93923
360 PRINT" All contributors sending $10 or more will receive 
370 PRINT" a diskette with the latest version of this program 
380 PRINT" and its documentation, as well as other programs 
390 PRINT" by the same author.  Contribute as much as you feel
400 PRINT" the program is worth to you, and send your comments
410 PRINT" too!  Be sure to specify double or single density
420 PRINT" and the name of the program you want.
430 PRINT CHR$(&H1B)CHR$(&H29)"      (Offer subject to change without notice)" CHR$(&H1B)CHR$(&H28)
440 PRINT" This program is copyrighted and may not be sold 
450 PRINT" for profit without written permission from the
460 PRINT" author.  However, free copies may be made and 
470 PRINT" distributed without limitation.  Pass it around!
480 PRINT "           Press any key to continue...";
490 FOR I=1 TO N:A$=INKEY$:IF A$<>""THEN 530 ELSE NEXT I
500 PRINT CHR$(13)"                                       "CHR$(13);
510 FOR I=1 TO N:A$=INKEY$:IF A$<>""THEN 530 ELSE NEXT I
520 GOTO 480
530 '
600 SC% = 51 'SCREEN DISPLAY WIDTH
610 F1$="######.##" 'FORMAT FOR DISPLAYING DATA ON SCREEN
630 PRINT CHR$(&H1A):PRINT:PRINT:A$="MULTREG":GOSUB 710
640 PRINT:PRINT:A$="Version 1.0":GOSUB 710
650 PRINT:PRINT:PRINT:A$="COPYRIGHT (c) 1983 BY GREGORY C. DAHL":GOSUB 710
660 PRINT:A$="* *   All rights reserved   * *":GOSUB 710
670 DEFDBL A-D,F-H,O-Y : DEFINT I-N 'SET MOST VARIABLES DOUBLE-PRECISION
680 WIDTH SC%'SETS SCREEN DISPLAY WIDTH
690 GOTO 1000
700 '

	DISPLAY LINE, CENTERED


710 PRINT TAB((SC%-LEN(A$))/2) A$:RETURN
720 '


	ENTER DATA (AND TRANSFORMATIONS, IF ANY)



1000 N=13  'PUT NUMBER OF OBSERVATIONS HERE * * * * *
1010 V=3   'PUT NUMBER OF INDEPENDENT VARIABLES HERE * * * * *
1020 HEAD$ = " * * PUT THE DATE & A DESCRIPTIVE HEADING HERE * *" ' * * * * *
1030      M=V+1:DIM X(N,M), Y(N), XX(M,M), XXINV(M,M), A(M,M)
1040 ' X IS MATRIX OF DATA, ROWS ARE OBSERVATIONS
1050 '     COL 1 = 1'S, COLS 2 TO V+1 ARE INDEP. VBLES
1060 ' Y IS VECTOR OF DEPENDENT VBLE OBSERVATIONS
1070 ' (XX IS X'X, AND XXINV IS (X'X) INVERSE.  A IS A TEMPORARY WORKING MATRIX)
1080 '

	NOTE: EACH VARIABLE SHOULD BE MULTIPLIED
1090 '	BY A SCALE FACTOR SO THAT ALL OBSERVATIONS
1100 '	FALL AS CLOSE AS POSSIBLE TO A RANGE OF
1110 '	0.1 TO 1000.0.  RESULTS ARE NOT AFFECTED.
1120 '

	ENTER DEPENDENT VARIABLE OBSERVATIONS IN
1130 '   DATA STATEMENTS FOLLOWING, SEPARATED
1140 '	BY COMMAS.  (REPLACE EXISTING DATA
1150 '	STATEMENTS.)  NUMBER OF OBSERVATIONS
1160 '	MUST EQUAL N (SEE LINE 100).
2000 '


	THE FOLLOWING ARE SAMPLE DATA.  YOU MUST


	PUT IN YOUR OWN.



2010 PRINT:PRINT:PRINT:PRINT:PRINT:A$="DEMO DATA ARE BEING LOADED....":GOSUB 710
2020 N1=N+1
2030 DIM VR(N1),VP(N1),VC(N1),VM(N1)
2040 DATA -14687.8,2565.5,48176.6,101613.8,96592.6,-2846.7,-118305.9,-24782.4,43177.9,114296.4,195168.7,147224.9,-10140.8,-32931.3
2050 FOR I=1 TO N1: READ VR(I) : NEXT I
2060 DATA 50,51,53,56,67,77,91,100,107,104,114,132,156,172
2070 FOR I=1 TO N1: READ VP(I) : NEXT I
2080 DATA 218.028,236.846,258.5162,284.8869,387.8018,604.6273,832.7179,984.9344,1192.7398,1483.1753,1757.7751,2096.6606,2513.4998,2774.1448
2090 FOR I=1 TO N1: READ VC(I) : NEXT I
2100 DATA 203.3402,239.4115,306.6958,386.5007,484.3944,601.7806,714.412,960.152,1235.9167,1597.4717,1952.9438,2243.8855,2503.359,2741.2135
2110 FOR I=1 TO N1: READ VM(I) : NEXT I
2120 FOR I=1 TO N
2130   X(I,1)=1
2140   Y(I)=(VR(I+1)-VR(I))/VM(I) 'INDEP. VBLE = CHANGE R/M(T-1)
2150   X(I,2)=1000*(VP(I+1)-VP(I))/VP(I) 'PRICE CHANGE PER CENT
2160   X(I,3)=1000*(VM(I+1)/VP(I+1)-VM(I)/VP(I))*VP(I)/VM(I) 'REAL MONEY CHANGE PER CENT
2170   X(I,4)=1000*(VC(I+1)-VC(I))/VM(I) 'CREDIT CHANGE OVER MONEY
2180 NEXT I
2190 GOTO 4540
2200 ' 


	END OF DEMO DATA




2800 FOR I=1 TO N:READ Y(I):NEXT I 'THIS STATEMENT LOADS YOUR DATA INTO VECTOR Y
2810 '

	ENTER INDEPENDENT VARIABLE OBSERVATIONS IN
2820 '	DATA STATEMENTS FOLLOWING: FIRST ALL N
2830 '   OBSERVATIONS OF FIRST VARIABLE, THEN ALL
2840 '	N OBSERVATIONS OF SECOND VARIABLE, ETC.
2850 '	THERE MUST BE V VARIABLES ALL TOGETHER
2860 '	(SEE LINES 1000 AND 1010 ABOVE).
2870 '
2880 '
4500  FOR J = 2 TO M : FOR I = 1 TO N : READ X(I,J) : NEXT I,J 'THIS STATEMENT LOADS YOUR DATA
4510 '  INTO MATRIX OF INDEP. VARIABLES, X
4520  FOR I = 1 TO N : X(I,1) = 1 : NEXT I 'LOADS COLUMN OF ONE'S FOR INTERCEPT TERM
4530 '

	DISPLAY INPUT DATA


4540 PRINT CHR$(&H1A):A$=HEAD$:GOSUB 710
4550 HEAD1$="* * * *  INPUT DATA  * * * *":A$=HEAD1$:GOSUB 710
4560 I=(LEN(F1$)-8)/2:IF I<0 THEN I=0
4570 PRINT"

OBS#  "SPACE$(I)"DEP. VBLE"SPACE$(I+2);
4580 IF SC%-POS(1)-1>LEN(F1$) THEN PRINT"INDEP. VARIABLES:" ELSE PRINT
4590 F$="###.  "+F1$+" "
4600 K=INT((SC%-7)/LEN(F1$)): IF K>M THEN K=M 'NUMBER OF INDEP. VARIABLES THAT CAN BE DISPLAYED ON SCREEN
4610 FOR I=1 TO N
4620   PRINT USING F$;I,Y(I);
4630   FOR J=2 TO K : PRINT USING F1$;X(I,J);
4640   NEXT J:PRINT:NEXT I:GOSUB 6640
4650 IF K=M THEN 4740 'ALL INPUT DATA DISPLAYED
4660 L=INT((SC%-6)/LEN(F1$)):K2=K
4670 K1=K2+1:K2=K1+L-1:IF K2>M THEN K2=M
4680 PRINT CHR$(&H1A):A$=HEAD$:GOSUB 710:A$=HEAD1$:GOSUB 710:PRINT:PRINT"INDEP. VARIABLES, CONTINUED:":PRINT
4690 FOR I=1 TO N:PRINT USING "###.  ";I;
4700 FOR J=K1 TO K2:PRINT USING F1$;X(I,J);
4710 NEXT J:PRINT:NEXT I:GOSUB 6640
4720 IF K2<M THEN 4670
4730 '


	INVERT MATRIX X'X (ANSWER IS XXINV)


4740 PRINT "

	INVERTING MATRIX.  PLEASE BE PATIENT....
4750 FOR I=1 TO M : FOR J=1 TO M : XX(I,J)=0
4760 FOR K=1 TO N : XX(I,J)=XX(I,J)+X(K,I)*X(K,J)
4770 NEXT K,J,I
4780 FOR J=1 TO M: XXINV(J,J)=1 : NEXT J
4790 FOR I=1 TO M:FOR J=1 TO M:A(I,J)=XX(I,J):NEXT J,I 'MATRIX TO INVERT
4800 FOR J=1 TO M:FOR I=J TO M
4810 IF A(I,J)<>0 THEN 4830
4820 NEXT I : PRINT "SINGULAR MATRIX.  STOPPING":STOP
4830 FOR K=1 TO M
4840 S=A(J,K) : A(J,K)=A(I,K) : A(I,K)=S
4850 S=XXINV(J,K) : XXINV(J,K)=XXINV(I,K) : XXINV(I,K)=S
4860 NEXT K
4870 T=1/A(J,J)
4880 FOR K=1 TO M : A(J,K)=T*A(J,K) : XXINV(J,K)=T*XXINV(J,K)
4890 NEXT K
4900 FOR L=1 TO M : IF L=J THEN 4960
4910 T=-A(L,J)
4920 FOR K=1 TO M
4930 A(L,K)=A(L,K)+T*A(J,K)
4940 XXINV(L,K)=XXINV(L,K)+T*XXINV(J,K)
4950 NEXT K
4960 NEXT L,J
4970 GOTO 5110 ' * * * * *
4980 '

	TEST INVERSE


4990 PRINT "TEST.  SHOULD BE IDENTITY MATRIX I:
5000 FOR I=1 TO M
5010 FOR J=1 TO M
5020 S=0
5030 FOR K=1 TO M
5040 S=S+XX(I,K)*XXINV(K,J)
5050 NEXT K
5060 PRINT USING "#####.###############";S;
5070 NEXT J
5080 PRINT
5090 NEXT I
5100 '

	COMPUTE ESTIMATED COEFFICIENTS BETA


5110 DIM BETA(M),C(M),EST(N),ER(N),T(M)
5120 FOR I=1 TO M : C(I)=0
5130 FOR J=1 TO N : C(I)=C(I)+X(J,I)*Y(J)
5140 NEXT J,I
5150 FOR I=1 TO M : BETA(I)=0
5160 FOR J=1 TO M : BETA(I)=BETA(I)+XXINV(I,J)*C(J)
5170 NEXT J,I
5180 '

	COMPUTE OTHER STATISTICS


5190 ' S = Y'Y
5200 ' W = (SUM Y)^2 / N
5210 W=0:FOR I=1 TO N:W=W+Y(I):NEXT I
5220 W=W*W/N
5230 RSQR=0:S=0
5240 FOR I=1 TO M:RSQR=RSQR+BETA(I)*C(I):NEXT I
5250 FOR I=1 TO N:S=S+Y(I)*Y(I):NEXT I
5260 RSQR=(RSQR-W)/(S-W)
5270 F = RSQR * (N-M) / ((1 - RSQR)*(M-1))
5280 ' F DEGREES OF FREEDOM: M-1, N-M
5290 EMIN=1.7E+37 : EMAX = -EMIN 'INITIAL VALUES
5300 ERSQR = 0
5310 FOR I=1 TO N
5320 EST(I)=0
5330 FOR J=1 TO M
5340 EST(I)=EST(I)+BETA(J)*X(I,J)
5350 NEXT J
5360 ER(I)=Y(I)-EST(I)
5370 ERSQR = ERSQR+ ER(I)*ER(I)
5380 IF ER(I)>EMAX THEN EMAX=ER(I)
5390 IF ER(I)<EMIN THEN EMIN=ER(I)
5400 NEXT I
5410 IF ABS(EMIN)>EMAX THEN EMAX=ABS(EMIN) ELSE EMIN=-EMAX ' MAKE ERROR LIMITS SYMMETRICAL FOR GRAPHING
5420 U = SQR(ERSQR/(N-M))
5430 FOR I=1 TO M: T(I) = BETA(I)/(U * SQR(XXINV(I,I))) : NEXT I
5440 ' T HAS N-M DEGREES OF FREEDOM
5450 DW=0: FOR I=2 TO N:DW=DW+(ER(I)-ER(I-1))*(ER(I)-ER(I-1)):NEXT I
5460 DW=DW/ERSQR 'DURBAN-WATSON STATISTIC
5470 '

	DISPLAY RESULTS ON SCREEN


5480 PRINT CHR$(&H1A):PRINT HEAD$:PRINT
5490 PRINT "

ESTIMATED COEFFICIENTS:


5500 PRINT SPACE$(28) "t STATISTIC"
5510 F3$ = "  #######.###" 'FORMAT FOR t STATISTIC
5520 FOR I=0 TO M-1
5530 IF I=0 THEN PRINT "INTERCEPT:  "; ELSE PRINT "COEFF #"I": ";
5540 IF ABS(BETA(I+1))>100000! OR ABS(BETA(I+1))<.001 THEN F$="#.######^^^^" ELSE F$="######.#####"
5550 PRINT USING F$;BETA(I+1);:PRINT USING F3$;T(I+1)
5560 NEXT I
5570 Z=RSQR:PRINT "

R SQUARED:                "Z
5580 Z=F:PRINT "

F STATISTIC:              "Z
5590 PRINT USING "(degrees of freedom: ##_,###)";M-1,N-M
5600 Z=DW:PRINT "

DURBAN-WATSON STATISTIC:  "Z
5610 PRINT USING "

(t degrees of freedom: ###)";N-M
5620 '

	DISPLAY ERRORS


5630 MASK$="*          |          *"
5640 F$="###. #########.## #########.## #########.##"
5650 PRINT:GOSUB 6640
5660 PRINT CHR$(&H1A):A$=HEAD$:GOSUB 710:A$="* *  ERRORS  * *":GOSUB 710:PRINT:PRINT "OBS#     OBSERVED     ESTIMATED       ERROR":PRINT
5670 FOR I=1 TO N:PRINT USING F$;I,Y(I),EST(I),ER(I):NEXT I
5680 PRINT:GOSUB 6640 'PRESS RETURN TO CONTINUE
5690 PRINT CHR$(&H1A):PRINT HEAD$:PRINT:PRINT "ERROR PATTERN:":PRINT
5700 M1$=STR$(CSNG(EMIN)):M2$=STR$(CSNG(EMAX)):L=LEN(M1$)+LEN(M2$):L=L/2:IF L<LEN(MASK$) THEN L=LEN(MASK$)-L ELSE L=2
5710 M1$=SPACE$(10-LEN(M1$)/2)+M1$+SPACE$(L)+M2$:PRINT M1$ 'MIN AND MAX VALUES
5720 PRINT TAB(11) STRING$(LEN(MASK$),"*")
5730 FOR I=1 TO N
5740 M$=MASK$:MID$(M$,CINT((ER(I)-EMIN)*(LEN(MASK$)-3)/(EMAX-EMIN))+2,1)="+"
5750 PRINT TAB(11) M$
5760 NEXT I
5770 PRINT TAB(11) STRING$(LEN(MASK$),"*")
5780 PRINT M1$
5790 GOSUB 6640
5990 ' 


	PRINT RESULTS TO PRINTER




6000 WID% = 80 'PRINTER WIDTH IN CHARACTERS
6010 INIT$ = "" 'INITIALIZATION STRING TO SEND TO PRINTER 
6020 F1$ = "########.#####" 'FORMAT FOR PRINTING DATA
6030 FF$=CHR$(&HC) 'FORM FEED
6040 PRINT CHR$(&H1A):PRINT:PRINT:A$="YOU CAN NOW SEND DATA AND RESULTS":GOSUB 710:A$="TO THE PRINTER":GOSUB 710:PRINT:PRINT:A$="INPUT DATA":GOSUB 6680
6050 IF FLAG THEN 6280
6060 GOSUB 6760 'ASK FOR FORM FEED 
6070 '

	PRINT INPUT DATA


6080 A$=HEAD$:GOSUB 6740:A$="* * * *  INPUT DATA  * * * *":GOSUB 6740
6090 I=(LEN(F1$)-8)/2:IF I<0 THEN I=0
6100 LPRINT"

OBS#  "SPACE$(I)"DEP. VBLE"SPACE$(I+2);
6110 IF WID%-LPOS(1)-1>LEN(F1$) THEN LPRINT"INDEP. VARIABLES:" ELSE LPRINT
6120 F$="###.  "+F1$+" "
6130 K=INT((WID%-7)/LEN(F1$)): IF K>M THEN K=M 'NUMBER OF INDEP. VARIABLES THAT CAN BE DISPLAYED ON SCREEN
6140 FOR I=1 TO N
6150   LPRINT USING F$;I,Y(I);
6160   FOR J=2 TO K : LPRINT USING F1$;X(I,J);
6170   NEXT J:LPRINT:NEXT I
6180 IF K=M THEN 6280 'ALL INPUT DATA DISPLAYED
6190 L=INT((WID%-6)/LEN(F1$)):K2=K
6200 K1=K2+1:K2=K1+L-1:IF K2>M THEN K2=M
6210 GOSUB 6760:IF FLAG THEN A$=HEAD$:GOSUB 6740:A$=HEAD1$:GOSUB 6740
6220 LPRINT:LPRINT"INDEP. VARIABLES, CONTINUED:":LPRINT
6230 FOR I=1 TO N:LPRINT USING "###.  ";I;
6240 FOR J=K1 TO K2:LPRINT USING F1$;X(I,J);
6250 NEXT J:LPRINT:NEXT I
6260 IF K2<M THEN 6200
6270 '

	PRINT EST. COEFFICIENTS, ETC.


6280 A$="EST. COEFFS. AND STAT.":GOSUB 6680
6290 IF FLAG THEN 6450
6300 GOSUB 6760:IF FLAG THEN A$=HEAD$:GOSUB 6740
6310 LPRINT "



	ESTIMATED COEFFICIENTS:":LPRINT:LPRINT
6320 LPRINT SPACE$(28) "t STATISTIC"
6330 F3$ = "  #######.###" 'FORMAT FOR t STATISTIC
6340 FOR I=0 TO M-1
6350 IF I=0 THEN LPRINT "INTERCEPT:  "; ELSE LPRINT "COEFF #"I": ";
6360 IF ABS(BETA(I+1))>100000! OR ABS(BETA(I+1))<.001 THEN F$="#.######^^^^" ELSE F$="######.#####"
6370 LPRINT USING F$;BETA(I+1);:LPRINT USING F3$;T(I+1)
6380 NEXT I
6390 Z=RSQR:LPRINT "

R SQUARED:                "Z
6400 Z=F:LPRINT "

F STATISTIC:              "Z
6410 LPRINT USING "(degrees of freedom: ##_,###)";M-1,N-M
6420 Z=DW:LPRINT"

DURBAN-WATSON STATISTIC:  "Z
6430 LPRINT USING "

(t degrees of freedom: ###)";N-M
6440 '

	PRINT ERRORS


6450 A$="ERRORS":GOSUB 6680
6460 IF FLAG THEN 6620
6470 GOSUB 6760
6480 MASK$="*          |          *"
6490 F$="###. #########.## #########.## #########.##"
6500 IF FLAG THEN A$=HEAD$:GOSUB 6740:A$=" * * *   ERRORS   * * *":GOSUB 6740
6510 M1$=STR$(CSNG(EMIN)):M2$=STR$(CSNG(EMAX)):L=LEN(M1$)+LEN(M2$):L=L/2:IF L<LEN(MASK$) THEN L=LEN(MASK$)-L ELSE L=2
6520 M1$=SPACE$(10-LEN(M1$)/2)+M1$+SPACE$(L)+M2$ 'MIN AND MAX VALUES
6530 LPRINT "


OBS#     OBSERVED     ESTIMATED       ERROR        ERROR PATTERN":LPRINT
6540 LPRINT:LPRINT SPACE$(LEN(F$)-3) M1$  
6550 LPRINT SPACE$(LEN(F$)+8) STRING$(LEN(MASK$),"*")
6560 FOR I=1 TO N
6570 M$=MASK$:MID$(M$,CINT((ER(I)-EMIN)*(LEN(MASK$)-3)/(EMAX-EMIN))+2,1)="+"
6580 LPRINT USING F$;I,Y(I),EST(I),ER(I);:LPRINT SPACE$(8) M$
6590 NEXT I
6600 LPRINT SPACE$(LEN(F$)+8) STRING$(LEN(MASK$),"*")
6610 LPRINT SPACE$(LEN(F$)-3) M1$
6620 GOTO 8000
6630 '

	PRESS ENTER TO CONTINUE


6640 PRINT "PRESS ENTER TO CONTINUE... ";
6650 A$=INKEY$:IF A$="" THEN 6650
6660 PRINT:RETURN
6670 '

	ASK FOR PRINT


6680 PRINT:PRINT "PRINT "A$"?  (Y/N)  ";
6690 A$=INKEY$:IF A$="" THEN 6690
6700 IF A$="Y" OR A$="y" THEN FLAG=0 ELSE FLAG=-1:A$="N"
6710 IF NOT FLAG AND NOT FLAG2 THEN LPRINT INIT$;:FLAG2=-1 'PRINT INITIALIZATION STRING ONCE
6720 PRINT A$:RETURN 
6730 '

	PRINT LINE, CENTERED


6740 LPRINT SPACE$((WID%-LEN(A$))/2) A$:RETURN
6750 '

	SEND FORM FEED


6760 PRINT "SEND A FORM FEED?  (Y/N)  ";
6770 A$=INKEY$:IF A$="" THEN 6770
6780 FLAG=-1
6790 IF A$="Y" OR A$="y" THEN LPRINT FF$; ELSE A$="N":FLAG=0
6800 PRINT A$:RETURN
7990 ' 


	SEND RESULTS TO DISK FILE



8000 WID% = 80 'LINE LENGTH IN CHARACTERS
8010 INIT$ = "" 'INITIALIZATION STRING, IF ANY
8020 F1$ = "########.#####" 'FORMAT FOR DATA OUTPUT
8030 FF$="" 'FORM FEED
8040 PRINT CHR$(&H1A):PRINT:PRINT:A$="YOU CAN NOW SEND DATA AND RESULTS":GOSUB 710:A$="TO A DISK FILE":GOSUB 710
8050 PRINT:PRINT:PRINT"ENTER A FILE NAME OR PRESS RETURN":PRINT:PRINT:INPUT "    TO END THE PROGRAM   ", F$
8060 IF F$="" THEN STOP ELSE OPEN "O",#1,F$
8070 PRINT:PRINT:A$="THE INPUT DATA":GOSUB 8690
8080 IF FLAG THEN 8300
8090 '

	PRINT INPUT DATA


8100 A$=HEAD$:GOSUB 8750:A$="* * * *  INPUT DATA  * * * *":GOSUB 8750
8110 I=(LEN(F1$)-8)/2:IF I<0 THEN I=0
8120 PRINT#1,"

OBS#  "SPACE$(I)"DEP. VBLE"SPACE$(I+2);
8130 IF WID%-LPOS(1)-1>LEN(F1$) THEN PRINT#1,"INDEP. VARIABLES:" ELSE PRINT#1
8140 F$="###.  "+F1$+" "
8150 K=INT((WID%-7)/LEN(F1$)): IF K>M THEN K=M 'NUMBER OF INDEP. VARIABLES THAT CAN BE DISPLAYED ON SCREEN
8160 FOR I=1 TO N
8170   PRINT#1, USING F$;I,Y(I);
8180   FOR J=2 TO K : PRINT#1, USING F1$;X(I,J);
8190   NEXT J:PRINT#1,:NEXT I
8200 IF K=M THEN 8300 'ALL INPUT DATA DISPLAYED
8210 L=INT((WID%-6)/LEN(F1$)):K2=K
8220 K1=K2+1:K2=K1+L-1:IF K2>M THEN K2=M
8230 IF FLAG THEN A$=HEAD$:GOSUB 8750:A$=HEAD1$:GOSUB 8750
8240 PRINT#1:PRINT#1,"INDEP. VARIABLES, CONTINUED:":PRINT#1
8250 FOR I=1 TO N:PRINT#1, USING "###.  ";I;
8260 FOR J=K1 TO K2:PRINT#1, USING F1$;X(I,J);
8270 NEXT J:PRINT#1:NEXT I
8280 IF K2<M THEN 8220
8290 '

	PRINT EST. COEFFICIENTS, ETC.


8300 A$="EST. COEFFS. AND STAT.":GOSUB 8690
8310 IF FLAG THEN 8470
8320 IF FLAG THEN A$=HEAD$:GOSUB 8750
8330 PRINT#1,:PRINT#1,:PRINT#1,:PRINT#1, "	ESTIMATED COEFFICIENTS:":PRINT#1,:PRINT#1,
8340 PRINT#1, SPACE$(28) "t STATISTIC"
8350 F3$ = "  #######.###" 'FORMAT FOR t STATISTIC
8360 FOR I=0 TO M-1
8370 IF I=0 THEN PRINT#1, "INTERCEPT:  "; ELSE PRINT#1, "COEFF #"I": ";
8380 IF ABS(BETA(I+1))>100000! OR ABS(BETA(I+1))<.001 THEN F$="#.######^^^^" ELSE F$="######.#####"
8390 PRINT#1, USING F$;BETA(I+1);:PRINT#1, USING F3$;T(I+1)
8400 NEXT I
8410 Z=RSQR:PRINT#1, "

R SQUARED:                "Z
8420 Z=F:PRINT#1, "

F STATISTIC:              "Z
8430 PRINT#1, USING "(degrees of freedom: ##_,###)";M-1,N-M
8440 Z=DW:PRINT#1,"

DURBAN-WATSON STATISTIC:  "Z
8450 PRINT#1, USING "

(t degrees of freedom: ###)";N-M
8460 '

	PRINT ERRORS


8470 A$="ERRORS":GOSUB 8690
8480 IF FLAG THEN 8630
8490 MASK$="*          |          *"
8500 F$="###. #########.## #########.## #########.##"
8510 IF FLAG THEN A$=HEAD$:GOSUB 8750:A$=" * * *   ERRORS   * * *":GOSUB 8750
8520 M1$=STR$(CSNG(EMIN)):M2$=STR$(CSNG(EMAX)):L=LEN(M1$)+LEN(M2$):L=L/2:IF L<LEN(MASK$) THEN L=LEN(MASK$)-L ELSE L=2
8530 M1$=SPACE$(10-LEN(M1$)/2)+M1$+SPACE$(L)+M2$ 'MIN AND MAX VALUES
8540 PRINT#1,:PRINT#1,:PRINT#1, "OBS#     OBSERVED     ESTIMATED       ERROR        ERROR PATTERN":PRINT#1,
8550 PRINT#1,:PRINT#1, SPACE$(LEN(F$)-3) M1$  
8560 PRINT#1, SPACE$(LEN(F$)+8) STRING$(LEN(MASK$),"*")
8570 FOR I=1 TO N
8580 M$=MASK$:MID$(M$,CINT((ER(I)-EMIN)*(LEN(MASK$)-3)/(EMAX-EMIN))+2,1)="+"
8590 PRINT#1, USING F$;I,Y(I),EST(I),ER(I);:PRINT#1, SPACE$(8) M$
8600 NEXT I
8610 PRINT#1, SPACE$(LEN(F$)+8) STRING$(LEN(MASK$),"*")
8620 PRINT#1, SPACE$(LEN(F$)-3) M1$
8630 PRINT:PRINT:A$="* * *  END OF PROGRAM  * * *":GOSUB 710:PRINT:PRINT:CLOSE:STOP 'END OF PROGRAM
8640 '

	PRESS ENTER TO CONTINUE


8650 PRINT "PRESS ENTER TO CONTINUE... ";
8660 A$=INKEY$:IF A$="" THEN 8660
8670 PRINT:RETURN
8680 '

	ASK FOR OUTPUT


8690 PRINT:PRINT "OUTPUT "A$"?  (Y/N)  ";
8700 A$=INKEY$:IF A$="" THEN 8700
8710 IF A$="Y" OR A$="y" THEN FLAG=0 ELSE FLAG=-1:A$="N"
8720 IF NOT FLAG AND NOT FLAG2 THEN PRINT#1, INIT$;:FLAG2=-1 'PRINT INITIALIZATION STRING ONCE
8730 PRINT A$:RETURN 
8740 '

	PRINT LINE, CENTERED


8750 PRINT#1, SPACE$((WID%-LEN(A$))/2) A$:RETURN
IZATION STRING ONCE
8730 PRINT A$:RETURN 
8740 '

	PRINT LINE, CENTERE