home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
RBBS in a Box Volume 1 #3.1
/
RBBSIABOX31.cdr
/
mlpc
/
mlinreg.bas
< prev
next >
Wrap
BASIC Source File
|
1990-09-29
|
4KB
|
67 lines
10 CLS:PRINT TAB(27)"MULTIPLE LINEAR REGRESSION"
20 KEY OFF:PRINT:PRINT
30 PRINT"This program determines the degree of relationship between a"
40 PRINT"collection of variables on an individual. The program gives"
50 PRINT"you the ability to predict an outcome based on a number of"
60 PRINT"different variables. The value we are interested in later"
70 PRINT"predicting is the dependent variable.":PRINT
80 PRINT"TO CORRECT ERROR IN PREVIOUS SAMPLE, USE ^C THEN GOTO 400"
90 PRINT
100 PRINT"TO CORRECT ERRORS IN CURRENT SAMPLE, USE ^C THEN GOTO 200
110 PRINT:PRINT:PRINT
112 INPUT"Title of regression analysis: ";T$:PRINT
115 INPUT"Number of observations: ";N:PRINT
120 INPUT"Number of independent variables: ";V
122 X=INT(FRE(0)/422-V*.5+12):IF (N-V-1)=0 THEN GOTO 500
124 IF N>X THEN PRINT"There is ONLY memory for ";X;" observations":PRINT:GOTO 115
126 DIM B(N+V),C(N+V),D(N+V),N$(N+V),A(N+V,N+V):CLS:N$(0)=T$
140 FOR X=1 TO V:PRINT"Name of independent variable (";X;")";
145 INPUT N$(X):NEXT X
150 INPUT"Name of dependent variable: ";N$(X+1)
160 B(1)=1:FOR X=1 TO N:PRINT
195 ' NTR VARS
200 PRINT"SAMPLE ";X:FOR Y=1 TO V:PRINT TAB(3)N$(Y);:INPUT B(Y+1):NEXT Y:PRINT TAB(3)N$(V+2);:INPUT B(V+2)
205 ' STOR SUM OF N,X,Y,X^2,XY IN MATRIX
210 FOR A=1 TO V+1:FOR B=1 TO V+2:A(A,B)=A(A,B)+B(A)*B(B):C(A)=A(A,V+2):NEXT B:NEXT A
215 '
220 C(V+2)=C(V+2)+B(V+2)^2:NEXT X
225 CLS:PRINT"Calculating....."
230 FOR X=2 TO V+1:D(X)=A(1,X):NEXT X
235 FOR X=1 TO V+1:Y=X
240 IF A(Y,X)<>0 THEN 260
245 Y=Y+1
250 IF Y<=V+1 THEN 240
255 PRINT"***** NO CORRELATION *****":PRINT CHR$(7):CLS:END
260 FOR A=1 TO V+2:C=A(X,A):A(X,A)=A(Y,A):A(Y,A)=C:NEXT A
265 Z=1/A(X,X)
270 FOR A=1 TO V+2:A(X,A)=Z*A(X,A):NEXT A
275 FOR Y=1 TO V+1:IF Y=X THEN 290
280 Z=-A(Y,X)
285 FOR A=1 TO V+2:A(Y,A)=A(Y,A)+Z*A(X,A):NEXT A
290 NEXT Y:NEXT X:CLS:PRINT TAB((80-LEN(N$(0)))/2)N$(0):PRINT:PRINT"EQUATION COEFFICIENTS:":PRINT
300 PRINT"CONSTANT = ";A(1,V+2):PRINT:FOR X=2 TO V+1
310 PRINT"COEFFICIENT OF (";N$(X-1);") VARIABLE = ";A(X,V+2):NEXT X:E=0
320 FOR X=2 TO V+1:E=E+A(X,V+2)*(C(X)-D(X)*C(1)/N):NEXT X:F=C(V+2)-C(1)^2/N
330 Z=F-E:G=N-V-1:PRINT:X=E/F:PRINT"COEFFICIENT OF DETERMINATION = ";X
340 PRINT"COEFFICIENT OF CORRELATION = ";SQR(X)
350 PRINT"STANDARD ERROR OF ESTIMATE = ";SQR(ABS(Z/G)):PRINT
360 PRINT"INTERPOLATION: (ENTER 0 TO END) ":PRINT:PRINT N$(V+2);" = ";A(1,V+2)
370 FOR X=2 TO V+1:PRINT TAB(1+LEN(N$(V+2)))"+ ";N$(X-1);" *";A(X,V+2):NEXT X
380 PRINT:E=A(1,V+2):FOR Y=1 TO V:PRINT N$(Y);" ";:INPUT H:IF H=0 THEN CLS:END
385 E=E+A(Y+1,V+2)*H:NEXT Y
390 PRINT N$(V+2);" = ";E:PRINT:PRINT:GOTO 380
395 ' CORRECT ERRORS IN VARIABLE ENTRY
400 CLS:INPUT"SAMPLE NUMBER OF ERROR: ";H
410 PRINT:PRINT"WHAT WAS THE ERROR? (ENTER INCORRECT VALUES FOR SAMPLE ";H;" )"
420 FOR Y=1 TO V:PRINT TAB(5)N$(Y);:INPUT B(Y+1):NEXT Y:PRINT TAB(5)N$(V+2);:INPUTB(V+2)
430 FOR A=1 TO V+1:FOR B=1 TO V+2:A(A,B)=A(A,B)-B(A)*B(B):C(A)=A(A,V+2):NEXT B:NEXT A
440 C(V+2)=C(V+2)-B(V+2)^2:PRINT
450 PRINT"ENTER CORRECT VALUES FOR SAMPLE ";H:FOR Y=1 TO V
460 PRINT TAB(5)N$(Y);:INPUT B(Y+1):NEXT Y:PRINT TAB(5);N$(V+2);:INPUT B(V+2)
470 FOR A=1 TO V+1:FOR B=1 TO V+2:A(A,B)=A(A,B)+B(A)*B(B):C(A)=A(A,V+2):NEXT B:NEXT A
480 C(V+2)=C(V+2)+B(V+2)^2:X=X-1:NEXT X
490 GOTO 225
500 CLS:PRINT"To operate correctly, the number of observations must be at least"
510 PRINT"two greater than the number of independent variables!!":PRINT CHR$(7)
520 PRINT:INPUT"Press RETURN key to continue ";A$:CLS:PRINT:GOTO 115