Sample from the Dirichlet distribution
Arguments
- n
Number of samples (rows) to draw
- alpha
Concentration parameters; either length 1 or length > 1 If length 1, assumes symmetric Dirichlet;
k
must not be null- k
Number of components (columns); ignored if
length(alpha) > 1
See also
Other generators:
draw_corpus()
,
journal_specific()
,
peak_alpha()
Examples
rdirichlet(10, .1, 5)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 2.423841e-09 1.532803e-12 2.169466e-06 7.406266e-01 2.593712e-01
#> [2,] 1.459912e-07 9.978821e-01 2.041467e-03 7.548776e-05 8.241854e-07
#> [3,] 6.691078e-02 8.739031e-01 8.838151e-08 1.322609e-13 5.918602e-02
#> [4,] 9.997311e-01 2.344897e-04 9.438505e-06 2.016269e-05 4.762268e-06
#> [5,] 5.705727e-01 3.289170e-03 3.885484e-03 1.422979e-01 2.799548e-01
#> [6,] 3.979995e-11 1.145891e-04 7.392265e-02 3.694382e-07 9.259624e-01
#> [7,] 3.620254e-07 7.164644e-09 2.523535e-07 9.277864e-01 7.221295e-02
#> [8,] 2.877197e-01 6.969973e-01 8.160363e-04 3.396563e-03 1.107040e-02
#> [9,] 2.667917e-09 2.071258e-03 9.659243e-01 1.175474e-02 2.024974e-02
#> [10,] 3.164987e-12 1.471874e-01 3.901119e-03 2.830459e-02 8.206069e-01
rdirichlet(10, c(.8, .1, .1))
#> [,1] [,2] [,3]
#> [1,] 0.99233959 4.493176e-08 7.660367e-03
#> [2,] 0.81257946 1.874204e-01 9.633943e-08
#> [3,] 0.99995797 4.202902e-05 2.243478e-16
#> [4,] 0.86415746 1.231873e-01 1.265520e-02
#> [5,] 0.05493031 6.767110e-01 2.683587e-01
#> [6,] 0.14377540 8.483355e-01 7.889068e-03
#> [7,] 0.97931985 1.905010e-02 1.630049e-03
#> [8,] 0.27276990 4.473032e-02 6.824998e-01
#> [9,] 0.85135935 1.486406e-01 5.826725e-09
#> [10,] 0.96300713 8.924995e-03 2.806787e-02