0
$\begingroup$

Is there a code/ software that generates random numbers? My specific interest - from Dirichlet distribution. Lets say, x1,x2,...x8 and 1000 random instances of it with a uniform alpha=2.

$\endgroup$
1
$\begingroup$

in R using MCMC pack http://ugrad.stat.ubc.ca/R/library/MCMCpack/html/dirichlet.html

> library(MCMCpack)
> rdirichlet(10, c(2,2,2,2,2,2,2,2))
        [,1]       [,2]       [,3]       [,4]       [,5]       [,6]       [,7]       [,8]
 [1,] 0.18331559 0.04963897 0.09147763 0.12917653 0.05112268 0.18718299 0.20280600 0.10527961
 [2,] 0.03109268 0.33347923 0.03985453 0.20214635 0.03918814 0.02256349 0.09901597 0.23265962
 [3,] 0.17014930 0.38431378 0.03299124 0.03709429 0.06292639 0.03564619 0.14343975 0.13343907
 [4,] 0.10645766 0.19891456 0.03896370 0.16776247 0.07054724 0.12152113 0.04787584 0.24795740
 [5,] 0.10336389 0.15332965 0.05916525 0.07978555 0.21871399 0.03245186   0.04481537 0.30837445
 [6,] 0.35104636 0.10134319 0.08159365 0.07493815 0.15875336 0.05832428 0.09765403 0.07634698
 [7,] 0.25615018 0.06459785 0.23003759 0.04623660 0.11182786 0.10745807 0.11450019 0.06919166
 [8,] 0.08151608 0.02621598 0.26610912 0.07679182 0.10899858 0.27492978 0.10612096 0.05931767
 [9,] 0.23030626 0.03858876 0.16619106 0.01939367 0.15696856 0.04498264 0.15360794 0.18996110
[10,] 0.11680868 0.03409545 0.51320903 0.05394151 0.08095239 0.01446853 0.11147443 0.07505000
$\endgroup$
6
  • $\begingroup$ Where can I get the MCMCpack? It did not come in the standard R installation. Thanks. $\endgroup$
    – Murali
    Nov 12 '19 at 18:35
  • $\begingroup$ It is on cran. If you do install.package("MCMCpack") in your r console you should get it $\endgroup$
    – rep_ho
    Nov 12 '19 at 18:43
  • $\begingroup$ I think I am definitely doing something wrong, it says "could not find the function install.package". I got R version 3.6.1, and in its library, there is no mcmc folder $\endgroup$
    – Murali
    Nov 12 '19 at 18:51
  • $\begingroup$ Because it is install.packages sorry $\endgroup$
    – rep_ho
    Nov 12 '19 at 18:53
  • 1
    $\begingroup$ I figured it out. Thanks a lot. $\endgroup$
    – Murali
    Nov 12 '19 at 19:51
1
$\begingroup$

Try numpy.random.dirichlet in Python.

Once you install Python and the numpy package (to install both in the easiest way start here), you can generate your samples in a new file by the code

import numpy

numpy.random.dirichlet((2,2,2,2,2,2,2,2),size=1000).T
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.