chickadee » statistics » histogram-breaks

(histogram-breaks sequence n #:method)procedure

Computes histogram bin edges using various methods. Returns a vector of n+1 breakpoints (edges). The #:method keyword determines the binning strategy:

  • 'equal-width - Equal width bins (default for specified n)
  • 'sturges - Sturges' formula: 1 + log2(n) bins
  • 'scott - Scott's normal reference rule
  • 'fd - Freedman-Diaconis rule: 2*IQR/n^(1/3) (robust to outliers)
> (histogram-breaks '(1 2 3 4 5 6 7 8 9 10) 5 #:method 'equal-width)
#(1.0 2.8 4.6 6.4 8.2 10.0)
> (histogram-breaks '(1 2 3 4 5 6 7 8 9 10) 10 #:method 'sturges)
#(1.0 2.25 3.5 4.75 6.0 7.25 8.5 9.75)