PHPackages                             tomkyle/binning - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tomkyle/binning

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tomkyle/binning
===============

Determine optimal number of bins 𝒌 for histogram creation and optimal bin width 𝒉 using various statistical methods.

1.0.3(6mo ago)187MITPHPPHP ^8.3CI passing

Since Jun 25Pushed 6mo agoCompare

[ Source](https://github.com/tomkyle/binning)[ Packagist](https://packagist.org/packages/tomkyle/binning)[ RSS](/packages/tomkyle-binning/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (6)Versions (5)Used By (0)

tomkyle/binning
===============

[](#tomkylebinning)

[![Composer Version](https://camo.githubusercontent.com/2a90b1e5326aabfe4db700ee3f857f1b1c8e9db3e63a131182b69d02c76dad12/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f6d6b796c652f62696e6e696e67)](https://packagist.org/packages/tomkyle/binning)[![PHP version](https://camo.githubusercontent.com/2417d837c4827a19e35e72cbf33dff955fca8b7e8ef11f6735c0ef0470562c8d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f6d6b796c652f62696e6e696e67)](https://packagist.org/packages/tomkyle/binning)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/754631d48f80758612ad41fb3c9c013a4a0ea58df08d056f6face7ee7a0e0e8d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f6d6b796c652f62696e6e696e672f7068702e796d6c)](https://github.com/tomkyle/binning/actions/workflows/php.yml)[![Packagist License](https://camo.githubusercontent.com/989c66d98f1cb27f9c948b63f0f35943a1ed8d5d40e9c77b0cff8a5e9cf03450/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f6d6b796c652f62696e6e696e67)](LICENSE.txt)

**Determine the optimal 𝒌 number of bins for histogram creation and optimal bin width 𝒉 using various statistical methods. Its unified interface includes implementations of well-known binning rules such as:**

- Square Root Rule (1892)
- Sturges’ Rule (1926)
- Doane’s Rule (1976)
- Scott’s Rule (1979)
- Freedman-Diaconis Rule (1981)
- Terrell-Scott’s Rule (1985)
- Rice University Rule

Requirements
------------

[](#requirements)

This library requires PHP 8.3 or newer. Support of older versions like [markrogoyski/math-php](https://github.com/markrogoyski/math-php) provides for PHP 7.2+ is not planned.

Installation
------------

[](#installation)

```
composer require tomkyle/binning
```

Usage
-----

[](#usage)

The **BinSelection** class provides several methods for determining the optimal number of bins for histogram creation and optimal bin width. You can either use specific methods directly or the general `suggestBins()` and `suggestBinWidth()` methods with different strategies.

### Determine Bin Width

[](#determine-bin-width)

Use the **suggestBinWidth** method to get the *optimal bin width* based on the selected method. The method returns the bin width, often referred to as 𝒉, as a float value.

```
