Question: Problem in sampling gaussian random variables


A year ago I submitted a problem about the sampling of a Gaussian Random Variable (GRV).
A serious problem with Statistics:-Sample()
In short, the default method (Ziggurat method) used in the Stratistics package to sample a GRV overestimates the weights of the tails of the distribution.

Forcing the method to "envelope" is a way to obtain a correct sample

Statistics:-Sample(Normal(0, 1), N, method=envelope)

(another one is to use for instance the Box-Muller sampling algorithm ; look to the reference above for the fast implementation acer proposed).

I recently observed that the envelope method generates an error ("too many inflexion points...") when the standard deviation of the GRV is not one.
I tried to avoid this error by adding the suboption "range" :

f := (sigma, k, N) => Statistics:-Sample(Normal, 0, sigma), N,  method=[envelope, range=-k*sigma..k*sigma]):
# this works
f(1, 3, 10):
# these do not work
f(0.1, 3, 10):
f(10, 3, 10):

Here, k is a positive real value (which could depend on N but can be imagined to be around 5 or 6 to fix the ideas
Even with this suboption I keep receivind the same error.

If there is no way to parameterize correctly the envelope method, this means that Maple is unable to sample correctly a GRV.

Of course, if X is a GRV of mean mu and standard deviation sigma on could do this to generate a sample of X:

Xstd := RandomVariable(Normal(0, 1)):
Sstd := Sample(Xstd, 10^6, method=envelope):
S := mu +~ sigma *~ Sstd

But this should not be a permanent solution.

Please Wait...