home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / SIMTEL / CPMUG / CPMUG080.ARK / STAT.STB < prev    next >
Text File  |  1984-04-29  |  10KB  |  296 lines

  1.  
  2.    20   Rem 4/21/80
  3.    40   Set 0,132
  4.    60   Integer Variables,I,J,K,L,M,N,Plot1,Plot2
  5.    80   Dim Title$(80),Format$(20),Command$(50)
  6.   100   @ : @ : @"Statistical Analysis" : @ : @
  7.   120   @"    By"
  8.   140   @"David Trachtenbarg" : @
  9.   160   @"copyright 1980" : @ : @
  10.   180   Input"Do you wish to enter new data? (Y/N) ",Command$
  11.   200   If Command$(0,0)="Y" Then Gosub Enter'data
  12.   220   If Command$(0,0)="N" Then Gosub Get'data
  13.   240   If Command$(0,0)<>"Y" And Command$(0,0)<>"N" Then Goto 180
  14.   250   Gosub Plot
  15.   260   Gosub Mean
  16.   280   Gosub Standard'deviation
  17.   300   Gosub Correlation'matrix
  18.   320   Long Inverse(Variables,Variables),Determinant
  19.   340   Call .Inverse (Mat Correlation,Mat Inverse,Variables;Determinant)
  20.   360   Call .Test'inverse (Mat Correlation,Mat Inverse,Variables)
  21.   380   Gosub Enter'betas
  22.   400   Long Beta(Size)
  23.   420   Call .Beta'weights (Mat Correlation2,Mat Inverse2,Mat Mean2,Mat Deviation2,Size)
  24.   440   Goto 380
  25.   460   End
  26.   480 *Mean
  27.   500   Long Mean(Variables)
  28.   520   Mat Mean=0
  29.   540   @
  30.   560     For I=1 To N
  31.   580     @ Using"###. ",I;
  32.   600       For J=1 To Variables
  33.   620       @ Using" ##.## ",Results(I,J);
  34.   640       Mean(J)=Mean(J)+Results(I,J)
  35.   660       Next J
  36.   680     @
  37.   700     Next I
  38.   720   @ : @"MEAN ";
  39.   740     For I=1 To Variables
  40.   760     Mean(I)=Mean(I)/N
  41.   780     @ Using" ##.## ",Mean(I);
  42.   800     Next I
  43.   820   Return
  44.   840 *Standard'deviation
  45.   860   Long Deviation(Variables)
  46.   880   Mat Deviation=0
  47.   900   @ : @"DEV. ";
  48.   920     For I=1 To Variables
  49.   940       For J=1 To N
  50.   960       Deviation(I)=(Mean(I)-Results(J,I))*(Mean(I)-Results(J,I))+Deviation(I)
  51.   980       Next J
  52.  1000     Deviation(I)=Sqr(Deviation(I)/(N-1))
  53.  1020     @ Using" ##.## ",Deviation(I);
  54.  1040     Next I
  55.  1060   Return
  56.  1080 *Correlation'matrix
  57.  1100   Long Correlation(Variables,Variables)
  58.  1120   @ : @ : @"CORRELATION MATRIX" : @
  59.  1140   Mat Correlation=0
  60.  1160     For J=1 To Variables
  61.  1180     @ Using" ###. ",J;
  62.  1200       For I=1 To Variables
  63.  1220         For K=1 To N
  64.  1240         Correlation(I,J)=Correlation(I,J)+(Results(K,I)-Mean(I))*(Results(K,J)-Mean(J))
  65.  1260         Next K
  66.  1280       Correlation(I,J)=(Correlation(I,J)/(N-1))/(Deviation(I)*Deviation(J))
  67.  1300       @ Using"-#.### ",Correlation(I,J);
  68.  1320       Next I
  69.  1340     @
  70.  1360     Next J
  71.  1380   Return
  72.  1400 *Store'data
  73.  1420   @ : @"Storing data....." : @ : @
  74.  1440   On Error Goto 1480
  75.  1460   Erase"stat.dat"
  76.  1480   On Error Stop
  77.  1500   Create"stat.dat"
  78.  1520   Open\1,(Variables*8)\"stat.dat"
  79.  1540   Put\1,0\N,Variables
  80.  1560     For I=1 To N
  81.  1580       For J=1 To Variables
  82.  1600       Put\1,I,((J-1)*8)\Results(I,J)
  83.  1620       Next J
  84.  1640     Next I
  85.  1660   Close\1\
  86.  1680   Return
  87.  1700 *Get'data
  88.  1720   @ : @"Retreiving data....." : @ : @
  89.  1740   Open\1\"stat.dat"
  90.  1760   Get\1\N,Variables
  91.  1780   Close\1\
  92.  1800   Long Results(N,Variables)
  93.  1820   Open\1,(Variables*8)\"stat.dat"
  94.  1840     For I=1 To N
  95.  1860       For J=1 To Variables
  96.  1880       Get\1,I,((J-1)*8)\Results(I,J)
  97.  1900       Next J
  98.  1920     Next I
  99.  1940   Close\1\
  100.  1960   Out 52,0
  101.  1980   Return
  102.  2000 *Enter'data
  103.  2020   Input"Enter the number of variables. ",Variables
  104.  2040   Input"Enter the N for your data. ",N
  105.  2060   Long Results(N,Variables)
  106.  2080   @
  107.  2100     For I=1 To N
  108.  2120     @ I;".  ";
  109.  2140       For J=1 To Variables
  110.  2160       Input"  ",Results(I,J);
  111.  2180       Next J
  112.  2200     @
  113.  2220     Next I
  114.  2240   Gosub Store'data
  115.  2260   Return
  116.  2280 *Clear'screen
  117.  2300   Out 1,126 : Out 1,28
  118.  2320   Return
  119.  2340 *Cursor
  120.  2360   Out 1,126 : Out 1,17 : Out 1,X : Out 1,Y
  121.  2380   Return
  122.  2400 Procedure .Print'array (Title$,Format$,X,Y,Mat Array)
  123.  2420   @ : @ : @ Title$ : @ : @
  124.  2440     For J=1 To Y
  125.  2460     @ Using"###. #",J;
  126.  2480     If X>0 Then  Do
  127.  2500         For I=1 To X
  128.  2520         @ Using Format$,Array(I,J);
  129.  2540         Next I
  130.  2560       Else
  131.  2580       @ Using Format$,Array(J)
  132.  2600       Enddo
  133.  2620     @
  134.  2640     Next J
  135.  2660   @ : @
  136.  2680   Endproc 
  137.  2700 *Plot
  138.  2720   Dim Row$(100)
  139.  2740     For Plot1=1 To Variables-1
  140.  2760       For Plot2=Plot1+1 To Variables
  141.  2780       @ : @ : @"VARIABLE ";Plot1;" VERSUS VARIABLE ";Plot2 : @
  142.  2800         For Row=30 To-30 Step-1
  143.  2820         Row$="                                                                                                       "
  144.  2840         If Fra(Row/10)=0 Then  Do
  145.  2860             For I=10 To 100 Step 10
  146.  2880             Row$(I,I)="-"
  147.  2900             Next I
  148.  2920           Enddo
  149.  2940         If Fra(Row/5)=0 Then @ Using"-##.# ",Row/10;
  150.  2960         If Fra(Row/5)<>0 Then @"   |  ";
  151.  2980           For I=1 To N
  152.  3000           Y=((Results(I,Plot1)-Mean(Plot1))/Deviation(Plot1))*10
  153.  3020           If Y<Row+0.5 And Y>Row-0.5 Then  Do
  154.  3040             X=(((Results(I,Plot2)-Mean(Plot2))/Deviation(Plot2))*10)+50
  155.  3060             If X<1 Then X=1
  156.  3080             If X>100 Then X=100
  157.  3100             If Row$(X,X)="*" Then Row$(X,X)="#"
  158.  3120             If Row$(X,X)<>"#" Then Row$(X,X)="*"
  159.  3140             Enddo
  160.  3160           Next I
  161.  3180         @ Row$
  162.  3200         Next Row
  163.  3220       Next Plot2
  164.  3240     Next Plot1
  165.  3260   Return
  166.  3280 Procedure .Inverse (Mat Correlation,Mat Inverse,Variables)
  167.  3300     For I=1 To Variables
  168.  3320       For J=1 To Variables
  169.  3340       Inverse(I,J)=Correlation(I,J)
  170.  3360       Next J
  171.  3380     Next I
  172.  3400   Determinant=1.0
  173.  3420     For J=1 To Variables
  174.  3440     Pivot=Inverse(J,J)
  175.  3460     Determinant=Determinant*Pivot
  176.  3480     Inverse(J,J)=1.0
  177.  3500       For K=1 To Variables
  178.  3520       Inverse(J,K)=Inverse(J,K)/Pivot
  179.  3540       Next K
  180.  3560       For K=1 To Variables
  181.  3580       If(K-J)=0 Then 3700
  182.  3600       T=Inverse(K,J)
  183.  3620       Inverse(K,J)=0.0
  184.  3640         For L=1 To Variables
  185.  3660         Inverse(K,L)=Inverse(K,L)-Inverse(J,L)*T
  186.  3680         Next L
  187.  3700       Next K
  188.  3720     Next J
  189.  3740   Title$="MATRIX INVERSE:"
  190.  3760   Format$="-##.### "
  191.  3780   Call .Print'array (Title$,Format$,Variables,Variables,Mat Inverse)
  192.  3800   @ : @"DETERMINANT = ";Determinant
  193.  3820   Endproc (Determinant)
  194.  3840 Procedure .Test'inverse (Mat Correlation,Mat Inverse,Variables)
  195.  3860   Long Test(Variables,Variables)
  196.  3880     For J=1 To Variables
  197.  3900       For K=1 To Variables
  198.  3920       Test(J,K)=0.0
  199.  3940         For L=1 To Variables
  200.  3960         Test(J,K)=Test(J,K)+Correlation(J,L)*Inverse(L,K)
  201.  3980         Next L
  202.  4000       Next K
  203.  4020     Next J
  204.  4040   Title$="IDENTITY MATRIX"
  205.  4060   Format$="-#.### "
  206.  4080   Call .Print'array (Title$,Format$,Variables,Variables,Mat Test)
  207.  4100   Endproc 
  208.  4120 Procedure .Beta'weights (Mat Correlation2,Mat Inverse2,Mat Mean2,Mat Deviation2,Size)
  209.  4140   Long Beta(5,Size)
  210.  4160   Mat Beta=0
  211.  4180     For J=1 To Size
  212.  4200       For K=1 To Size
  213.  4220       Beta(1,J)=Beta(1,J)+Inverse2(J,K)*Correlation2(K,Size+1)
  214.  4240       Next K
  215.  4260     Next J
  216.  4280   R'squared=0
  217.  4300     For I=1 To Size
  218.  4320     Beta(2,I)=Beta(1,I)*Beta(1,I)
  219.  4340     Beta(3,I)=Correlation2(I,Size+1)
  220.  4360     Beta(4,I)=Beta(1,I)*Correlation2(I,Size+1)
  221.  4380     R'squared=R'squared+Beta(1,I)*Correlation2(I,Size+1)
  222.  4400     Next I
  223.  4420   @"MULTIPLE R SQUARED = ";R'squared : @
  224.  4440   Multiple'r=Sqr(R'squared)
  225.  4460   @" MULTIPLE R = ";Multiple'r : @
  226.  4480   Df1=Size
  227.  4500   Df2=N-Size-1
  228.  4520   F=(R'squared*Df2)/((1.0-R'squared)*Df1)
  229.  4540   @"ANALYSIS OF VARIANCE ON R = ";F : @
  230.  4560   @"DEGREES OF FREEDOM IN REGRESSION EQUATION = ";Df1 : @
  231.  4580   @"DEGREES OF FREEDOM FOR DATA = ";Df2 : @
  232.  4600     For I=1 To Size
  233.  4620     Beta(5,I)=Correlation2(I,Size+1)/Multiple'r
  234.  4640     Next I
  235.  4660   Title$="             BETA      BETA SQ  R(CRITERION)   BETA*R    STRUCTURED R"
  236.  4680   Format$="     -##.###"
  237.  4700   Call .Print'array (Title$,Format$,5,Size,Mat Beta)
  238.  4720   Intercept=0.0
  239.  4740   Long B(Size)
  240.  4760     For I=1 To Size
  241.  4780     B(I)=Beta(1,I)*(Deviation2(Size+1)/Deviation2(I))
  242.  4800     Intercept=Intercept+B(I)*Mean2(I)
  243.  4820     Next I
  244.  4821   @ Intercept
  245.  4840   Intercept=Mean2(Size+1)-Intercept
  246.  4860   Title$="RAW REGRESSION WEIGHTS"
  247.  4880   Format$="-###.###"
  248.  4900   Call .Print'array (Title$,Format$,0,Size,Mat B)
  249.  4920   @"Intercept Constant = ";Intercept : @
  250.  4940   Endproc 
  251.  4960 *Enter'betas
  252.  4980   On Error Goto 5040
  253.  5000   Integer Dependant,Betas'used(Variables)
  254.  5020   Mat Betas'used=0
  255.  5040   @ : @ : Input"Enter the number of the dependant variable. ",Command$
  256.  5060   Dependant=Val(Command$)
  257.  5080   If Dependant<1 Or Dependant>Variables Then 5040
  258.  5100   @ : @ : Input"Enter the independant variables you wish to use separated by commas. ",Command$
  259.  5120   J=0
  260.  5140   Size=0
  261.  5160     Repeat
  262.  5180     I=Val(Command$(J))
  263.  5200     J=Pos(Command$,",",J)+1
  264.  5220     If I<1 Or I>Variables Or I=Dependant Then 5020
  265.  5240     Size=Size+1
  266.  5260     Betas'used(I)=1
  267.  5280     Until J=0
  268.  5300   On Error Stop
  269.  5320   Long Correlation2(Size+1,Size+1),Inverse2(Size,Size),Mean2(Size+1),Deviation2(Size+1)
  270.  5340   Mat Correlation2=1
  271.  5360   K=0
  272.  5380     For I=1 To Variables
  273.  5400     If Betas'used(I)=0 Then 5640
  274.  5420     K=K+1
  275.  5440     Correlation2(Size+1,K)=Correlation(Dependant,I)
  276.  5460     Correlation2(K,Size+1)=Correlation(I,Dependant)
  277.  5480     Mean2(K)=Mean(I)
  278.  5500     Deviation2(K)=Deviation(I)
  279.  5520     L=0
  280.  5540       For J=1 To Variables
  281.  5560       If Betas'used(J)=0 Then 5620
  282.  5580       L=L+1
  283.  5600       Correlation2(K,L)=Correlation(I,J)
  284.  5620       Next J
  285.  5640     Next I
  286.  5660   Mean2(Size+1)=Mean(Dependant)
  287.  5680   Deviation2(Size+1)=Deviation(Dependant)
  288.  5700   Title$="CORRELATION MATRIX"
  289.  5720   Format$=" -#.###"
  290.  5740   Call .Print'array (Title$,Format$,Size+1,Size+1,Mat Correlation2)
  291.  5760   Call .Inverse (Mat Correlation2,Mat Inverse2,Size;Determinant)
  292.  5780   Long Test2(Size,Size)
  293.  5800   Call .Test'inverse (Mat Correlation2,Mat Inverse2,Size)
  294.  5820   Return
  295.