Skip to content

runif limited precision

7 messages · Stavros Macrakis, Duncan Murdoch, Daniel Nordlund

#
runif appears to give 31 bits of precision, but this isn't mentioned
in the documentation page. The R numeric type supports 53 digits of
precision, and other numeric functions (sin, etc.) give full-precision
results.  So I'd think that either runif should give full precision or
its documentation should mention this limitation.

#integers
table(runif(10000,-2^30,2^30) %% 1)
   0  0.5
4972 5028
#natural numbers
0  0.5
4956 5044
#fractions
table((r<-runif(10000,0,1)*2^31)-floor(r))
   0  0.5
5021 4979
#
On 02/01/2009 2:45 PM, Stavros Macrakis wrote:
It refers to the .Random.seed page for details, and that page mentions 
the limitation to at most 2^32 different values for most of the generators.
Your interval is 2^31 units long, and you're getting values on the 
integers and halfway between, so that looks like 2^32 bits, not 2^31.
Same here.

Duncan Murdoch
#
On Fri, Jan 2, 2009 at 4:03 PM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
Indeed it does -- thanks for the pointer!  I still think it would be
helpful to the user to mention the limitation in the individual
r<dist> doc pages, as not many users are likely to work through the
very complete RNG doc page.

          -s
#
On 02/01/2009 4:16 PM, Stavros Macrakis wrote:
I don't agree.  If you add too much technical detail to a topic, then 
people don't "work through it".  I'd say the r<dist> pages generally 
give enough detail now, but not too much.  If you add every detail that 
might interest someone somewhere, then they'd all be hard to read.

Duncan Murdoch
#
I would have to agree with Duncan on this.  Besides, if you are doing
something where having only 2^32 distinct values is a problem, you probably
should be "working through" ALL of the documentation on random number
generation in R.  But that is just my 4 cents worth (inflation :-).

Dan

Daniel Nordlund
Bothell, WA USA
#
On Fri, Jan 2, 2009 at 5:56 PM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
Duncan, Daniel,

Thanks for your responses.

I agree that it's a delicate balance between too little and too much
information on individual documentation pages -- especially when, as
in this case, a number of different functions (r<dist>) share some
content (RNG).  That said, I find in general that R documentation
pages are somewhat on the "too little" side. In particular, I'd find
it useful if there were more references to synthetic overviews: a link
from the connection page to an overview of I/O; a link from the runif
page to an overview of distributions; etc.

           -s
#
On 02/01/2009 7:33 PM, Stavros Macrakis wrote:
One structural problem we have is that it is hard to make a useful link 
between different types of documentation.  You can cite one of the 
manuals from a man page, but it's hard to make a convenient link to a 
particular section.  Vignettes are similar: when they exist, they often 
give exactly the overview you're looking for, but it's almost by chance 
that you find them.

I spent a little bit of time putting things in place so that 
help.search() could look through vignettes and manuals, but got 
sidetracked before it was complete, so I doubt it will make it into 2.9.0.

Duncan Murdoch