├── LICENSE.txt ├── README.md ├── composer.json └── src ├── Statistics.php └── StatisticsError.php /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) Oefenweb.nl 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # php-statistics 2 | 3 | [![Build Status](https://travis-ci.org/Oefenweb/php-statistics.svg?branch=master)](https://travis-ci.org/Oefenweb/php-statistics) 4 | [![PHP 7 ready](http://php7ready.timesplinter.ch/Oefenweb/php-statistics/badge.svg)](https://travis-ci.org/Oefenweb/php-statistics) 5 | [![codecov](https://codecov.io/gh/Oefenweb/php-statistics/branch/master/graph/badge.svg)](https://codecov.io/gh/Oefenweb/php-statistics) 6 | [![Packagist downloads](http://img.shields.io/packagist/dt/Oefenweb/statistics.svg)](https://packagist.org/packages/oefenweb/statistics) 7 | [![Code Climate](https://codeclimate.com/github/Oefenweb/php-statistics/badges/gpa.svg)](https://codeclimate.com/github/Oefenweb/php-statistics) 8 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Oefenweb/php-statistics/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Oefenweb/php-statistics/?branch=master) 9 | 10 | Statistics library for PHP. 11 | 12 | ## Requirements 13 | 14 | * PHP 7.2.0 or greater. 15 | 16 | ## Usage 17 | 18 | ### Sum 19 | ```php 20 | use Oefenweb\Statistics\Statistics; 21 | 22 | Statistics::sum([1, 2, 3]); // 6 23 | ``` 24 | 25 | ### Minimum 26 | ```php 27 | use Oefenweb\Statistics\Statistics; 28 | 29 | Statistics::min([1, 2, 3]); // 1 30 | ``` 31 | 32 | ### Maximum 33 | ```php 34 | use Oefenweb\Statistics\Statistics; 35 | 36 | Statistics::max([1, 2, 3]); // 3 37 | ``` 38 | 39 | ### Mean 40 | ```php 41 | use Oefenweb\Statistics\Statistics; 42 | 43 | Statistics::mean([1, 2, 3]); // 2 44 | ``` 45 | 46 | ### Frequency 47 | ```php 48 | use Oefenweb\Statistics\Statistics; 49 | 50 | Statistics::frequency([1, 2, 3, 3, 3]); // [1 => 1, 2 => 1, 3 => 3] 51 | ``` 52 | 53 | ### Mode 54 | ```php 55 | use Oefenweb\Statistics\Statistics; 56 | 57 | Statistics::mode([1, 2, 2, 3]); // 2 58 | ``` 59 | 60 | ### Variance (sample and population) 61 | ```php 62 | use Oefenweb\Statistics\Statistics; 63 | 64 | Statistics::variance([1, 2, 3]); // 1 65 | Statistics::variance([1, 2, 3], false); // 0.66666666666667 66 | ``` 67 | 68 | ### Standard deviation (sample and population) 69 | ```php 70 | use Oefenweb\Statistics\Statistics; 71 | 72 | Statistics::standardDeviation([1, 2, 3]); // 1.0 73 | Statistics::standardDeviation([1, 2, 3], false); // 0.81649658092773 74 | ``` 75 | 76 | ### Range 77 | ```php 78 | use Oefenweb\Statistics\Statistics; 79 | 80 | Statistics::range([4, 6, 10, 15, 18]); // 14 81 | ``` 82 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "oefenweb/statistics", 3 | "description": "Statistics library for PHP", 4 | "type": "library", 5 | "keywords": [ 6 | "statistics" 7 | ], 8 | "homepage": "http://github.com/Oefenweb/php-statistics", 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "Oefenweb.nl BV team", 13 | "homepage": "https://github.com/Oefenweb/php-statistics/contributors" 14 | } 15 | ], 16 | "require": { 17 | "php": ">=7.0.0" 18 | }, 19 | "support": { 20 | "issues": "https://github.com/Oefenweb/php-statistics/issues", 21 | "source": "https://github.com/Oefenweb/php-statistics" 22 | }, 23 | "autoload": { 24 | "psr-4": { 25 | "Oefenweb\\Statistics\\": "src" 26 | } 27 | }, 28 | "autoload-dev": { 29 | "psr-4": { 30 | "Oefenweb\\Statistics\\Test\\": "tests" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Statistics.php: -------------------------------------------------------------------------------- 1 |