Rev 20 | Rev 4161 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20 | reyssat | 1 | !if $wims_read_parm!=slib_header |
2 | !goto proc |
||
3 | !endif |
||
4 | slib_title=Generation of multinomial random data |
||
5 | slib_parms=3\ |
||
6 | 1,m\ |
||
7 | ,n\ |
||
8 | ,[p1,p2, .. pj] |
||
9 | slib_author=Sophie Lemaire et Bernadette PERRIN-RIOU |
||
10 | slib_out=random data of m integers following a multinomial law of parameters n and p=[p_1,...,p_j] (n is an integer and p_i are positive reals of sum <= 1; if the sum of the p_i is less than 1, 1-sum(p_i) is add to the list. |
||
11 | |||
12 | slib_comment= P(X1=k1,X2=k2,..)=n!/(k1!k2!..)*p1^k1*p2^(k2)... In fact, it is preferable to enter only n-1 p_i because of the tuncature errors : the last one will be add. |
||
13 | |||
14 | slib_example=3,6,[1/3,1/3] |
||
3307 | bpr | 15 | !exit |
20 | reyssat | 16 | |
17 | :proc |
||
18 | |||
19 | !distribute item $wims_read_parm into slib_M, slib_nn |
||
20 | slib_q=!item 3 to -1 of $wims_read_parm |
||
21 | !default slib_M=1 |
||
22 | |||
23 | slib_q=!declosing $slib_q |
||
24 | slib_t=!itemcnt $slib_q |
||
25 | |||
26 | slib_s=!sum x for x in $slib_q |
||
27 | !if $slib_s>1 |
||
28 | !exit |
||
29 | !endif |
||
30 | !if $slib_s>0 and $slib_s<1 |
||
31 | slib_q=$slib_q, $[1-$slib_s] |
||
32 | !advance slib_t |
||
33 | !endif |
||
34 | |||
35 | slib_mult= |
||
36 | !for slib_r=1 to $slib_M |
||
37 | slib_s=1 |
||
38 | slib_N=$slib_nn |
||
39 | |||
40 | slib_V= |
||
41 | !for slib_i=1 to $[$slib_t-1] |
||
42 | slib_j=!item $slib_i of $slib_q |
||
43 | !readproc slib/stat/binomial 1,$slib_N, $[$slib_j/$slib_s] |
||
44 | |||
45 | slib_V=!append item $slib_out to $slib_V |
||
46 | !distribute item $[$slib_s-$slib_j], $[$slib_N-$slib_out] into slib_s,slib_N |
||
47 | |||
48 | !next slib_i |
||
49 | slib_V=!append item $slib_N to $slib_V |
||
50 | |||
51 | slib_mult=!append line $slib_V to $slib_mult |
||
52 | !next slib_r |
||
53 | |||
54 | slib_out=!nonempty line $slib_mult |
||
55 | slib_out=!trim $slib_out |