# Histogram and Sturges' formula

**URL:** <https://discuss.elastic.co/t/histogram-and-sturges-formula/14133>\
**Category:** Elasticsearch\
**Created:** [October 28, 2013, 4:09am UTC](https://discuss.elastic.co/t/histogram-and-sturges-formula/14133 "2013-10-28T04:09:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_MacCarthy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_maccarthy/32/2020_2.png) [@Justin\_MacCarthy](https://discuss.elastic.co/u/Justin_MacCarthy)\
**Post date:** [October 28, 2013, 4:09am UTC](https://discuss.elastic.co/t/histogram-and-sturges-formula/14133/1 "2013-10-28T04:09:20Z")

</div>

Hi,

Has anyone figured out how to use Sturges  
([http://en.wikipedia.org/wiki/Histogram#cite\_note-sturges-9](http://en.wikipedia.org/wiki/Histogram#cite_note-sturges-9)) or similar to  
set the number of bins in a histogram?  
Is it possible to use scripting to set that number ?

This is a common method in more histogram, functions, in R, D3,js , etc.

Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 28, 2013, 9:42am UTC](https://discuss.elastic.co/t/histogram-and-sturges-formula/14133/2 "2013-10-28T09:42:08Z")

</div>

Hey,

can you maybe tell us, what you expect the histogram interval to happen  
with? Linking to paid content makes is pretty hard to understand the  
requirement. 🙂  
I suppose you want automatic bucketing instead of specifying an interval  
manually?

--Alex

On Mon, Oct 28, 2013 at 5:09 AM, Justin MacCarthy \<  
[justin.maccarthy@gmail.com](mailto:justin.maccarthy@gmail.com)\> wrote:

> Hi,
> 
> Has anyone figured out how to use Sturges (  
> [Histogram - Wikipedia](http://en.wikipedia.org/wiki/Histogram#cite_note-sturges-9)) or similar to  
> set the number of bins in a histogram?  
> Is it possible to use scripting to set that number ?
> 
> This is a common method in more histogram, functions, in R, D3,js , etc.
> 
> Thanks
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Justin\_MacCarthy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_maccarthy/32/2020_2.png) [@Justin\_MacCarthy](https://discuss.elastic.co/u/Justin_MacCarthy)\
**Post date:** [October 28, 2013, 10:00am UTC](https://discuss.elastic.co/t/histogram-and-sturges-formula/14133/3 "2013-10-28T10:00:03Z")

</div>

From the wikipedia article I linked to

> Sturges' formula  
> Sturges' formula[9][http://en.wikipedia.org/wiki/Histogram#cite\_note-sturges-9](http://en.wikipedia.org/wiki/Histogram#cite_note-sturges-9) is  
> derived from a binomial distribution and implicitly assumes an  
> approximately normal distribution.  
> [image: k = \lceil \log\_2 n + 1 \rceil, ,]  
> It implicitly bases the bin sizes on the range of the data and can perform  
> poorly if _n_ \< 30.[\*citation needed[http://en.wikipedia.org/wiki/Wikipedia:Citation\_needed](http://en.wikipedia.org/wiki/Wikipedia:Citation_needed)  
> \*] It may also perform poorly if the data are not normally distributed.

> I suppose you want automatic bucketing instead of specifying an interval  
> manually?

Yes, using the above method or similar

Justin

On Monday, October 28, 2013 4:42:08 PM UTC+7, Alexander Reelsen wrote:

> Hey,
> 
> can you maybe tell us, what you expect the histogram interval to happen  
> with? Linking to paid content makes is pretty hard to understand the  
> requirement. 🙂  
> I suppose you want automatic bucketing instead of specifying an interval  
> manually?
> 
> --Alex
> 
> On Mon, Oct 28, 2013 at 5:09 AM, Justin MacCarthy \<[justin.m...@gmail.com](mailto:justin.m...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > Has anyone figured out how to use Sturges (  
> > [Histogram - Wikipedia](http://en.wikipedia.org/wiki/Histogram#cite_note-sturges-9)) or similar  
> > to set the number of bins in a histogram?  
> > Is it possible to use scripting to set that number ?
> > 
> > This is a common method in more histogram, functions, in R, D3,js , etc.
> > 
> > Thanks
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [October 28, 2013, 8:31pm UTC](https://discuss.elastic.co/t/histogram-and-sturges-formula/14133/4 "2013-10-28T20:31:33Z")

</div>

If you want to implement automatic number of bin calculation for a  
histogram, I recommend reading Lucien Birgé and Yves Rozenholc:  
[http://archive.numdam.org/ARCHIVE/PS/PS\_2006\_\_10\_/PS\_2006\_\_10\_\_24\_0/PS\_2006\_\_10\_\_24\_0.pdf](http://archive.numdam.org/ARCHIVE/PS/PS_2006 __10_/PS_2006__ 10 __24_0/PS_2006__ 10__24_0.pdf)

For a start, I would prefer alternatives of equi-distant histogram bins or  
equi-frequent histogram bins instead of having to put in a specific  
constant interval.

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:10am UTC](https://discuss.elastic.co/t/histogram-and-sturges-formula/14133/5 "2017-07-06T02:10:07Z")

</div>


