[R] Histograms and Sturges rule
Paul Smith
phhs80 at gmail.com
Wed Nov 28 02:17:50 CET 2007
On Nov 28, 2007 12:32 AM, Deepayan Sarkar <deepayan.sarkar at gmail.com> wrote:
> > According to the Sturges rule, the number of classes of a histogram is
> > the closest integer to
> >
> > 1 + logb(n,base=2)
> >
> > where n is the number of observations. The function hist(), by
> > default, uses the Sturges rule. However, the code
> >
> > x <- 1:200
> > hist(x)
> >
> > produces a histogram with 10 classes and not 9 classes as determined
> > by the Sturges rule. What am I missing?
>
> The documentation does say that:
>
> In the last three cases the number is a suggestion only.
>
> Basically, hist() uses "pretty" breakpoints, and you have
>
> > pretty(c(1, 200), 9)
> [1] 0 20 40 60 80 100 120 140 160 180 200
>
> (i.e. 10 intervals even when you ask for 9). truehist() in MASS and
> histogram() in lattice don't have this "feature" (though truehist
> doesn't seem to allow "Sturges" as an option).
Thanks, Deepayan, for the clarification.
Paul
More information about the R-help
mailing list