[R] ties in runif() output
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Jun 26 08:15:17 CEST 2004
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.
> 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
More information about the R-help
mailing list