home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Compute! Gazette 1994 February
/
1994-02b.d64
/
statistics
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-09-20
|
3KB
|
137 lines
10 rem statistics
20 rem by earl woodman
30 rem copyright 1994 - compute publications intl ltd - all rights reserved
40 dimr(200),x(100),y(100)
50 poke53280,0:poke53281,0
60 print"[147]"
70 print"[153] menu"
80 print:print:print" [159]1.statistics"
90 print:print:print" [159]2.linear regression"
100 print:print:print" [159]3.quit":print
110 print:print:print"[156]please choose 1, 2 or 3";
120 input zz
130 if zz=2thengosub 840
140 if zz=1 then gosub170
145 if zz=3thenend
150 if zz<>1andzz<>2then120
160 run
170 print"[147][149] statistics"
180 print
190 print"this part of the program is used to"
200 print"find the smallest, largest, range, mean,";
210 print"and median values, and the variances"
220 print"and standard deviations, from values"
230 print"input by you. as many as 200 items can"
240 print"be entered. or type -1 to end entries."
250 print
290 print"press a key to begin."
300 getr$:ifr$=""then 300
310 print"[147]"
320 d=d+1
330 print"[129]please enter entry: "d;:inputr(d)
340 ifr(d)<0andr(d)<>-1thengosub490
350 ifr(d)=-1thend=d-1:goto380
360 if d=100then380
370 goto 320
380 rem beginning of sort routine
390 print"[147][155]sorting...":let sr= 0
400 if sr =-1then 520
410 sr=-1
420 for qw= 1 to d-1
430 if r(qw) > r(qw+1) then450
440 next qw:goto 400
450 tp =r(qw) :r(qw) = r(qw+1):let r(qw+1) =tp:sr=0
460 next qw
470 goto 400
480 end
490 print"[150]must be non-negative or zero."
500 d=d-1:return
510 end
520 print"[147]"
530 print"[158]here are the numbers:"
540 for pl= 1 to d
550 print r(pl),
560 next pl
570 print
580 print
590 print"the lowest entry is:";r(1)
600 print"the highest entry is:";r(d)
610 print"the range is:";r(d) - r(1)
620 if int(d/2)=d/2 thenmed=(r(d/2)+r(d/2+1))*.5:goto 640
630 med=r(d/2+.5)
640 print"the median is:";med
650 for o = 1tod
660 ts=ts+r(o)
670 next o
680 av=ts/(o-1)
690 print"the mean is:";av
700 rem sample variance
710 for g=1tod
720 tt=tt+(r(g)-av)^2
730 next g
740 var=(tt)/(d-1)
750 sd=var^.5
760 pv=tt/d
770 print"the sample variance is:";var
780 print"sample standard deviation is:";sd
790 print"pop. variance is:";pv
800 print"pop. standard deviation is:";pv^.5
810 print"press any key"
820 get e$:ife$=""then820
830 return
840 rem linear regression
850 rem
860 print"[147]"
870 poke53280,0:poke53281,0:p=0
880 print"linear regression"
890 print"this program will calculate a"
900 print"relationship of the form y=mx+b"
910 print"for the values of x, and y that are"
920 print"supplied by you."
930 print"[154]press any key to continue..."
940 get a$:ifa$=""then940:print"[147]"
950 print" enter -1 for x-entry to end."
960 p=p+1
970 print"[153]enter x-entry number ";p;
980 inputx(p):ifx(2)=-1thenp=0:print"[159]enter at least 2 x values":x(2)=0:goto950
990 if x(p) =-1 then p=p-1:goto1040
1000 print"[152]enter y-entry number ";p;
1010 input y(p)
1020 if p>99 then1040
1030 goto 960
1040 rem
1050 sr=0 :print"[147]sorting (on x)...":rem begin sort routine
1060 sr=-1
1070 for g=1top-1
1080 if x(g)<=x(g+1) then1120
1090 ya=y(g):y(g)=y(g+1):y(g+1)=ya
1100 xa=x(g):x(g)=x(g+1):x(g+1)=xa
1110 sr=0:ya=0:xa=0
1120 next g
1130 if not sr then 1060
1140 print"here is the list of sorted data:"
1150 forr=1top:printx(r)" "y(r),
1160 nextr:print"":bb=0:dd=0
1170 print"calculating regression equation..."
1180 for aa=1top:letxt=x(aa)+xt:nextaa
1190 for cc=1top:letyt=y(cc)+yt:nextcc
1200 xavg=xt/p:yavg=yt/p
1210 for we=1top:l=l+(x(we)-xavg)*(y(we)-yavg):nextwe
1220 forwf=1top:la=la+(x(wf)-xavg)^2:nextwf:ifla=0thenprint"not a line":goto1360
1230 for wg=1top:lb=lb+(y(wg)-yavg)^2:nextwg
1240 b1=l/la
1250 b0=(yt-b1*xt)/p
1260 print"the regression equation is:"
1270 print" y = ";b1;"x + ";b0
1280 print"the sample's correlation coefficient is:";
1290 print"(an indication of the relationship's":print"linearity)"
1300 r=l/(la^.5*lb^.5)
1310 printr
1320 print"enter a value for x, and the y"
1330 input"value will be calculated";va
1340 let y=va*b1+b0
1350 print" y = ";y
1360 print"press any key"
1370 gete$:ife$=""then 1370
1380 return