[R] Needed: Understading runif() output :-)

Kjetil Kjernsmo kjetil.kjernsmo at astro.uio.no
Thu May 25 16:38:40 CEST 2000


Dear all,

I have been trying to understand what runif() is telling me. 
I am generating lots of numbers (billions and billions (wow, I've dreamed
about saying that for many years... :-) ), for a distribution that has the
following quantile function:
    1 / (2 * sqrt(1 - p)) 
(that is, the distribution has a lower cutoff)
As you can imagine, this has rather heavy upper tail. I was looking at the
largest values, and it looked as if the largest values appeared again and
again. Now, it wasn't in itself that large values were strange, since I'm
generating so many numbers, but that the largest were very much larger
than the second largest numbers, and that exactly the same number appeared
again and again. First I thought it was a bug, and I'm sorry to have
wasted r-devels time with a bug report. 

I started running the same simulation with different RNGs and they all
seem to generate numbers in "quantized states". Then, I started to look
into what runif() gives, and let it print 13 digits. 
In the below output, I use the "Mersenne-Twister" RNG and I have generated
1e+10 numbers (100000 at a time) and I print a line if it the number is
above 10000 (my dist, the left coloumn), the right coloumn are runif()
the corresponding outputs.
[1] 3.276800000000e+04 9.999999997672e-01
[1] 13377.479981919865     0.999999998603
[1] 1.158523750296e+04 9.999999981374e-01
[1] 1.036215143684e+04 9.999999976717e-01
[1] 1.158523750296e+04 9.999999981374e-01
[1] 1.036215143684e+04 9.999999976717e-01
[1] 1.036215143684e+04 9.999999976717e-01
[1] 13377.479981919865     0.999999998603

So, it seems that the runif() outputs are "quantized" too. The question 
is: What is the reason for this?
I have been playing with the tought that it may be connected to the finite 
number representation capabilites of a computer? As I said, all the RNGs
seems to have similar characteristics.

If this is the case, I have no problem. It's cosmology I'm doing, so
whether a number is 32768 or 29923 is (presumably) of little
importance. However, I should understand what is going on here.... :-)

Finally, I may get a "loss of precision"-problem in my coding of my
quantile function, but I guess it is not that much of a concern.

Hope somebody can help me with this.

Best,

Kjetil
-- 
Kjetil Kjernsmo
Graduate astronomy-student                    Problems worthy of attack
University of Oslo, Norway            Prove their worth by hitting back
E-mail: kjetikj at astro.uio.no                                - Piet Hein
Homepage <URL:http://www.astro.uio.no/~kjetikj/>
Webmaster at skepsis.no 



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list