I was wondering if there are established rules of thumb (or algorithms) that, given a set of observations can help:

  1. choose an initial number of class intervals.
  2. refine that choice to a better number.

I could find talk of using square-root(N), where N is the number of observations as an initial guess of the number of class intervals.

Thanks in advance.

  • $\begingroup$ I remember reading some rules of thumb for this, but I can't remember which book had them. I think it might have been one of William Cleveland's books. $\endgroup$ – Peter Flom Sep 24 '12 at 10:22
  • 1
    $\begingroup$ check out van Belle's Statistical Rules of Thumb. If he has a rule for this in there he will give a nice justification for it. $\endgroup$ – Michael Chernick Sep 24 '12 at 11:44
  • $\begingroup$ What is the purpose of classification here? No rule of thumb can possibly cover even the commonest cases. For instance, a good rule of thumb for classifying observations as explanatory variates in regression modeling is not to do it. If the focus is on histograms, note that there are many, many procedures--and selecting one depends, once again, on how the histogram will be used $\endgroup$ – whuber Sep 24 '12 at 14:17
  • $\begingroup$ @whuber where did you get the idea that the OP is talking about a classification problem?? It sound like he is just looking for rules of thumb for binning data for a histogram. I think it is common terminology to call the bin intervals class intervals. I think therre are reasonable rules of thumb that talk about taking the range of the data and dividing it into k equally spaced intervals where k is chosen as a function of the total sample size n. therre may be some exceptions on this when some of the cells are very sparse or empty and then a smaller choice for k would be picked. $\endgroup$ – Michael Chernick Sep 24 '12 at 20:55
  • $\begingroup$ Of course just as with kernel density estimation there is always a degree of subjectivity regarding smoothness and roughness of the hitogram or the density and prior knowledge could come into play. Nevertheless rules of thumb are popular and sometimes rules can be set up that work in a large majority of cases. No rule holds without some exceptions. But some people like them because it simplifies decison making and doesn't require as much thought. But rules of thumb can be dangerous for that reason. $\endgroup$ – Michael Chernick Sep 24 '12 at 21:01

The help of the R command hist http://stat.ethz.ch/R-manual/R-patched/library/grDevices/html/nclass.html has some references to algorithms for computing the number of the bins:

Sturges, H. A. (1926) The choice of a class interval. Journal of the American Statistical Association 21, 65–66.

Scott, D. W. (1979) On optimal and data-based histograms. Biometrika 66, 605–610.

Freedman, D. and Diaconis, P. (1981) On the histogram as a density estimator: L_2 theory. Zeitschrift für Wahrscheinlichkeitstheorie und verwandte Gebiete 57, 453–476.


See also HOGG, David W. Data analysis recipes: Choosing the binning for a histogram. arXiv preprint arXiv:0807.4820, 2008.

The abstract:

Data points are placed in bins when a histogram is created, but there is always a decision to be made about the number or width of the bins. This decision is often made arbitrarily or subjectively, but it need not be. A jackknife or leave-one-out cross-validation likelihood is defined and employed as a scalar objective function for optimization of the locations and widths of the bins. The objective is justified as being related to the histogram’s usefulness for predicting future data. The method works for data or histograms of any dimensionality.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.