home *** CD-ROM | disk | FTP | other *** search
-
- 20 Rem 4/21/80
- 40 Set 0,132
- 60 Integer Variables,I,J,K,L,M,N,Plot1,Plot2
- 80 Dim Title$(80),Format$(20),Command$(50)
- 100 @ : @ : @"Statistical Analysis" : @ : @
- 120 @" By"
- 140 @"David Trachtenbarg" : @
- 160 @"copyright 1980" : @ : @
- 180 Input"Do you wish to enter new data? (Y/N) ",Command$
- 200 If Command$(0,0)="Y" Then Gosub Enter'data
- 220 If Command$(0,0)="N" Then Gosub Get'data
- 240 If Command$(0,0)<>"Y" And Command$(0,0)<>"N" Then Goto 180
- 250 Gosub Plot
- 260 Gosub Mean
- 280 Gosub Standard'deviation
- 300 Gosub Correlation'matrix
- 320 Long Inverse(Variables,Variables),Determinant
- 340 Call .Inverse (Mat Correlation,Mat Inverse,Variables;Determinant)
- 360 Call .Test'inverse (Mat Correlation,Mat Inverse,Variables)
- 380 Gosub Enter'betas
- 400 Long Beta(Size)
- 420 Call .Beta'weights (Mat Correlation2,Mat Inverse2,Mat Mean2,Mat Deviation2,Size)
- 440 Goto 380
- 460 End
- 480 *Mean
- 500 Long Mean(Variables)
- 520 Mat Mean=0
- 540 @
- 560 For I=1 To N
- 580 @ Using"###. ",I;
- 600 For J=1 To Variables
- 620 @ Using" ##.## ",Results(I,J);
- 640 Mean(J)=Mean(J)+Results(I,J)
- 660 Next J
- 680 @
- 700 Next I
- 720 @ : @"MEAN ";
- 740 For I=1 To Variables
- 760 Mean(I)=Mean(I)/N
- 780 @ Using" ##.## ",Mean(I);
- 800 Next I
- 820 Return
- 840 *Standard'deviation
- 860 Long Deviation(Variables)
- 880 Mat Deviation=0
- 900 @ : @"DEV. ";
- 920 For I=1 To Variables
- 940 For J=1 To N
- 960 Deviation(I)=(Mean(I)-Results(J,I))*(Mean(I)-Results(J,I))+Deviation(I)
- 980 Next J
- 1000 Deviation(I)=Sqr(Deviation(I)/(N-1))
- 1020 @ Using" ##.## ",Deviation(I);
- 1040 Next I
- 1060 Return
- 1080 *Correlation'matrix
- 1100 Long Correlation(Variables,Variables)
- 1120 @ : @ : @"CORRELATION MATRIX" : @
- 1140 Mat Correlation=0
- 1160 For J=1 To Variables
- 1180 @ Using" ###. ",J;
- 1200 For I=1 To Variables
- 1220 For K=1 To N
- 1240 Correlation(I,J)=Correlation(I,J)+(Results(K,I)-Mean(I))*(Results(K,J)-Mean(J))
- 1260 Next K
- 1280 Correlation(I,J)=(Correlation(I,J)/(N-1))/(Deviation(I)*Deviation(J))
- 1300 @ Using"-#.### ",Correlation(I,J);
- 1320 Next I
- 1340 @
- 1360 Next J
- 1380 Return
- 1400 *Store'data
- 1420 @ : @"Storing data....." : @ : @
- 1440 On Error Goto 1480
- 1460 Erase"stat.dat"
- 1480 On Error Stop
- 1500 Create"stat.dat"
- 1520 Open\1,(Variables*8)\"stat.dat"
- 1540 Put\1,0\N,Variables
- 1560 For I=1 To N
- 1580 For J=1 To Variables
- 1600 Put\1,I,((J-1)*8)\Results(I,J)
- 1620 Next J
- 1640 Next I
- 1660 Close\1\
- 1680 Return
- 1700 *Get'data
- 1720 @ : @"Retreiving data....." : @ : @
- 1740 Open\1\"stat.dat"
- 1760 Get\1\N,Variables
- 1780 Close\1\
- 1800 Long Results(N,Variables)
- 1820 Open\1,(Variables*8)\"stat.dat"
- 1840 For I=1 To N
- 1860 For J=1 To Variables
- 1880 Get\1,I,((J-1)*8)\Results(I,J)
- 1900 Next J
- 1920 Next I
- 1940 Close\1\
- 1960 Out 52,0
- 1980 Return
- 2000 *Enter'data
- 2020 Input"Enter the number of variables. ",Variables
- 2040 Input"Enter the N for your data. ",N
- 2060 Long Results(N,Variables)
- 2080 @
- 2100 For I=1 To N
- 2120 @ I;". ";
- 2140 For J=1 To Variables
- 2160 Input" ",Results(I,J);
- 2180 Next J
- 2200 @
- 2220 Next I
- 2240 Gosub Store'data
- 2260 Return
- 2280 *Clear'screen
- 2300 Out 1,126 : Out 1,28
- 2320 Return
- 2340 *Cursor
- 2360 Out 1,126 : Out 1,17 : Out 1,X : Out 1,Y
- 2380 Return
- 2400 Procedure .Print'array (Title$,Format$,X,Y,Mat Array)
- 2420 @ : @ : @ Title$ : @ : @
- 2440 For J=1 To Y
- 2460 @ Using"###. #",J;
- 2480 If X>0 Then Do
- 2500 For I=1 To X
- 2520 @ Using Format$,Array(I,J);
- 2540 Next I
- 2560 Else
- 2580 @ Using Format$,Array(J)
- 2600 Enddo
- 2620 @
- 2640 Next J
- 2660 @ : @
- 2680 Endproc
- 2700 *Plot
- 2720 Dim Row$(100)
- 2740 For Plot1=1 To Variables-1
- 2760 For Plot2=Plot1+1 To Variables
- 2780 @ : @ : @"VARIABLE ";Plot1;" VERSUS VARIABLE ";Plot2 : @
- 2800 For Row=30 To-30 Step-1
- 2820 Row$=" "
- 2840 If Fra(Row/10)=0 Then Do
- 2860 For I=10 To 100 Step 10
- 2880 Row$(I,I)="-"
- 2900 Next I
- 2920 Enddo
- 2940 If Fra(Row/5)=0 Then @ Using"-##.# ",Row/10;
- 2960 If Fra(Row/5)<>0 Then @" | ";
- 2980 For I=1 To N
- 3000 Y=((Results(I,Plot1)-Mean(Plot1))/Deviation(Plot1))*10
- 3020 If Y<Row+0.5 And Y>Row-0.5 Then Do
- 3040 X=(((Results(I,Plot2)-Mean(Plot2))/Deviation(Plot2))*10)+50
- 3060 If X<1 Then X=1
- 3080 If X>100 Then X=100
- 3100 If Row$(X,X)="*" Then Row$(X,X)="#"
- 3120 If Row$(X,X)<>"#" Then Row$(X,X)="*"
- 3140 Enddo
- 3160 Next I
- 3180 @ Row$
- 3200 Next Row
- 3220 Next Plot2
- 3240 Next Plot1
- 3260 Return
- 3280 Procedure .Inverse (Mat Correlation,Mat Inverse,Variables)
- 3300 For I=1 To Variables
- 3320 For J=1 To Variables
- 3340 Inverse(I,J)=Correlation(I,J)
- 3360 Next J
- 3380 Next I
- 3400 Determinant=1.0
- 3420 For J=1 To Variables
- 3440 Pivot=Inverse(J,J)
- 3460 Determinant=Determinant*Pivot
- 3480 Inverse(J,J)=1.0
- 3500 For K=1 To Variables
- 3520 Inverse(J,K)=Inverse(J,K)/Pivot
- 3540 Next K
- 3560 For K=1 To Variables
- 3580 If(K-J)=0 Then 3700
- 3600 T=Inverse(K,J)
- 3620 Inverse(K,J)=0.0
- 3640 For L=1 To Variables
- 3660 Inverse(K,L)=Inverse(K,L)-Inverse(J,L)*T
- 3680 Next L
- 3700 Next K
- 3720 Next J
- 3740 Title$="MATRIX INVERSE:"
- 3760 Format$="-##.### "
- 3780 Call .Print'array (Title$,Format$,Variables,Variables,Mat Inverse)
- 3800 @ : @"DETERMINANT = ";Determinant
- 3820 Endproc (Determinant)
- 3840 Procedure .Test'inverse (Mat Correlation,Mat Inverse,Variables)
- 3860 Long Test(Variables,Variables)
- 3880 For J=1 To Variables
- 3900 For K=1 To Variables
- 3920 Test(J,K)=0.0
- 3940 For L=1 To Variables
- 3960 Test(J,K)=Test(J,K)+Correlation(J,L)*Inverse(L,K)
- 3980 Next L
- 4000 Next K
- 4020 Next J
- 4040 Title$="IDENTITY MATRIX"
- 4060 Format$="-#.### "
- 4080 Call .Print'array (Title$,Format$,Variables,Variables,Mat Test)
- 4100 Endproc
- 4120 Procedure .Beta'weights (Mat Correlation2,Mat Inverse2,Mat Mean2,Mat Deviation2,Size)
- 4140 Long Beta(5,Size)
- 4160 Mat Beta=0
- 4180 For J=1 To Size
- 4200 For K=1 To Size
- 4220 Beta(1,J)=Beta(1,J)+Inverse2(J,K)*Correlation2(K,Size+1)
- 4240 Next K
- 4260 Next J
- 4280 R'squared=0
- 4300 For I=1 To Size
- 4320 Beta(2,I)=Beta(1,I)*Beta(1,I)
- 4340 Beta(3,I)=Correlation2(I,Size+1)
- 4360 Beta(4,I)=Beta(1,I)*Correlation2(I,Size+1)
- 4380 R'squared=R'squared+Beta(1,I)*Correlation2(I,Size+1)
- 4400 Next I
- 4420 @"MULTIPLE R SQUARED = ";R'squared : @
- 4440 Multiple'r=Sqr(R'squared)
- 4460 @" MULTIPLE R = ";Multiple'r : @
- 4480 Df1=Size
- 4500 Df2=N-Size-1
- 4520 F=(R'squared*Df2)/((1.0-R'squared)*Df1)
- 4540 @"ANALYSIS OF VARIANCE ON R = ";F : @
- 4560 @"DEGREES OF FREEDOM IN REGRESSION EQUATION = ";Df1 : @
- 4580 @"DEGREES OF FREEDOM FOR DATA = ";Df2 : @
- 4600 For I=1 To Size
- 4620 Beta(5,I)=Correlation2(I,Size+1)/Multiple'r
- 4640 Next I
- 4660 Title$=" BETA BETA SQ R(CRITERION) BETA*R STRUCTURED R"
- 4680 Format$=" -##.###"
- 4700 Call .Print'array (Title$,Format$,5,Size,Mat Beta)
- 4720 Intercept=0.0
- 4740 Long B(Size)
- 4760 For I=1 To Size
- 4780 B(I)=Beta(1,I)*(Deviation2(Size+1)/Deviation2(I))
- 4800 Intercept=Intercept+B(I)*Mean2(I)
- 4820 Next I
- 4821 @ Intercept
- 4840 Intercept=Mean2(Size+1)-Intercept
- 4860 Title$="RAW REGRESSION WEIGHTS"
- 4880 Format$="-###.###"
- 4900 Call .Print'array (Title$,Format$,0,Size,Mat B)
- 4920 @"Intercept Constant = ";Intercept : @
- 4940 Endproc
- 4960 *Enter'betas
- 4980 On Error Goto 5040
- 5000 Integer Dependant,Betas'used(Variables)
- 5020 Mat Betas'used=0
- 5040 @ : @ : Input"Enter the number of the dependant variable. ",Command$
- 5060 Dependant=Val(Command$)
- 5080 If Dependant<1 Or Dependant>Variables Then 5040
- 5100 @ : @ : Input"Enter the independant variables you wish to use separated by commas. ",Command$
- 5120 J=0
- 5140 Size=0
- 5160 Repeat
- 5180 I=Val(Command$(J))
- 5200 J=Pos(Command$,",",J)+1
- 5220 If I<1 Or I>Variables Or I=Dependant Then 5020
- 5240 Size=Size+1
- 5260 Betas'used(I)=1
- 5280 Until J=0
- 5300 On Error Stop
- 5320 Long Correlation2(Size+1,Size+1),Inverse2(Size,Size),Mean2(Size+1),Deviation2(Size+1)
- 5340 Mat Correlation2=1
- 5360 K=0
- 5380 For I=1 To Variables
- 5400 If Betas'used(I)=0 Then 5640
- 5420 K=K+1
- 5440 Correlation2(Size+1,K)=Correlation(Dependant,I)
- 5460 Correlation2(K,Size+1)=Correlation(I,Dependant)
- 5480 Mean2(K)=Mean(I)
- 5500 Deviation2(K)=Deviation(I)
- 5520 L=0
- 5540 For J=1 To Variables
- 5560 If Betas'used(J)=0 Then 5620
- 5580 L=L+1
- 5600 Correlation2(K,L)=Correlation(I,J)
- 5620 Next J
- 5640 Next I
- 5660 Mean2(Size+1)=Mean(Dependant)
- 5680 Deviation2(Size+1)=Deviation(Dependant)
- 5700 Title$="CORRELATION MATRIX"
- 5720 Format$=" -#.###"
- 5740 Call .Print'array (Title$,Format$,Size+1,Size+1,Mat Correlation2)
- 5760 Call .Inverse (Mat Correlation2,Mat Inverse2,Size;Determinant)
- 5780 Long Test2(Size,Size)
- 5800 Call .Test'inverse (Mat Correlation2,Mat Inverse2,Size)
- 5820 Return
-