home *** CD-ROM | disk | FTP | other *** search
- rem This is a program for any chi square situation.
- var t,chitot,b,n,ac,bc,cc,dc,ab,num,den,chisq=real
- var o,e,totob,totex,totchi=real
- var a,k,r,df,j,m,c,d,dof=integer
- dim real tc(20) ob(20,20) tr(20) ex(20,20) diff(20,20)
- dim real chi(20,20) obs(20) expt(20) dif(20) chis(20)
- 10 print
- print "This is a program to calculate the value of chi"
- print "square. If you wish to compute a simple chi square,"
- print "enter a 1. If you are dealing with a 2x2 table, enter"
- print "a 2. If you have a table which is larger than 2x2,"
- print "enter a 3. To exit, enter a 4. This program will"
- print "handle up to 20 rows and 20 columns."
- input2 a
- if a=1 then 20
- if a=2 then 30
- if a=4 then 40
- t=0
- chitot=0
- print
- print "How many columns are there?"
- input2 k
- print
- print "How many rows are there?"
- input2 r
- rem There are k columns (j) and r rows (m)
- df=(k-1)*(r-1)
- for j=1 to k
- tc(j)=0
- for m=1 to r
- print "In column ";j;" what is number ";m;"?"
- input2 b
- ob(j,m)=b
- tc(j)=tc(j)+b
- next m
- next j
- for m=1 to r
- tr(m)=0
- for j=1 to k
- tr(m)=tr(m)+ob(j,m)
- next j
- next m
- for j=1 to k
- t=t+tc(j)
- next j
- for j=1 to k
- for m=1 to r
- ex(j,m)=tc(j)*tr(m)/t
- next m
- next j
- print
- print "If you wish to have the answers on the console, enter a"
- print "zero. Otherwise, enter a 1."
- input2 c
- print #c;"Column","Row","Observed","Expected","Difference","D*D/E"
- print #c;
- for j=1 to k
- for m=1 to r
- diff (j,m)=ob(j,m)-ex(j,m)
- chi (j,m)=diff(j,m)*diff(j,m)/ex(j,m)
- print #c;j,m,ob(j,m),ex(j,m),diff(j,m),chi(j,m)
- chitot=chitot+chi(j,m)
- next m
- next j
- print #c;
- print #c;"Chi Square = ";chitot;", Degrees of Freedom are ";df;"."
- go to 10
- 30 print "To calculate the value of chi square for a 2x2 table, enter"
- print "the number in the upper left first, then the number in the upper"
- print "right, then the number in the lower left, and finally the number"
- print "in the lower right. Separate the numbers by commas."
- print "Enter them now."
- input2 ac,bc,cc,dc
- n=ac+bc+cc+dc
- ab=abs(ac*dc-bc*cc)
- num=n*(ab-n/2)*(ab-n/2)
- den=(ac+bc)*(cc+dc)*(ac+cc)*(bc+dc)
- chisq=num/den
- print
- print "If you wish to have the answers on the console, enter a"
- print "zero. Otherwise, enter a 1."
- input2 c
- if c=0 then 50
- print #c;
- print #c;"The numbers are: ";ac;",";bc;",";cc;",";dc
- print #c;
- 50 print #c;"N","Abs Value","Numerator","Denomenator","Chi Square"
- print #c;
- print #c;n,ab,num,den,chisq
- print #c;
- print #c;"There is one degree of freedom."
- goto 10
- 20 totob=0
- totex=0
- totchi=0
- print "How many pairs of numbers are you dealing with?"
- input2 d
- print
- print "Enter each pair of numbers, with commas between them, the"
- print "observed first and then the expected."
- for j=1 to d
- print "Pair number ";j;" is:"
- input2 o,e
- obs(j)=o
- expt(j)=e
- totob=totob+obs(j)
- totex=totex+expt(j)
- dif(j)=obs(j)-expt(j)
- chis(j)=dif(j)*dif(j)/expt(j)
- totchi=totchi+chis(j)
- next j
- print
- print "If you wish to have the answer on the console, enter a"
- print "zero. Otherwise, enter a 1."
- input2 c
- print #c;
- print #c;"Observed","Expected","Difference","Chi Square"
- print #c;
- for j=1 to d
- print #c;obs(j),expt(j),dif(j),chis(j)
- next j
- dof=d-1
- print #c;
- print #c;"The total value of chi square is ";totchi;". There are"
- print #c;dof;" degrees of freedom."
- goto 10
- 40 end
-
- ;cc;",";dc
-