Rev 3307 | Go to most recent revision | Details | 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] |
||
15 | |||
16 | :proc |
||
17 | |||
18 | !distribute item $wims_read_parm into slib_M, slib_nn |
||
19 | slib_q=!item 3 to -1 of $wims_read_parm |
||
20 | !default slib_M=1 |
||
21 | |||
22 | slib_q=!declosing $slib_q |
||
23 | slib_t=!itemcnt $slib_q |
||
24 | |||
25 | slib_s=!sum x for x in $slib_q |
||
26 | !if $slib_s>1 |
||
27 | !exit |
||
28 | !endif |
||
29 | !if $slib_s>0 and $slib_s<1 |
||
30 | slib_q=$slib_q, $[1-$slib_s] |
||
31 | !advance slib_t |
||
32 | !endif |
||
33 | |||
34 | slib_mult= |
||
35 | !for slib_r=1 to $slib_M |
||
36 | slib_s=1 |
||
37 | slib_N=$slib_nn |
||
38 | |||
39 | slib_V= |
||
40 | !for slib_i=1 to $[$slib_t-1] |
||
41 | slib_j=!item $slib_i of $slib_q |
||
42 | !readproc slib/stat/binomial 1,$slib_N, $[$slib_j/$slib_s] |
||
43 | |||
44 | slib_V=!append item $slib_out to $slib_V |
||
45 | !distribute item $[$slib_s-$slib_j], $[$slib_N-$slib_out] into slib_s,slib_N |
||
46 | |||
47 | !next slib_i |
||
48 | slib_V=!append item $slib_N to $slib_V |
||
49 | |||
50 | slib_mult=!append line $slib_V to $slib_mult |
||
51 | !next slib_r |
||
52 | |||
53 | slib_out=!nonempty line $slib_mult |
||
54 | slib_out=!trim $slib_out |