home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / MCAD254.ZIP / STAT / MULTINOM.MCD < prev    next >
Encoding:
Text File  |  1988-12-02  |  3.0 KB  |  125 lines

  1. .MCD 20000 0
  2. .CMD PLOTFORMAT logs=0,0 subdivs=1,1 size=5,15 type=l
  3. .CMD FORMAT  rd=d ct=10 im=i et=3 zt=15 pr=3 mass length time charge
  4. .CMD SET ORIGIN 0
  5. .CMD SET TOL 0.001000
  6. .CMD MARGIN 0
  7. .CMD LINELENGTH 78
  8. .CMD SET PRNCOLWIDTH 8
  9. .CMD SET PRNPRECISION 4
  10. .TXT 0 38 1 39 
  11. a1,38,40,37
  12. Copyright (c) 1988 by MathSoft, Inc.
  13. .TXT 2 -18 1 38 
  14. a1,37,54,36
  15. SIMULATING A MULTINOMIAL EXPERIMENT
  16. .TXT 2 -18 3 79 
  17. a3,78,76,204
  18. MathCAD's histogram function provides a convenient method for making random 
  19. draws from a multinomial distribution.  In this example, there are four 
  20. outcomes, with probabilities .2, .1, .45, and .25.   
  21. .EQN 4 2 4 15 
  22. PROBS~({4,1}÷.25÷.45÷.1÷.2)
  23. .EQN 0 28 4 16 
  24. OUTCOMES~({4,1}÷4÷3÷2÷1)
  25. .TXT 6 -29 1 71 
  26. a1,70,76,69
  27. Set up a vector of intervals with widths equal to the probabilities:
  28. .EQN 2 0 1 23 
  29. l~0;length(PROBS)
  30. .EQN 0 31 1 27 
  31. h~0;length(PROBS)-1
  32. .EQN 2 -32 4 34 
  33. INTERVALS[l~h$(h<l)*PROBS[h
  34. .TXT 5 0 1 15 
  35. a1,14,76,13
  36. [Ctrl][PgDn]
  37. .TXT 1 0 3 79 
  38. a3,78,77,183
  39. Now draw random numbers uniformly distributed between 0 and 1.  If a number 
  40. falls in the first interval, interpret it as outcome 1, in the second 
  41. interval as outcome 2, and so on. 
  42. .TXT 4 0 1 31 
  43. a1,30,76,29
  44. Choose the number of trials:
  45. .EQN 0 31 1 8 
  46. N~20
  47. .EQN 1 0 1 15 
  48. i~0;N-1
  49. .TXT 2 -31 1 27 
  50. a1,26,76,25
  51. Draw N uniform deviates:
  52. .EQN 0 31 2 13 
  53. R[i~rnd(1)
  54. .EQN 2 0 3 41 
  55. M[i~(hist(INTERVALS,(R{51}){52}i))*OUTCOMES
  56. .TXT 1 -31 1 21 
  57. a1,20,35,19
  58. Find the outcomes:
  59. .TXT 3 0 1 71 
  60. a1,70,76,69
  61. The vector M now contains the results of N trials of the experiment:
  62. .EQN 2 0 1 69 
  63. M{51}=?
  64. .TXT 3 0 1 15 
  65. a1,14,76,13
  66. [Ctrl][PgDn]
  67. .TXT 1 0 2 76 
  68. a2,75,77,98
  69. To draw a different set of N trials, press [F10] C P, or press [Esc] and 
  70. type process [Enter].  
  71. .TXT 3 0 4 78 
  72. a4,77,76,287
  73. To generate random deviates from a hypergeometric distribution, use the 
  74. cumulative distribution function to define an interval vector INT.  The 
  75. screens below illustrate the process for the distribution of defectives in 
  76. samples of size n from a population of size m with d defectives.
  77. .EQN 5 0 1 8 
  78. m~30
  79. .EQN 0 13 1 8 
  80. d~10
  81. .EQN 0 13 1 7 
  82. n~8
  83. .EQN 2 -27 1 19 
  84. U~if(n>d,d,n)
  85. .EQN 0 27 1 35 
  86. L~if(n+d-m>0,n+d-m,0)
  87. .EQN 2 -27 1 19 
  88. j~L+1;U+1
  89. .EQN 0 27 1 11 
  90. k~L;U
  91. .EQN 2 -27 3 22 
  92. f(a,b)~a!/(b!*(a-b)!)
  93. .TXT 4 0 1 15 
  94. a1,14,76,13
  95. [Ctrl][PgDn]
  96. .EQN 1 20 4 54 
  97. INT[(j-L)~1/f(m,n)*(k$(k<j)*f(d,k)*f(m-d,n-k))
  98. .EQN 1 -19 2 10 
  99. INT[0~0
  100. .EQN 3 0 2 12 
  101. OUT[(k-L)~k
  102. .TXT 3 0 1 33 
  103. a1,32,35,31
  104. Choose the number of deviates:
  105. .EQN 0 43 1 8 
  106. N~20
  107. .EQN 0 13 1 15 
  108. i~0;N-1
  109. .TXT 2 -56 1 27 
  110. a1,26,77,25
  111. Draw N uniform deviates:
  112. .EQN 0 43 2 13 
  113. R[i~rnd(1)
  114. .EQN 2 -8 3 30 
  115. H[i~(hist(INT,(R{51}){52}i))*OUT
  116. .TXT 1 -35 1 35 
  117. a1,34,76,33
  118. Find the corresponding outcomes:
  119. .TXT 3 0 2 79 
  120. a2,78,76,133
  121. The vector H holds N values drawn from the hypergeometric distribution that 
  122. corresponds to the sampling experiment defined above.  
  123. .EQN 3 0 1 69 
  124. H{51}=?
  125.