Re: simulating random variables

• To: mathgroup at smc.vnet.net
• Subject: [mg32851] Re: [mg32831] simulating random variables
• From: "Johannes Ludsteck" <johannes.ludsteck at wiwi.uni-regensburg.de>
• Date: Fri, 15 Feb 2002 02:49:55 -0500 (EST)
• Organization: Universitaet Regensburg
• Sender: owner-wri-mathgroup at wolfram.com

```Dear Aaron,
unfortunately I have no simple idea how to speed up
generation of binomial random deviates, but I can
give you two standard references on pseudorandom variable
generation:
[1] Luc Devroye (I have forgotten the title)
[2] Johnson: Multivariate Statistical Simulation, 1987.

However, the Mathematica implementation is likely to be efficient.

As for the normal random variables, if you
need large lists or arrays of r.v., a *simple*
method to speed up things considerably ist to use
RandomArray[]. On my computer, RandomArray is
about 10 times faster for 100000 draws:

In[1]:=
Timing[Table[Random[NormalDistribution[0,1]],{100000}];]
Out[1]= {3.62 Second,Null}
In[2]:=
Timing[RandomArray[NormalDistribution[0,1],100000];]
Out[2]= {0.33 Second,Null}

I guess that is impossible to speed up RandomArray,
since the implementation is considerably efficient.
Have a look at the Package Statistics`NormalDistribution`
if you don't believe this.

Best regards,
Johannes

On 14 Feb 2002, at 1:44, Aaron E. Hirsh wrote:

> Dear All,
>
> I need to simulate a large number of binomial random variables.
> Unfortunately, when the parameter n (number of trials) is large, the
> simulation of binomial random variables is relatively time consuming.
> For example, if I would like to simulate a binomial random variable
> with parameters n = 10000 and p =0.01:
>
> In[134]:=
> Timing[Random[BinomialDistribution[100000,0.01]]]
>
> Out[134]=
> {0.283333 Second,1007}
>
> One possibility for saving time would be to use an approximation. For
> small p, an appropriate approximation is the Poisson. While this is
> definitely better:
>
> In[135]:=
> Timing[Random[PoissonDistribution[(.01)(100000)]]]
>
> Out[135]=
> {0.0333333 Second,1002}
>
> , it is still much slower than using a normal:
>
> In[136]:=
> \!\(Timing[
>      Random[NormalDistribution[(.01)(100000),((.01)(100000)(.99))^0.5]]]\)
>
> Out[136]=
> {0. Second,1025.3}
>
> Does anyone know how I could speed up my simulation of binomial or
> poisson-distributed random variables? I would also be interested in
> ways of speeding up the simulation of the Normal, though it seems
>
>      Thank you very much,
>
> Aaron Hirsh
> --
>
> Aaron E. Hirsh
> Center for Computational Genetics and Biological Modeling
> Stanford University
> tel. (650) 723-4952
> fax. (650) 725-0180
>

<><><><><><><><><><><><><><><><><><>
Johannes Ludsteck
Institut fuer Volkswirtschaftslehre
Lehrstuhl Prof. Dr. Moeller
Universitaet Regensburg
Universitaetsstrasse 31
93053 Regensburg
Tel +49/0941/943-2741

```

• Prev by Date: Re: simulating random variables
• Next by Date: Re: Linebreaks and style when saving as TeX
• Previous by thread: Re: simulating random variables
• Next by thread: Linebreaks and style when saving as TeX