hist()

Prof Brian Ripley Prof Brian Ripley <ripley@stats.ox.ac.uk>
Mon, 16 Nov 1998 16:27:17 +0000 (GMT)


> From: Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk>
> Date: 16 Nov 1998 14:26:38 +0100
> 
> Going over my old notes, I realised that hist() has changed since the
> earlier versions of R, in that the intervals are now
> left-open,right-closed rather than the opposite. This is a change in
> the direction of S-plus compatibility, but I wonder how sensible it
> really is.

Since a histogram is intended to be of continuous data, it should
not really matter. And if the data are already rounded (like ages) it
matters how they were rounded. (One of my grandfathers would
say he was `in his eighty-second year', so the rounding direction
may even depend on the value.)  My example below shows that rounding
error can play havoc with one's intentions too.

Since cut in R has an argument `right', could not hist have too?
And I don't actually understand why hist.default does not call cut.default
directly, when enhancements to cut will be easy to apply to hist.
Then we can argue about the default for right. It seems to me that
it should be the same for cut and for hist, and I would argue for
not changing the current default (whatever it might have been).

Oh, and what do bincode and bincode2 do about rounding error? (Nothing,
I think.) The default breaks in cut and hist are computed quantities,
and as we know, seq does not always get them exactly right.
As in:

> cut(c(0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85), 6) 
[1] (0.249,0.35] (0.35,0.45]  (0.45,0.55]  (0.45,0.55]  (0.55,0.65] 
[6] (0.65,0.75]  (0.75,0.851]

> cut(c(0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85), 6, right=FALSE)
[1] [0.249,0.35) [0.35,0.45)  [0.45,0.55)  [0.55,0.65)  [0.55,0.65) 
[6] [0.65,0.75)  [0.75,0.851)

(R 0.63.0 and others) !!!

Brian

-- 
Brian D. Ripley,                  ripley@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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._