[Rd] problem with "breaks" in histogram (PR#710)

mcw@ln.nimh.nih.gov mcw@ln.nimh.nih.gov
Wed, 25 Oct 2000 20:49:20 +0200 (MET DST)


Full_Name: Matthew Wiener
Version: 1.1.1
OS: linux
Submission from: (NULL) (156.40.248.102)


I've come across a glitch in hist.  I can reproduce it on linux for Intel, linux
for
PPC, and Irix 6.5.

t1 <- c(41, 42, 42, 43, 43, 43, 44, 44, 45, 46)
hist(t1, breaks = 10)    (OK)
hist(t1/50, breaks = 10)
	Error in hist.defauilt(t1/50, breaks = 10):
	        some 'x' not counted; maybe breaks do not span range of x


The breaks generated by the call
hist(t1/50, breaks = 10) are (as printed just after the call to "pretty" on line
32
of hist.default):  0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.90 0.91 0.92 .

>hist(t1/50, breaks = seq(from = 0.82, to = 0.92, by = .01))
gives me the error, but

>hist(t1/50, breaks =  c(.82, .83, .84, .85, .86, .87, .88, .89, .9, .91, .92))
does not.

It seems to be a numerical precision problem in generating the breaks, and
maybe
in seq() in general.  I tried 
printing the breaks generated with seq() with 20 digits precision, and the 
first and last breaks were 0.81999999999999995115 and 
0.91999999999999992895, and counts confirms that the value of 0.92 is being
missed
in this case.

And if I try
> hist(t1[-2]/50, breaks = 10), 
the extreme breaks are 0.82000000000000006217 and
0.92000000000000003997  and you miss the value of 0.82.

Maybe some sort of rounding of the breaks is in order, but it would need to
take
into account the actual size of the numbers you're dealing with.

I hope this report has enough information.  If not, please let me know what
else I can provide.  Thanks for the terrific software.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._