home *** CD-ROM | disk | FTP | other *** search
- .MCD 20000 0
- .CMD PLOTFORMAT logs=0,0 subdivs=1,1 size=5,15 type=l
- .CMD FORMAT rd=d ct=10 im=i et=3 zt=15 pr=3 mass length time charge
- .CMD SET ORIGIN 0
- .CMD SET TOL 0.001000
- .CMD MARGIN 0
- .CMD LINELENGTH 78
- .CMD SET PRNCOLWIDTH 8
- .CMD SET PRNPRECISION 4
- .TXT 0 38 1 39
- a1,38,40,37
- Copyright (c) 1988 by MathSoft, Inc.
- .TXT 2 -18 1 38
- a1,37,54,36
- SIMULATING A MULTINOMIAL EXPERIMENT
- .TXT 2 -18 3 79
- a3,78,76,204
- MathCAD's histogram function provides a convenient method for making random
- draws from a multinomial distribution. In this example, there are four
- outcomes, with probabilities .2, .1, .45, and .25.
- .EQN 4 2 4 15
- PROBS~({4,1}÷.25÷.45÷.1÷.2)
- .EQN 0 28 4 16
- OUTCOMES~({4,1}÷4÷3÷2÷1)
- .TXT 6 -29 1 71
- a1,70,76,69
- Set up a vector of intervals with widths equal to the probabilities:
- .EQN 2 0 1 23
- l~0;length(PROBS)
- .EQN 0 31 1 27
- h~0;length(PROBS)-1
- .EQN 2 -32 4 34
- INTERVALS[l~h$(h<l)*PROBS[h
- .TXT 5 0 1 15
- a1,14,76,13
- [Ctrl][PgDn]
- .TXT 1 0 3 79
- a3,78,77,183
- Now draw random numbers uniformly distributed between 0 and 1. If a number
- falls in the first interval, interpret it as outcome 1, in the second
- interval as outcome 2, and so on.
- .TXT 4 0 1 31
- a1,30,76,29
- Choose the number of trials:
- .EQN 0 31 1 8
- N~20
- .EQN 1 0 1 15
- i~0;N-1
- .TXT 2 -31 1 27
- a1,26,76,25
- Draw N uniform deviates:
- .EQN 0 31 2 13
- R[i~rnd(1)
- .EQN 2 0 3 41
- M[i~(hist(INTERVALS,(R{51}){52}i))*OUTCOMES
- .TXT 1 -31 1 21
- a1,20,35,19
- Find the outcomes:
- .TXT 3 0 1 71
- a1,70,76,69
- The vector M now contains the results of N trials of the experiment:
- .EQN 2 0 1 69
- M{51}=?
- .TXT 3 0 1 15
- a1,14,76,13
- [Ctrl][PgDn]
- .TXT 1 0 2 76
- a2,75,77,98
- To draw a different set of N trials, press [F10] C P, or press [Esc] and
- type process [Enter].
- .TXT 3 0 4 78
- a4,77,76,287
- To generate random deviates from a hypergeometric distribution, use the
- cumulative distribution function to define an interval vector INT. The
- screens below illustrate the process for the distribution of defectives in
- samples of size n from a population of size m with d defectives.
- .EQN 5 0 1 8
- m~30
- .EQN 0 13 1 8
- d~10
- .EQN 0 13 1 7
- n~8
- .EQN 2 -27 1 19
- U~if(n>d,d,n)
- .EQN 0 27 1 35
- L~if(n+d-m>0,n+d-m,0)
- .EQN 2 -27 1 19
- j~L+1;U+1
- .EQN 0 27 1 11
- k~L;U
- .EQN 2 -27 3 22
- f(a,b)~a!/(b!*(a-b)!)
- .TXT 4 0 1 15
- a1,14,76,13
- [Ctrl][PgDn]
- .EQN 1 20 4 54
- INT[(j-L)~1/f(m,n)*(k$(k<j)*f(d,k)*f(m-d,n-k))
- .EQN 1 -19 2 10
- INT[0~0
- .EQN 3 0 2 12
- OUT[(k-L)~k
- .TXT 3 0 1 33
- a1,32,35,31
- Choose the number of deviates:
- .EQN 0 43 1 8
- N~20
- .EQN 0 13 1 15
- i~0;N-1
- .TXT 2 -56 1 27
- a1,26,77,25
- Draw N uniform deviates:
- .EQN 0 43 2 13
- R[i~rnd(1)
- .EQN 2 -8 3 30
- H[i~(hist(INT,(R{51}){52}i))*OUT
- .TXT 1 -35 1 35
- a1,34,76,33
- Find the corresponding outcomes:
- .TXT 3 0 2 79
- a2,78,76,133
- The vector H holds N values drawn from the hypergeometric distribution that
- corresponds to the sampling experiment defined above.
- .EQN 3 0 1 69
- H{51}=?
-