home *** CD-ROM | disk | FTP | other *** search
/ Play and Learn 2 / 19941.ZIP / 19941 / EDUCMATH / STATS / BAYES.BAS (.txt) < prev    next >
Encoding:
GW-BASIC  |  1994-02-04  |  3.1 KB  |  48 lines

  1. 1  '                         BAYES' THEOREM
  2. 2  '               Copyright Tracy L. Gustafson, M.D.
  3. 3  '              Round Rock, Texas. Version 3.2, 1985
  4. 4  ON ERROR GOTO 5000:CHAIN MERGE "EPIMRG",5
  5. 15  DIM D(1),PT(1),PD(1)
  6. 22  DATA "BAYES' THEOREM",32,16
  7. 30  PRINT"  This theorem is especially valuable in evaluating the prior probability":PRINT "    of disease given a certain symptom, sign or laboratory result."
  8. 35  PRINT:PRINT:PRINT "Do you want to evaluate the: ":PRINT
  9. 40  PRINT TAB(12);"1.)  Probabilities of False Positive and False Negative tests":PRINT
  10. 45  PRINT TAB(12);"2.)  Probability of Disease given a Positive test"
  11. 50  LOCATE 15,25:PRINT "Enter choice:":AR=15:AC=39:GOSUB 4800:ASUB=VAL(IP$):IF ABS(1.5-ASUB)>0.5 THEN BEEP:GOTO 50
  12. 55  CLS:ON ASUB GOTO 60,115
  13. 60  PRINT TAB(12);"PROBABILITIES OF FALSE POSITIVE AND FALSE NEGATIVE TESTS":PRINT TAB(12);STRING$(56,205):PRINT
  14. 65  INPUT "  What is the NAME of the disease or condition being tested for?  ",D(1)
  15. 70  DQ="What is the probability of a POSITIVE test":PRINT TAB(5);DQ:PRINT TAB(37);:PRINT "when a person has ";D(1);:INPUT PT:IF ABS(PT-0.5)>=0.5 THEN GOSUB 215:GOTO 70
  16. 75  PRINT TAB(27);"TEST SENSITIVITY = ";PT*100;"%":PRINT
  17. 80  PRINT TAB(5);DQ:PRINT TAB(30);:PRINT "when a person does not have ";D(1);:INPUT PF:IF ABS(PF-0.5)>=0.5 THEN GOSUB 215:GOTO 80
  18. 85  PRINT TAB(27);"TEST SPECIFICITY = ";(1-PF)*100;"%":PRINT
  19. 90  PRINT TAB(8);"Enter estimated incidence of ";D(1):PRINT TAB(10);:INPUT "in the population in which the test is used (PER/10,000) = ",PD:IF PD>10000 THEN BEEP:GOTO 90
  20. 95  PD=PD*9.9999E-05:PP=(PF*(1-PD))/(PF+PD*(PT-PF)):PN=((1-PT)*PD)/(1-PF-PD*(PT-PF))
  21. 100  GOSUB 210:PRINT:PRINT:COLOR CLR2,CLR1
  22. 105  PRINT TAB(10);"The probability of a FALSE POSITIVE result is  ";PP;TAB(80):PRINT:PRINT
  23. 110  PRINT TAB(10);"The probability of a FALSE NEGATIVE result is  ";PN;TAB(80):COLOR CLR1,CLR2:GOTO 195
  24. 115  PRINT TAB(19);"PROBABILITIES OF DISEASE GIVEN A POSITIVE TEST":PRINT TAB(19);STRING$(46,205):PRINT
  25. 120  PRINT TAB(5); "What is the name of the SYMPTOM COMPLEX, PHYSICAL FINDING,": PRINT TAB(27);:INPUT "or LABORATORY TEST under consideration?   ",T$
  26. 125  PRINT TAB(5);"In the tested population, HOW MANY DISEASES exist ":PRINT TAB(33);:INPUT "in which this test can be positive?     ",N:PRINT
  27. 130  ERASE PT,PD,D:DIM PT(N),PD(N),D(N):TF=0
  28. 135  PRINT TAB(15);"  PERCENT of people      PROBABILITY of a "
  29. 140  PRINT TAB(15);" in tested population    + test in people"
  30. 145  PRINT TAB(15);"who have this disease:    known to have"
  31. 150  PRINT TAB(3);"DISEASE      (SUM must = 100%)        this disease:": PRINT
  32. 155  FOR Z=1 TO N:PRINT Z;:IF TF=1 THEN PRINT D(Z); ELSE INPUT;"",D(Z)
  33. 160  PRINT TAB(24);:INPUT;"",P:PD(Z)=P*0.01:PRINT TAB(46);:INPUT "",PT(Z):NEXT Z
  34. 165  SP=0:FOR Z=1 TO N:SP=SP+PD(Z)*PT(Z):NEXT
  35. 170  LOCATE 9,60:COLOR CLR2,CLR1:PRINT "  PROBABILITY of ":LOCATE 10,60:PRINT " this disease in ":LOCATE 11,60:PRINT " a person with a ":LOCATE 12,60:PRINT "  positive test: ":GOSUB 210
  36. 175  FOR Z=1 TO N:LOCATE 13+Z,66:PRINT USING ".######";PD(Z)*PT(Z)/SP:NEXT
  37. 180  COLOR CLR1,CLR2:LOCATE 24,1:PRINT "Would you like to modify these calculations in relation to";
  38. 185  LOCATE 25,34:INPUT;"the SAME TEST and the SAME DISEASES?   ",A$
  39. 190  IF A$="y" OR A$="Y" THEN TF=1:CLS:LOCATE 4,30:PRINT "TEST = ";T$:LOCATE 9,1:GOTO 135
  40. 195  LOCATE 24,1:PRINT TAB(80):LOCATE 25,1:PRINT TAB(79):LOCATE 25,12:INPUT;"Do you want another calculation using Bayes' Theorem?   ",A$
  41. 200  IF A$="Y" OR A$="y" THEN 20
  42. 205  GOTO 3000
  43. 210  PLAY "MS O3 L64 G O2 GE L9 E":RETURN
  44. 215  BEEP:AR=CSRLIN:LOCATE 25,15:PRINT "Probability should be a fraction between 0 and 1.";:LOCATE AR,1:RETURN
  45. 5000  BEEP:IF ERR<>53 AND ERR<>71 THEN 5010 ELSE LOCATE 2,10:PRINT "Please place EPISTAT in drive A: (or other default).":PRINT TAB(25);"Press any key to continue:"
  46. 5005  A$=INKEY$:IF A$="" THEN 5005 ELSE RESUME
  47. 5010  ON ERROR GOTO 0:END
  48.