1
$\begingroup$

Let's say we want to histogram a finite set of measurements of some quantity. It is straight forward to calculate the usual statistical quantities for our sample such as the mean and the variance. Let's assume we can clean up our data by identifying outliers and moving them into underflow and overflow bins and thus, define more or less optimal min and max values for the plotting range. But how would one decide on the number and the size of bins? I would like to know if there are methods to find the optimal binning for the cases with fixed and variable bin sizes.

$\endgroup$
1
$\begingroup$

I don't know if this what you want but here is a way to calculate the number of bins.

  1. Count the number of data points in your dataset.
  2. Take the square root of the number of data points and round up to determine the initial number of bins required: $InitialNumberOfBins = \sqrt{NumberOfDataPoints}$.
  3. Divide the specification tolerance $Max-Min\ value$ by initial number of bins: $FinalNumberOfBins = (Max-Min\ value) / InitialNumberOfBins$.
|improve this answer|||||
$\endgroup$
  • $\begingroup$ (1 - 0) / sqrt(10000) = 0.01 bins?? How does that work? $\endgroup$ – K3---rnc Jun 18 '16 at 13:22
  • $\begingroup$ you square root the number of data points i.e (√144)= 12 initial bins $\endgroup$ – Darrin Thomas Jun 18 '16 at 13:36
  • $\begingroup$ Yes, 10k data points, normalized to [0, 1], squared, as above. Gives 0.01 bins. $\endgroup$ – K3---rnc Jun 18 '16 at 15:57
  • $\begingroup$ I don't remember saying to normalize the data. $\endgroup$ – Darrin Thomas Jun 18 '16 at 21:10
  • $\begingroup$ Sorry, it was already normalized. But I just used it as an example. The real data has values between 14.03 and 14.93, roughly normally distributed. So? $\endgroup$ – K3---rnc Jun 19 '16 at 17:05

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.