[R] ties in runif() output

Douglas Grove dgrove at fhcrc.org
Sun Jun 27 06:39:40 CEST 2004


On Sat, 26 Jun 2004, Prof Brian Ripley wrote:

> On Fri, 25 Jun 2004, Douglas Grove wrote:
> 
> > I get ties in output from runif() when I generate as few as 10^5
> > variates and get quite a lot when I generate 10^6.  Is this 
> > expected??  
> 
> It should have been.
> 
> > I haven't seen any duplication with rnorm(10^6), but
> > see varying amounts of duplication using rexp(), rbeta() and
> > rgamma().  I would have thought that there'd be enough precision
> > that one wouldn't get ties until generating samples larger than this..
> 
> Did you do the calculations?  Please do so. There are about 2e9 possible
> values of the standard generators.

I know little about the limitations of random number generation 
and didn't realize that only 2e9 values were obtainable.
I could have done the math myself had I known

Thanks very much for your help,
Doug


> > qbirthday(classes=2e9)
> [1] 52655
> 
> Statisticians ought to know about the birthday problem!
> 
> (rnorm is different because the default generator uses two uniforms, 
> deliberately to increase the precision.)
> 
> > > set.seed(222)
> > > sum(duplicated(runif(10^5)))
> > [1] 4
> 
> That's unusually high, BTW.
> 
> > > sum(duplicated(runif(10^6)))
> > [1] 140
> 
> -- 
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list