home *** CD-ROM | disk | FTP | other *** search
/ Compute! Gazette 1994 February / 1994-02b.d64 / statistics (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  3KB  |  137 lines

  1. 10 rem statistics
  2. 20 rem by earl woodman
  3. 30 rem copyright 1994 - compute publications intl ltd - all rights reserved
  4. 40 dimr(200),x(100),y(100)
  5. 50 poke53280,0:poke53281,0
  6. 60 print"[147]"
  7. 70 print"[153]              menu"
  8. 80 print:print:print"       [159]1.statistics"
  9. 90 print:print:print"       [159]2.linear regression"
  10. 100 print:print:print"       [159]3.quit":print
  11. 110 print:print:print"[156]please choose 1, 2 or 3";
  12. 120 input zz
  13. 130 if zz=2thengosub 840
  14. 140 if zz=1 then gosub170
  15. 145 if zz=3thenend
  16. 150 if zz<>1andzz<>2then120
  17. 160 run
  18. 170 print"[147][149]             statistics"
  19. 180 print
  20. 190 print"this part of the program is used to"
  21. 200 print"find the smallest, largest, range, mean,";
  22. 210 print"and median values, and the variances"
  23. 220 print"and standard deviations, from values"
  24. 230 print"input by you. as many as 200 items can"
  25. 240 print"be entered. or type -1 to end entries."
  26. 250 print
  27. 290 print"press a key to begin."
  28. 300 getr$:ifr$=""then 300
  29. 310 print"[147]"
  30. 320 d=d+1
  31. 330 print"[129]please enter entry: "d;:inputr(d)
  32. 340 ifr(d)<0andr(d)<>-1thengosub490
  33. 350 ifr(d)=-1thend=d-1:goto380
  34. 360 if d=100then380
  35. 370 goto 320
  36. 380 rem beginning of sort routine
  37. 390 print"[147][155]sorting...":let sr= 0
  38. 400 if sr =-1then 520
  39. 410 sr=-1
  40. 420 for qw= 1 to d-1
  41. 430 if r(qw) > r(qw+1) then450
  42. 440 next qw:goto 400
  43. 450 tp =r(qw) :r(qw) = r(qw+1):let r(qw+1) =tp:sr=0
  44. 460 next qw
  45. 470 goto 400
  46. 480 end
  47. 490 print"[150]must be non-negative or zero."
  48. 500 d=d-1:return
  49. 510 end
  50. 520 print"[147]"
  51. 530 print"[158]here are the numbers:"
  52. 540 for pl= 1 to d
  53. 550 print r(pl),
  54. 560 next pl
  55. 570 print
  56. 580 print
  57. 590 print"the lowest entry is:";r(1)
  58. 600 print"the highest entry is:";r(d)
  59. 610 print"the range is:";r(d) - r(1)
  60. 620 if int(d/2)=d/2 thenmed=(r(d/2)+r(d/2+1))*.5:goto 640
  61. 630 med=r(d/2+.5)
  62. 640 print"the median is:";med
  63. 650 for o = 1tod
  64. 660 ts=ts+r(o)
  65. 670 next o
  66. 680 av=ts/(o-1)
  67. 690 print"the mean is:";av
  68. 700 rem sample variance
  69. 710 for g=1tod
  70. 720 tt=tt+(r(g)-av)^2
  71. 730 next g
  72. 740 var=(tt)/(d-1)
  73. 750 sd=var^.5
  74. 760 pv=tt/d
  75. 770 print"the sample variance is:";var
  76. 780 print"sample standard deviation is:";sd
  77. 790 print"pop. variance is:";pv
  78. 800 print"pop. standard deviation is:";pv^.5
  79. 810 print"press any key"
  80. 820 get e$:ife$=""then820
  81. 830 return
  82. 840 rem linear regression
  83. 850 rem
  84. 860 print"[147]"
  85. 870 poke53280,0:poke53281,0:p=0
  86. 880 print"linear regression"
  87. 890 print"this program will calculate a"
  88. 900 print"relationship of the form y=mx+b"
  89. 910 print"for the values of x, and y that are"
  90. 920 print"supplied by you."
  91. 930 print"[154]press any key to continue..."
  92. 940 get a$:ifa$=""then940:print"[147]"
  93. 950 print"  enter -1 for x-entry to end."
  94. 960 p=p+1
  95. 970 print"[153]enter x-entry number ";p;
  96. 980 inputx(p):ifx(2)=-1thenp=0:print"[159]enter at least 2 x values":x(2)=0:goto950
  97. 990 if x(p) =-1 then p=p-1:goto1040
  98. 1000 print"[152]enter y-entry number ";p;
  99. 1010 input y(p)
  100. 1020 if p>99 then1040
  101. 1030 goto 960
  102. 1040 rem
  103. 1050 sr=0 :print"[147]sorting (on x)...":rem begin sort routine
  104. 1060 sr=-1
  105. 1070 for g=1top-1
  106. 1080 if x(g)<=x(g+1) then1120
  107. 1090 ya=y(g):y(g)=y(g+1):y(g+1)=ya
  108. 1100 xa=x(g):x(g)=x(g+1):x(g+1)=xa
  109. 1110 sr=0:ya=0:xa=0
  110. 1120 next g
  111. 1130 if not sr then 1060
  112. 1140 print"here is the list of sorted data:"
  113. 1150 forr=1top:printx(r)" "y(r),
  114. 1160 nextr:print"":bb=0:dd=0
  115. 1170 print"calculating regression equation..."
  116. 1180 for aa=1top:letxt=x(aa)+xt:nextaa
  117. 1190 for cc=1top:letyt=y(cc)+yt:nextcc
  118. 1200 xavg=xt/p:yavg=yt/p
  119. 1210 for we=1top:l=l+(x(we)-xavg)*(y(we)-yavg):nextwe
  120. 1220 forwf=1top:la=la+(x(wf)-xavg)^2:nextwf:ifla=0thenprint"not a line":goto1360
  121. 1230 for wg=1top:lb=lb+(y(wg)-yavg)^2:nextwg
  122. 1240 b1=l/la
  123. 1250 b0=(yt-b1*xt)/p
  124. 1260 print"the regression equation is:"
  125. 1270 print" y = ";b1;"x + ";b0
  126. 1280 print"the sample's correlation coefficient is:";
  127. 1290 print"(an indication of the relationship's":print"linearity)"
  128. 1300 r=l/(la^.5*lb^.5)
  129. 1310 printr
  130. 1320 print"enter a value for x, and the y"
  131. 1330 input"value will be calculated";va
  132. 1340 let y=va*b1+b0
  133. 1350 print" y = ";y
  134. 1360 print"press any key"
  135. 1370 gete$:ife$=""then 1370
  136. 1380 return
  137.